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 ...
随机推荐
- python中发送get或post请求
示例 get import httplib import uuid import time url = "/KM/test.php?time=" url += str(int(ti ...
- linux下挂载CDROM命令
cdrom装载在/dev/cdrom 下面. 挂载时在权限范围内建立一个文件夹.例如mkdir /home/dang/cdtmp 然后执行 mount dev/cdrom /home/dang/cdt ...
- shell脚本练习(随机取名)
1.写一个脚本,实现随机选人功能,脚本需传递一个参数进去,如 pick.sh 1 出现结果"家驹” pick.sh 3 出现结果 "落叶" "jason ...
- 连接oracle数据库出现:ORA-12505,TNS:listener does not currently know of SID given in connect descriptor
Java使用 jdbc:oracle:thin:@11.1.0.14:1521:orcl 连接oracle数据库出现: ORA-12505,TNS:listener does not currentl ...
- Ucenter注册后,需要二次登录才能同步登录的解决方案
1. 打开配置文件config.inc.php 在根目录data目录下最下方定义 define('DZ_DBTABLEPRE', '你的表前缀'); 2.打开uc_server/model/user. ...
- 无法添加sql server ER图
Database diagram support objects cannot be installed because this database does not have a valid own ...
- try-catch-finally块的运行机制
try {}里有一个return语句,那么紧跟在这个try后的finally {}里的code会不会被执行,什么时候被执行,在return前还是后? 也许你的答案是在return之前,但往更细地说,我 ...
- Fatal error: Allowed memory size of 8388608 bytes exhausted
这两天安装bugfree,更换了一个数据量较大的库,结果打开bug详情页要么是空白页,要么就报如题的错误,错误信息还包括C:\wamp\www\bugfree\Include\Class\ADOLit ...
- hdu2208之搜索
唉,可爱的小朋友 Time Limit: 10000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- MSSQL 镜像
1.设置数据库CollectionDB 为完整备份模式服务端: USE master ALTER DATABASE CollectionGuest SET RECOVERY FULL GO 镜相端: ...