CodeForces333B :Chips (规律,思维)

题目链接---CodeForces33B:Chips


CodeForces333B :Chips

时间限制:1000MS    内存限制:262144KByte   64位IO格式:%I64d & %I64u
描述

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.

输入

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.

输出

Print a single integer — the maximum points Gerald can earn in this game.

样例输入
Input
3 1
2 2
Output
0
Input
3 0
Output
1
Input
4 3
3 1
3 2
3 3
Output
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).


题意:有一个n*n的棋盘,在棋盘的四边可以放棋子,但在四角不能放,在棋盘上有m个点被ban掉,每个棋子要在接下来n-1步中到达对边,两个棋子不能在同一个位置,两个棋子不能够交换

题解:   如果一行或者一列没有被ban的点的话,那么这一行或者这一列可以放一个棋子,否则不能放,还有就是要考虑一下如果棋盘是奇数边的话,那么中心点最多只能放一个棋子


#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define MAX 1000+5
using namespace std;
int H[MAX],L[MAX];//表示行和列 
int main()
{
	int n,m;
	while(cin>>n>>m)
	{
		int ans=0;
		memset(H,0,sizeof(H));
		memset(L,0,sizeof(L));
		int x,y;
		for(int i=1;i<=m;i++)
		{
			cin>>x>>y;
			H[x]=1;
			L[y]=1; 
		}
		for(int i=2;i<n;i++)
		{
			if(H[i]+L[i]==1)
			ans++;
			else if(H[i]+L[i]==0)
			{
				if(n%2!=0&&(n+1)/2==i)
				ans++;
				else
				ans=ans+2;
			}
		}
		cout<<ans<<endl; 
	} 
return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值