Codeforces Round #194 (Div. 2) D. Chips
3409 단어 codeforces
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 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:
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 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.
Output
Print a single integer — the maximum points Gerald can earn in this game.
Sample test(s)
Input
3 1
2 2
Output
0
Input
3 0
Output
1
Input
4 3
3 1
3 2
3 3
Output
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).
먼저 저항이 없을 때 규칙을 찾은 다음에 저항이 있는 줄이나 열을 제거한다
#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
",res);
}
return 0;
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Codeforces Round #715 Div. 2C The Sports Festival: 구간 DP전형구간 DP의 초전형. 이하, 0-indexed. 입력을 정렬하여 어디서나 시작하고 최적으로 좌우로 계속 유지하면 좋다는 것을 알 수 있습니다. {2000})$의 주문이 된다. 우선, 입력을 소트하여 n개의 요소를 $...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.