A.QAQ 题目大意:从给定的字符串中找出QAQ的个数,三个字母的位置可以不连续 思路:暴力求解,先找到A的位置,往前扫,往后扫寻找Q的个数q1,q2,然 后相乘得到q1*q2,这就是这个A能够找到的QAQ个数,依次累加即可 #include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); string s; cin>>s;…
894B - Ralph And His Magic Field 思路: 当k为1时,如果n和m奇偶性不同,那么没有答案. 可以证明,在其他情况下有答案,且答案为2^(n-1)*(m-1),因为前n-1行和m-1列确定后,最后一列和最后一行可以确定,且确定的最后一格不矛盾. 可以采用在全为1的格子中把一些1换成-1的方法来证明以上两条结论. 代码: #include<bits/stdc++.h> using namespace std; #define ll long long #define…
题目链接:https://cn.vjudge.net/problem/CodeForces-894B 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 alway…
B. Ralph And His Magic Field time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Ralph has a magic field which is divided into n × m blocks. That is to say, there are n rows and m columns on th…
题目链接 题意:给你三个数n,m,k;让你构造出一个nm的矩阵,矩阵元素只有两个值(1,-1),且满足每行每列的乘积为k,问你多少个矩阵. 解法:首先,如果n,m奇偶不同,且k=-1时,必然无解: 设n为奇数,m为偶数,且首先要满足每行乘积为-1,那么每行必然有奇数个-1,那么必然会存在有偶数个-1..满足每列乘积为-1,那么每列必然有奇数个-1,那么必然存在奇数个-1.互相矛盾. 剩下的就是有解的情况了. 我们可以在n-1m-1的矩阵中随意放置-1,1.在最后一列和最后一行控制合法性即可. #…
题目链接:https://cn.vjudge.net/problem/CodeForces-894C 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…
B. Ralph And His Magic Field time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Ralph has a magic field which is divided into n × m blocks. That is to say, there are n rows and m columns on th…
| [链接] 我是链接,点我呀:) [题意] 给你一个n*m矩阵,让你在里面填数字. 使得每一行的数字的乘积都为k; 且每一列的数字的乘积都为k; k只能为1或-1 [题解] 显然每个位置只能填1或-1 如果只考虑前n-1行和前m-1列. 那么我们对这(n-1)*(m-1)的范围. 先任意填入数字; 则一共有\(2^{(n-1)*(m-1)}\)种方法. 然后把最后一行的前m-1列填一下. 使得前m-1列满足,每一列的乘积为k 然后把最后一列的前n-1行填一下使前n-1行每一行的乘积都为k 最后…
C. Marco and GCD Sequence time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output In a dream Marco met an elderly man with a pair of black glasses. The man told him the key to immortality and then…
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 把gcd(a[1..n])放在输入的n个数之间. [代码] /* 1.Shoud it use long long ? 2.Have you ever test several sample(at least therr) yourself? 3.Can you promise that the solution is right? At least,the main ideal 4.use the puts("")…