Codeforces Round #194 (Div. 2) D. Chips
Gerald plays the following game. He has a checkered field of size n × n cells, where m various cells are banned. Before the game, he has to put a few chips on some border (but not corner) board cells. Then forn - 1 minutes, Gerald every minute moves each chip into an adjacent cell. He moves each chip from its original edge to the opposite edge. Gerald loses in this game in each of the three cases:
- At least one of the chips at least once fell to the banned cell.
- At least once two chips were on the same cell.
- At least once two chips swapped in a minute (for example, if you stand two chips on two opposite border cells of a row with even length, this situation happens in the middle of the row).
In that case he loses and earns 0 points. When nothing like that happened, he wins and earns the number of points equal to the number of chips he managed to put on the board. Help Gerald earn the most points.
The first line contains two space-separated integers n andm (2 ≤ n ≤ 1000,0 ≤ m ≤ 105) — the size of the field and the number of banned cells. Nextm lines each contain two space-separated integers. Specifically, thei-th of these lines contains numbersxi andyi (1 ≤ xi, yi ≤ n) — the coordinates of thei-th banned cell. All given cells are distinct.
Consider the field rows numbered from top to bottom from 1 to n, and the columns — from left to right from 1 to n.
Print a single integer — the maximum points Gerald can earn in this game.
3 1
2 2
0
3 0
1
4 3
3 1
3 2
3 3
1
In the first test the answer equals zero as we can't put chips into the corner cells.
In the second sample we can place one chip into either cell (1, 2), or cell (3, 2), or cell (2, 1), or cell (2, 3). We cannot place two chips.
In the third sample we can only place one chip into either cell (2, 1), or cell (2, 4).
先按照没有阻挡的时候找到规律,然后去掉那些带阻挡的行或列
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#define N 1100
using namespace std;
bool row[N],col[N];
int main()
{
int n,m;
while(scanf("%d %d",&n,&m)!=EOF)
{
memset(row,true,sizeof(row));
memset(col,true,sizeof(col));
while(m--)
{
int x,y;
scanf("%d %d",&x,&y);
row[x] = false;
col[y] = false;
}
int res = 0;
for(int i=2;i<=n-1;i++)
{
if(n%2&&i==n/2+1)
{
continue;
}
if(col[i])
{
res++;
}
if(row[i])
{
res++;
}
}
if(n%2&&(col[n/2+1]||row[n/2+1]))
{
res++;
}
printf("%d\n",res);
}
return 0;
}
Codeforces Round #194 (Div. 2) D. Chips的更多相关文章
- Codeforces Round #194 (Div. 1) B. Chips 水题
B. Chips Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/333/problem/B D ...
- 套题:Codeforces Round #194 (Div. 1) (2/5)
A. Secrets http://www.cnblogs.com/qscqesze/p/4528529.html B. Chips http://www.cnblogs.com/qscqesze/p ...
- Codeforces Round #194 (Div. 1) A. Secrets 数学
A. Secrets Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/333/problem/A ...
- [Codeforces Round #194 (Div. 2)] Secret 解题报告 (数学)
题目链接:http://codeforces.com/problemset/problem/334/C 题目: 题目大意: 给定数字n,要求构建一个数列使得数列的每一个元素的值都是3的次方,数列之和S ...
- Codeforces Round #194 (Div. 2) 部分题解
http://codeforces.com/contest/334 A题意:1-n^2 平均分成 n 份,每份n个数,且和相同 解法 : 构造矩阵1-n^2的矩阵即可 ][]; int main() ...
- Codeforces Round #194 (Div.1 + Div. 2)
A. Candy Bags 总糖果数\(\frac{n^2(n^2+1)}{2}\),所以每人的数量为\(\frac{n}{2}(n^2+1)\) \(n\)是偶数. B. Eight Point S ...
- Codeforces Round #582 (Div. 3) A. Chips Moving
传送门 题解: 给你n个数的坐标,你需要把他们移动到一个位置,有两种移动方式 1.向左或者右移动2 2.向左或者右移动1,但是耗费1 求最小耗费 题解: 很简单就可以想到,看一下偶数坐标多还是奇数坐标 ...
- Educational Codeforces Round 84 (Div. 2)
Educational Codeforces Round 84 (Div. 2) 读题读题读题+脑筋急转弯 = =. A. Sum of Odd Integers 奇奇为奇,奇偶为偶,所以n,k奇偶性 ...
- Codeforces Round #366 (Div. 2) ABC
Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...
随机推荐
- Ubuntu系统下搭建Python开发环境
之前演示了在Windows中安装Pycharm,很简单.下面介绍一下如何在Ubuntu中安装Pycharm 1.更新Python至3.5.1,执行以下命令: sudo add-apt-reposito ...
- POJ 1269 - Intersecting Lines 直线与直线相交
题意: 判断直线间位置关系: 相交,平行,重合 include <iostream> #include <cstdio> using namespace std; str ...
- (原)ubuntu16中编译boost1.61.0库
转载请注明出处: http://www.cnblogs.com/darkknightzh/p/5797940.html 参考网址: http://www.boost.org/doc/libs/1_61 ...
- eclipse中配置免安装tomcat7
参看如下链接:http://hi.baidu.com/gpy11/item/744c13e14614c9b52e140b25
- struts2.x中因变量命名错误不被注入到值栈的问题
//I declare... private String aBC="abc"; Then I Alt+Shift+R and S(Generate Getter/Setter) ...
- jQuery对checkbox的各种操作
//注意: 操作checkbox的checked,disabled属性时jquery1.6以前版本用attr,1.6以上(包含)建议用prop //1.根据id获取checkbox $("# ...
- 不用图片,纯Css3实现超酷的类似iphone的玻璃气泡效果
最近在一个私活做手机项目时候,需要实现一个类似ios 6中短信那样的气泡效果. 这里分享下实现心得,希望能给大家一点启发. 首先分析下iphone的气泡效果有一下特点 1. 四面圆角 2. 界面上向下 ...
- debian 64位系统中添加对32位的支持
dpkg --add-architecture i386 apt-get update apt-get install ia32-libs
- WordPress插件制作笔记(二)---Second Plugins Demo
1->插件演示代码:下载地址:http://pan.baidu.com/s/1gd1lFlL 在 wordpress/wp-content/plugins/ 目录下 新建一个文件夹取名为seco ...
- MySQL用户管理语句001
总的来说mysql的用户管理方法可以分为如下两种: 1.直接对mysql.user 表进行[insert | update | delete] + flush privileges 这种方式主要针对那 ...