博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
【Codeforces Round #447 (Div. 2)】
阅读量:5248 次
发布时间:2019-06-14

本文共 5655 字,大约阅读时间需要 18 分钟。

A. QAQ

  "QAQ" is a word to denote an expression of crying. Imagine "Q" as eyes with tears and "A" as a mouth.

  Now Diamond has given Bort a string consisting of only uppercase English letters of length n. There is a great number of "QAQ" in the string (Diamond is so cute!).

  Bort wants to know how many subsequences "QAQ" are in the string Diamond has given. Note that the letters "QAQ" don't have to be consecutive, but the order of letters should be exact.

Input

  The only line contains a string of length n (1 ≤ n ≤ 100). It's guaranteed that the string only contains uppercase English letters.

Output

  Print a single integer — the number of subsequences "QAQ" in the string.

Examples
 input
  QAQAQYSYIOIWIN
 output
  4
 input
  QAQQQZZYNOIWIN
 output
  3

题解:

  常见的题,记录'Q'出现的前缀,然后对于每个'A',答案加上前面'Q'的数量乘上后面'Q'的数量

1 #include
2 #include
3 #include
4 #include
5 char s[1005]; 6 int a[1005],ans=0; 7 int main() 8 { 9 scanf("%s",s+1);10 int len=strlen(s+1);11 for(int i=1;i<=len;i++)12 {13 if(s[i]=='Q')14 a[i]=a[i-1]+1;15 else a[i]=a[i-1];16 }17 for(int i=1;i<=len;i++)18 {19 if(s[i]=='A')20 ans+=a[i-1]*(a[len]-a[i-1]);21 }22 printf("%d\n",ans);23 return 0;24 }

B. Ralph And His Magic Field

  Ralph has a magic field which is divided into n × m blocks. That is to say, there are n rows and m columns on the field. Ralph can put an integer in each block. However, the magic field doesn't always work properly. It works only if the product of integers in each row and each column equals to k, where k is either 1 or -1.

  Now Ralph wants you to figure out the number of ways to put numbers in each block in such a way that the magic field works properly. Two ways are considered different if and only if there exists at least one block where the numbers in the first way and in the second way are different. You are asked to output the answer modulo 1000000007 = 109 + 7.

  Note that there is no range of the numbers to put in the blocks, but we can prove that the answer is not infinity.

Input

  The only line contains three integers nm and k (1 ≤ n, m ≤ 1018, k is either 1 or -1).

Output

  Print a single number denoting the answer modulo 1000000007.

Examples
 input
  1 1 -1
 output
  1
 input
  1 3 1
 output
  1
 input
  3 3 -1
 output
  16

题解:

  看到数据感觉是log的级别,快速幂?或者数学解?然后推了一堆没用的。最后写了个暴力打个表发现规律。

  k=1:ans=2^(n-1)*(m-1)

  k=-1:当(n+m)&1==1时为0,其他ans=2^(n-1)*(m-1)

  记住(n-1)*(m-1)会爆long long,因此先算前面的然后再次快速幂。

1 #include
2 #include
3 #include
4 #include
5 using namespace std; 6 const long long mod=(long long )(1e9+7); 7 inline long long pow(long long x,long long y) 8 { 9 long long ret=1;10 while(y)11 {12 if(y&1) ret=ret*x%mod;13 x=x*x%mod;14 y>>=1;15 }16 return ret;17 }18 int main()19 {20 long long n,m,k;21 scanf("%lld%lld%lld",&n,&m,&k);22 if(k==1) printf("%lld\n",pow(pow(2,n-1),m-1)%mod);23 else24 {25 if((n+m)%2==1) printf("0\n");26 else printf("%lld\n",pow(pow(2,n-1),m-1)%mod);27 }28 return 0;29 }

C. Marco and GCD Sequence

  In a dream Marco met an elderly man with a pair of black glasses. The man told him the key to immortality and then disappeared with the wind of time.

  When he woke up, he only remembered that the key was a sequence of positive integers of some length n, but forgot the exact sequence. Let the elements of the sequence be a1, a2, ..., an. He remembered that he calculated gcd(ai, ai + 1, ..., aj) for every 1 ≤ i ≤ j ≤ n and put it into a set Sgcdhere means the .

  Note that even if a number is put into the set S twice or more, it only appears once in the set.

  Now Marco gives you the set S and asks you to help him figure out the initial sequence. If there are many solutions, print any of them. It is also possible that there are no sequences that produce the set S, in this case print -1.

Input

  The first line contains a single integer m (1 ≤ m ≤ 1000) — the size of the set S.

  The second line contains m integers s1, s2, ..., sm (1 ≤ si ≤ 106) — the elements of the set S. It's guaranteed that the elements of the set are given in strictly increasing order, that means s1 < s2 < ... < sm.

Output

  If there is no solution, print a single line containing -1.

  Otherwise, in the first line print a single integer n denoting the length of the sequence, n should not exceed 4000.

  In the second line print n integers a1, a2, ..., an (1 ≤ ai ≤ 106) — the sequence.

  We can show that if a solution exists, then there is a solution with n not exceeding 4000 and ai not exceeding 106.

  If there are multiple solutions, print any of them.

Examples
 input
  4   2 4 6 12
 output
  3   4 6 12
 input
  2   2 3
 output
  -1

题解:

  显然最小的数x一定是所有数的最大公因数,否则无解。然后在每两个数之间插入一个x可以发现每个区间的gcd就是x,然后i==j的区间的gcd就是本身。所以是合法解。
1 #include
2 #include
3 #include
4 #include
5 #include
6 using namespace std; 7 int n,a[10005]; 8 int main() 9 {10 scanf("%d",&n);11 for(int i=1;i<=n;++i)12 {13 scanf("%d",a+i);14 if(a[i]%a[1]!=0)15 {16 printf("-1");17 return 0;18 }19 }20 printf("%d\n",2*n);21 for(int i=1;i<=n;++i)22 printf("%d %d ",a[i],a[1]);23 return 0;24 }

 

转载于:https://www.cnblogs.com/Dndlns/p/7863102.html

你可能感兴趣的文章
shell脚本
查看>>
Upload Image to .NET Core 2.1 API
查看>>
Js时间处理
查看>>
Java项目xml相关配置
查看>>
三维变换概述
查看>>
第三次作业
查看>>
vue route 跳转
查看>>
【雷电】源代码分析(二)-- 进入游戏攻击
查看>>
Entityframework:“System.Data.Entity.Internal.AppConfig”的类型初始值设定项引发异常。...
查看>>
Linux中防火墙centos
查看>>
mysql新建用户,用户授权,删除用户,修改密码
查看>>
FancyCoverFlow
查看>>
JS博客
查看>>
如何设置映射网络驱动器的具体步骤和方法
查看>>
ASP.NET WebApi 基于OAuth2.0实现Token签名认证
查看>>
283. Move Zeroes把零放在最后面
查看>>
Visual Studio Code 打开.py代码报Linter pylint is not installed解决办法
查看>>
Python 数据类型
查看>>
S5PV210根文件系统的制作(一)
查看>>
51NOD 1244 莫比乌斯函数之和
查看>>