Codeforces Problem 333B
来源:互联网 发布:网络文字录入员 编辑:程序博客网 时间:2024/05/22 12:30
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.
3 12 2
0
3 0
1
4 33 13 23 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).
题意:有n*n的网格,其中有m个格子是禁止进入的,问最多能放几个chip
要求:
1.chip只能放在除角落外的边界处
2.每分钟可以让每个chip移动到相邻的格子
3.chip不能移入禁止的格子内
4.两个chip不能同时在一个格子内
5.两个chip不能交换位置
6.每个chip要在n-1分钟内移到对面的边界处
思路:每个可以放chip的格子的放置情况只会影响到另外三个可以放置chip的格子,对每行的第一个格子进行判断放置情况,取最优,可以得到答案
某一行或列有禁止格子则不能放chip
判断上下两个位置能放的个数和左右两个能放的个数,取多的
这种情况时最多只能放一个
#include<iostream>#include<string.h>#include<stdio.h>#define LL long longusing namespace std;int n,m,visx[1010],visy[1010];int main(){ scanf("%d%d",&n,&m); for(int i=0;i<m;i++){ int x,y; scanf("%d%d",&x,&y); visx[x] = visy[y] = 1; } int ans = 0; for(int i=2;i<=n-1;i++){ int x = visx[i] + visx[n-i+1]; int y = visy[i] + visy[n-i+1]; if(i==n-i+1){ if(visx[i]==0||visy[i]==0) ans++; continue; } if(x>y){ visy[i] = visy[n-i+1] = 1; ans+=2-y; } else{ visx[i] = visx[n-i+1] = 1; ans+=2-x; } } printf("%d\n",ans); return 0;}
- Codeforces Problem 333B
- Problem - 216B - Codeforces
- Problem - 218B - Codeforces
- codeforces problem/408/B
- Codeforces Problem - 50B
- Problem - 376B - Codeforces
- problem - 616B -codeforces
- Codeforces Problem 332B
- codeforces-Problem 193B - Xor
- Codeforces Problem 499B. Lecture
- codeforces 278B New Problem
- Codeforces Problem - 617B Chocolate
- Problem--158B--Codeforces--Taxi
- codeforces 782/problem/B [二分]
- codeforces/contest/797/problem/B
- codeforces/contest/798/problem/B
- B. Secret Combination codeforces-problem-496B
- B. Internet Address codeforces-problem-245B
- 深度学习与神经网络习题(1)
- git命令之merge
- 第七周 项目 3
- 小技巧:把风扇的扇叶取下来
- 解决ubuntu16.04升级内核后耳机没声音的问题
- Codeforces Problem 333B
- nodejs 搭建https服务
- 当一个bug困扰你很久都解决不了的时候,它很可能就是一个低级错误
- CodeVS 1183 SPFA+二分答案 解题报告
- 递归知识
- 左值与右值
- Java中继承和多态,重写与重载的区别
- 线性表及其链式表示
- 计蒜客ACM ICPC 2017 Warmup Contest 9--I题-Older Brother