A - 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 for n - 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.
Input
The first line contains two space-separated integers n and m (2 ≤ n ≤ 1000, 0 ≤ m ≤ 105) — the size of the field and the number of banned cells. Next m lines each contain two space-separated integers. Specifically, the i-th of these lines contains numbers xi and yi (1 ≤ xi, yi ≤ n) — the coordinates of the i-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.
Output
Print a single integer — the maximum points Gerald can earn in this game.
Example
3 1
2 2
0
3 0
1
4 3
3 1
3 2
3 3
1
Note
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).
关键是读懂题,大致的题意就是:一个n*n的矩阵四角和中间不能放东西,只能放在其他的边缘部分,刚开始有一些位置已经给定,挪动的过程中不能经过这些位置,要求在n-1步内,把物品从一侧移动到另一侧,且移动的过程中不能有重叠现象(应该是多个物品可以同时移动),问最多有多少这样的位置?
AC代码:
#include<stdio.h> int main()
{
int n, m, x, y;
int ans = ;
bool cell_row[], cell_column[]; scanf("%d%d", &n, &m); int med = (n+)/; for(int i = ; i <= n; i++)
{
cell_column[i] = false;
cell_row[i] = false;
} for(int i = ; i <= m; i++)
{
scanf("%d%d", &x, &y);
cell_column[x] = true;
cell_row[y] = true;
} for(int i = ; i < n; i++)
{
if(!cell_row[i])
ans++;
} for(int i = ; i < n; i++)
{
if(n % == )
{
if(!cell_column[i])
ans++;
}
else if(n % != )
{
if(!cell_column[i] && (cell_row[i] == true || i != med))//如果中间行为true,但是中间列为false也可以
ans++;
}
} printf("%d\n", ans); return ;
}
A - Chips的更多相关文章
- 【UVALive - 5131】Chips Challenge(上下界循环费用流)
Description A prominent microprocessor company has enlisted your help to lay out some interchangeabl ...
- Codeforces Round #194 (Div. 2) D. Chips
D. Chips time limit per test:1 second memory limit per test:256 megabytes input:standard input outpu ...
- 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 ...
- [2011WorldFinal]Chips Challenge[流量平衡]
Chips Challenge Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) ...
- Chips CodeForces - 333B
Chips CodeForces - 333B 题意:有一个n*n的棋盘,其中有m个格子被禁止.在游戏开始前要将一些芯片(?)放到四条边上(但不能是角上).游戏开始后,每次操作将每一个芯片移动到它四周 ...
- [译]Cookies Without Chocolate Chips
Cookies Without Chocolate Chips In the HTTP sense, a cookie is a name with an associated value. A se ...
- Angular Material 学习笔记 Chips
依据 material guidelines, chips 可以用来做 filter https://material.io/design/components/chips.html#filter-c ...
- LeetCode.1217-交换芯片(Play with Chips)
这是小川的第次更新,第篇原创 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第270题(顺位题号是1217).There are some chips, and the i-th ch ...
- 【leetcode】1217. Play with Chips
题目如下: There are some chips, and the i-th chip is at position chips[i]. You can perform any of the tw ...
随机推荐
- POJ3292(素数筛选)
Semi-prime H-numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 8706 Accepted: 3 ...
- L2-020. 功夫传人(dfs+vector 或者 邻接矩阵+dij+优先队列)
L2-020. 功夫传人 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 一门武功能否传承久远并被发扬光大,是要看缘分的.一般来 ...
- C# 获取图片某像素点RGB565值
Project Source Download: http://download.csdn.net/detail/mostone/6360007 [csharp] view plain copy pu ...
- SpringMVC + AJAX 实现多文件异步上传
转自:https://www.jianshu.com/p/f3987f0f471f 今天,我就这个问题来写一篇如何用 SpringMVC + AJAX 实现的多文件异步上传功能.基本的代码还是沿用上篇 ...
- DAY13-前端之JavaScript
JavaScript概述 JavaScript的历史 1992年Nombas开发出C-minus-minus(C--)的嵌入式脚本语言(最初绑定在CEnvi软件中),后将其改名ScriptEase(客 ...
- How to watch property in attrs of directive
Q: I have a controller that has a counter that changes from time to time. That counter is tied to an ...
- java 类中 static 的使用
在类中 static 主要修饰变量,方法及代码块.大致的执行和使用,据个人理解如下: 1.修饰变量: 在修饰变量时,如 ,表示该变量是静态变量,也可称为类变量.当当前变量是静态变量时,该变量被该类的所 ...
- js利用数组实现队列与堆栈效果
之前在写Android的时候,会用到很多的队列与堆栈方式,其实js利用数组可以简单的实现类似的效果. 队列实现 var queue = new Array(); // unshift() 方法可向数组 ...
- day70-oracle 12-Java调用存储过程和存储函数
我们现在调用的是存储过程和存储函数.用CallableSatement调用存储函数和存储过程. RDBMS:关系数据库.使用标准方式调用存储过程.也就是说:在mysql中调用和在oracle中调用的写 ...
- 吐槽下linq to sql的分页功能
在调试程序的时候发现一个非常奇怪的问题: 用使用linq分页,分页到第二页的时候,第二页里面有第一页里出现的数据,开始还以为是. linq语句写的有问题,调试半天,无解.后来发现是因为没有排序的缘故. ...