B. Chips
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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.

Examples
input
3 1
2 2
output
0
input
3 0
output
1
input
4 3
3 1
3 2
3 3
output
1

题意:在一个n*n的矩阵的边上的单元格(角上的单元格不能放)中放入chip,每秒种chip向着它的对边移动一个单元格,进行n-1秒
以下三种情况为输得0分:
  1.两个chip出现在同一个单元格中。
  2.两个chip在一秒中互换位置。
  3.至少一个chip落在禁止的单元格中。
矩阵中可以放的chip数的最大值为其得分。 思路:初看无思路。(目前看来比较暴力)从第2行开始遍历行,若无障碍,可放一个,与该行沿对角线对称的列上,若无障碍则也可放一个,这个规则一定成立。若n等于奇数,则需考虑特殊情况,若n/2+1行和n/2+1列均无障碍的情况下,这一行和这一列一共只能放一个。
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
#define N 1005 int map[N][N]; int main()
{
int n,m,x,y,mr=,mc=;
scanf("%d%d",&n,&m);
for(int i=; i<m; i++)
{
scanf("%d%d",&x,&y);
map[x][y]=-;
}
int res=;
for(int i=; i<n; i++)
{
int ok=;
for(int j=;j<=n;j++)
{
if(map[i][j]==-)
{
ok=;
if(n%==&&(i==n/+))
mr=;
break;
}
}
if(ok)
res++;
ok=;
for(int j=;j<=n;j++)
{
if(map[j][i]==-)
{
ok=;
if(n%==&&i==(n/+))
mc=;
break;
}
}if(ok)
res++;
}
if(n%==&&mc==&&mr==)
res--;
printf("%d\n",res);
return ;
}

最新文章

  1. 表现层的设计(二)——MVC如何处理复杂的界面元素
  2. 为sproto手写了一个python parser
  3. liunx CentOS 升级Python版本
  4. SplashTop Remote + 4核android平板 试用
  5. NET Core中使用Redis
  6. hdu 2824 The Euler function
  7. 用Rufus来制作Windows10的U盘安装盘
  8. window2003安全设置
  9. IT传道解惑:心累了就读读
  10. asp.net实现伪静态遇到的问题
  11. backup mysql for xtrabackup with xbstream and lz4
  12. 从此不再担心键盘遮住输入框OC(一)
  13. 【编程笔记】Unity3D语言的类型系统--C#的类型系统
  14. 基于 MySQL 的数据库实践(自然连接)
  15. C#中的RDLC报告
  16. &lt;el-upload&gt;&lt;/el-upload&gt;组件上传图片到七牛云
  17. koa2源码解读及实现一个简单的koa2框架
  18. mysql慢日志, 锁表情况查询
  19. 使用tcpdump探测TCP/IP三次握手
  20. caffe安装

热门文章

  1. Cocos2dx使用ios内支付IAP具体流程-白白
  2. Unity3D研究之多语言用中文做KEY
  3. 动态JSP的了解
  4. Oculus Rift DK2 驱动安装教程
  5. 【codeforces379F】 New Year Tree
  6. 【转】Material Design 折叠效果 Toolbar CollapsingToolbarLayout AppBarLayout
  7. [Codeforces Round 486A] Fair
  8. ZOJ3962 2017 E.Seven Segment Display
  9. Java properties配置文件
  10. ASP.Net 知识点总结(三)