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 }
				
时间: 2024-11-06 03:52:23

CODE FESTIVAL 2017 qual A--B-fLIP(换种想法,暴力枚举)的相关文章

[Atcoder Code Festival 2017 Qual B Problem F]Largest Smallest Cyclic Shift

题目大意:给你\(A\)个a,\(B\)个b,\(C\)个c,要你构造一个字符串,使它的最小循环表示法最大.求这个表示法.解题思路:不知道怎么证,但把a.b.c当做单独的字符串扔进容器,每次把字典序最小的和字典序最大的两个字符串合并就是答案.容器用multiset即可. C++ Code: #include<cstdio> #include<set> #include<string> using namespace std; multiset<string>

【AtCoder】CODE FESTIVAL 2017 qual B

最近不知道为啥被安利了饥荒,但是不能再玩物丧志了,不能颓了 饥荒真好玩 A - XXFESTIVAL CCFESTIVAL #include <bits/stdc++.h> #define fi first #define se second #define pii pair<int,int> #define mp make_pair #define pb push_back #define space putchar(' ') #define enter putchar('\n'

CODE FESTIVAL 2017 qual A C Palindromic Matrix(思维题)

题目链接:点我呀 题意:给出n*m由26位小写字母组成的矩阵,问是否能够重构形成一个每行每列都是回文的矩阵 题解:分三种情况考虑(偶偶,奇奇,奇偶),每种情况下考虑最少 需要4个相同字母的字母数,2个相同字母的字母数和一个字母的字母数(只有奇奇的时候才需要一个字母) 最后判断一下.感觉自己的这个代码不是很简洁,明天起来看看别人怎么写的,睡觉去... 1 //Atcoder 3 2 #include <cstring> 3 #include <iostream> 4 #include

CODE FESTIVAL 2017 qual A--C - Palindromic Matrix(模拟所有情况,注意细节)

个人心得:其实本来这题是有规律的不过当时已经将整个模拟过程都构思出来了,就打算试试,将每个字符和总和用优先队列 装起来,然后枚举每个点,同时进行位置标志,此时需要多少个点的时候拿出最大的和出来,若不满足就输出No,结果一直卡在三组 数据.比赛完后一想,优先队列虽然用处大,不过当行列存在奇数的时候此时只要2个就可以,而如果你从最大的4个中拿出来, 那么下一层循环中必然有一个位置无法填充,如此就导致了算法的失败.所以后面建立个奇偶判定就好了. 感悟: 多注意思考和细节,从不同的层次看待问题,既可以全

atcoder CODE FESTIVAL 2017 qual C D - Yet Another Palindrome Partitioning

Problem Statement We have a string s consisting of lowercase English letters. Snuke is partitioning s into some number of non-empty substrings. Let the subtrings obtained be s1, s2, …, sNfrom left to right. (Here, s=s1+s2+…+sN holds.) Snuke wants to

CODE FESTIVAL 2017 qual C F

以上为官方题解..

【Atcoder】CODE FESTIVAL 2017 qual C D - Yet Another Palindrome Partitioning

[题意] 给定只含小写字母的字符串,要求分割成若干段使段内字母重组顺序后能得到回文串,求最少分割段数.n<=2*10^5 [题解] 关键在于快速判断一个字符子串是否合法,容易发现合法仅当不存在或只存在一个奇数字符,其余字符均为偶数. 当涉及到奇偶性(%2)时,很自然能想到异或. 将小写字母a~z转化2^0~2^25,那么一个字符子串合法当且仅当其连续异或值是0或2^i(0<=i<=25). 令f[i]表示前i个合法的最少段数,sum[i]表示异或前缀和,则有: f[i]=min(f[j]

101 to 010 Atcoder CODE FESTIVAL 2017 qual B D

https://www.luogu.org/problemnew/show/AT3575 题解 根本不会.. 错误记录:缺少32行的转移.显然这个转移是必要的 1 #include<cstdio> 2 #include<algorithm> 3 #include<cstring> 4 #include<vector> 5 using namespace std; 6 #define fi first 7 #define se second 8 #define

【AtCoder】CODE FESTIVAL 2017 qual C

A - Can you get AC? No #include <bits/stdc++.h> #define fi first #define se second #define pii pair<int,int> #define pb push_back #define mp make_pair using namespace std; typedef long long int64; char s[15]; int main() { scanf("%s",