B - fLIP

原题地址:http://code-festival-2017-quala.contest.atcoder.jp/tasks/code_festival_2017_quala_b

Time limit : 2sec / Memory limit : 256MB

Score : 200 points

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
题目意思:给一个N*M的方格,刚开始都是白色的,每次可以对一列或一行进行操作;
      使颜色反向;问是否可以得到K个黑色方块;
解题思路:遍历进行行列的操作;看是否可以出现K个方块;
#include<iostream>
#include<string>
#include<algorithm>
#include <string.h>
#include <stdio.h>
#include <math.h>
#include <set>
#include <queue>
#include <stack>
#include <map>
 
using namespace std;
typedef long long LL;
const int INF = int(1e9);
 
int main()
{
    int N,M,K;
    cin>>N>>M>>K;
    for(int i = 0;i<=N;i++){
        for(int j = 0;j<=M;j++){
            int temp = i*M+j*N -2*i*j;
            if(temp==K)
            {
                cout<<"Yes"<<endl;
                return 0;
            }
        }
    }
 
    cout<<"No"<<endl;
 
    return 0;
}

 

 

转载于:https://www.cnblogs.com/a2985812043/p/7749310.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值