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≤KNM

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

Copy
2 2 2

Sample Output 1

Copy
Yes

Press the buttons in the order of the first row, the first column.


Sample Input 2

Copy
2 2 1

Sample Output 2

Copy
No

Sample Input 3

Copy
3 5 8

Sample Output 3

Copy
Yes

Press the buttons in the order of the first column, third column, second row, fifth column.


Sample Input 4

Copy
7 9 20

Sample Output 4

Copy
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 }

 



posted @ 2017-09-24 10:29  余生漫漫浪  阅读(217)  评论(0编辑  收藏  举报