跳过正文
  1. Posts/

hdu 5630 Rikka with Chess (暴力 ,计数问题)

·1 分钟

http://acm.hdu.edu.cn/showproblem.php?pid=5630 题意:nm的棋盘,相邻格子的颜色相反,每次可以翻转一个任意大小矩形的格子,问最少需要翻转多少次使得棋盘的nm个格子颜色相同。(翻转的意思是颜色反色)

思路:手写了下。。发现。。答案就是n/2+m/2. 对应的最优策略是。。翻偶数行和偶数列,都翻一遍,颜色就一样了。

 1/* ***********************************************
 2Author :111qqz
 3Created Time :2016年03月03日 星期四 20时47分47秒
 4File Name :code/hdu/5630.cpp
 5************************************************ */
 6
 7#include <cstdio>
 8#include <cstring>
 9#include <iostream>
10#include <algorithm>
11#include <vector>
12#include <queue>
13#include <set>
14#include <map>
15#include <string>
16#include <cmath>
17#include <cstdlib>
18#include <ctime>
19#define fst first
20#define sec second
21#define lson l,m,rt<<1
22#define rson m+1,r,rt<<1|1
23#define ms(a,x) memset(a,x,sizeof(a))
24typedef long long LL;
25#define pi pair < int ,int >
26#define MP make_pair
27
28using namespace std;
29const double eps = 1E-8;
30const int dx4[4]={1,0,0,-1};
31const int dy4[4]={0,-1,1,0};
32const int inf = 0x3f3f3f3f;
33int n,m;
34int main()
35{
36	#ifndef  ONLINE_JUDGE
37	freopen("code/in.txt","r",stdin);
38  #endif
39
40	ios::sync_with_stdio(false);
41	int T;
42	cin>>T;
43	while (T--)
44	{
45	    cin>>n>>m;
46	    cout<<n/2+m/2<<endl;
47	}
48
49  #ifndef ONLINE_JUDGE
50  fclose(stdin);
51  #endif
52    return 0;
53}

相关文章

codeforces 522 A. Vanya and Table

http://codeforces.com/problemset/problem/552/A 题意:一个100*100的网格。然后给n个矩形。每个格子中填上包含这个格子的矩形的个数。最后问所有格子的和。 思路:树状数组搞得…然而..直接求所有矩形面积的和就可以啊喂。。o(n)。。。111qqz你个炒鸡大菜鸡。

hdu 1205 吃糖果 (鸽笼原理)

·1 分钟
http://acm.hdu.edu.cn/showproblem.php?pid=1205 题意:有n种糖果,第i种糖果有a[i]个,相邻两次不能吃一样的糖果,问能否有办法吃完所有糖果… 思路:如果第i种糖果有k个的话,那么其他所有种类的糖果之和至少有k-1个,才可能吃完。复杂度O(n) 看到有人说是抽屉原理…..大概。。。?不过不太明显。。直接想就好吧