CODE FESTIVAL 2017 qual A--B-fLIP(换种想法,暴力枚举)
Posted 余生漫漫浪
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CODE FESTIVAL 2017 qual A--B-fLIP(换种想法,暴力枚举)相关的知识,希望对你有一定的参考价值。
个人心得:开始拿着题目还是有点懵逼的,以前做过相同的,不过那是按一个位置行列全都反之,当时也是没有深究。现在在打比赛不得不
重新构思,后面一想把所有的状态都找出来,因为每次确定了已经按下的行和列后,按不同的操作所加的数都是一样的,于是就想到了用set
暴力枚举,从1-n个分别行列按钮,然后再枚举不同操作即确定行时再对列进行操作,每次操作放入set就可以了。
题目:
Problem Statement
We have a grid with N rows and M columns of squares. Initially, all the squares are white.
There is a button attached to each row and each column. When a button attached to a row is pressed, the colors of all the squares in that row are inverted; that is, white squares become black and vice versa. When a button attached to a column is pressed, the colors of all the squares in that column are inverted.
Takahashi can freely press the buttons any number of times. Determine whether he can have exactly K black squares in the grid.
Constraints
- 1≤N,M≤1000
- 0≤K≤NM
Input
Input is given from Standard Input in the following format:
N M K
Output
If Takahashi can have exactly K black squares in the grid, print Yes
; otherwise, print No
.
Sample Input 1
2 2 2
Sample Output 1
Yes
Press the buttons in the order of the first row, the first column.
Sample Input 2
2 2 1
Sample Output 2
No
Sample Input 3
3 5 8
Sample Output 3
Yes
Press the buttons in the order of the first column, third column, second row, fifth column.
Sample Input 4
7 9 20
Sample Output 4
No
1 #include<iostream> 2 #include<cstring> 3 #include<string> 4 #include<cstdio> 5 #include<vector> 6 #include<cmath> 7 #include<stack> 8 #include<set> 9 #include<queue> 10 #include<algorithm> 11 using namespace std; 12 #define in 1000000007 13 int main() 14 { 15 int n,m,p; 16 cin>>n>>m>>p; 17 set<int >s; 18 s.insert(0); 19 for(int i=1;i<=n;i++) 20 { 21 s.insert(i*m); 22 for(int j=1;j<=m;j++) 23 { 24 int t=i*m+j*(n-2*i); 25 s.insert(t); 26 } 27 } 28 for(int j=1;j<=m;j++) 29 { 30 s.insert(j*n); 31 for(int i=1;i<=n;i++) 32 { 33 int t=j*n+i*(m-2*j); 34 s.insert(t); 35 } 36 } 37 if(s.count(p)) cout<<"Yes"<<endl; 38 else cout<<"No"<<endl; 39 return 0; 40 }
以上是关于CODE FESTIVAL 2017 qual A--B-fLIP(换种想法,暴力枚举)的主要内容,如果未能解决你的问题,请参考以下文章
java CODE FESTIVAL 2017 qual B问题A.
CODE FESTIVAL 2017 qual A--B-fLIP(换种想法,暴力枚举)
CODE FESTIVAL 2017 qual A--C - Palindromic Matrix(模拟所有情况,注意细节)
[Atcoder Code Festival 2017 Qual B Problem F]Largest Smallest Cyclic Shift