贪心 CF 333B Chips
来源:互联网 发布:打字员软件 编辑:程序博客网 时间:2024/05/22 02:10
题目链接:
http://codeforces.com/problemset/problem/333/B
题目意思:
给一个n*n的矩阵,里面有m个障碍点,问最多可以在不是角落的边框上放多少个点,使得所有点的同时向对面移动,不遇到障碍点且不相互冲突。
解题思路:
贪心思想。
首先障碍点所在行和列不能放,然后当n为奇数时,n/2+1行和列只能放一个,其他行或列只要能放就放,因为不冲突,对于任意一行和一列,四种情况中必有一种满足他们两之间不冲突。
代码:
#include<iostream>#include<cmath>#include<cstdio>#include<cstdlib>#include<string>#include<cstring>#include<algorithm>#include<vector>#include<map>#include<set>#include<stack>#include<list>#include<queue>#define eps 1e-6#define INF 0x1f1f1f1f#define PI acos(-1.0)#define ll __int64#define lson l,m,(rt<<1)#define rson m+1,r,(rt<<1)|1//#pragma comment(linker, "/STACK:1024000000,1024000000")using namespace std;/*freopen("data.in","r",stdin);freopen("data.out","w",stdout);*/bool row[1100],col[1100];int main(){ int n,m; while(~scanf("%d%d",&n,&m)) { memset(row,false,sizeof(row)); memset(col,false,sizeof(col)); int a,b; for(int i=1;i<=m;i++) { scanf("%d%d",&a,&b); row[a]=true; //障碍点所在行和列不能放 col[b]=true; } int ans=0; for(int i=2;i<n;i++) //角落的点不能算 { if(!row[i]) ans++; if(!col[i]) ans++; } if((n&1)&&(!row[n/2+1]&&!col[n/2+1])) //n为奇数时,中间的行和列只能算一次,四种方法都不能解决冲突 ans--; printf("%d\n",ans); } return 0;}
- 贪心 CF 333B Chips
- CF-333B - Chips
- CF 333 B.Chips CodeForces【伪容斥】
- Codeforces Round #194 (Div. 1) / 333B Chips(贪心+代码优化)
- cf 484B 二分+贪心
- cf 342B - Xenia and Spies(贪心)
- CF 447B(DZY Loves Strings-贪心)
- CF 509B(Painting Pebbles-贪心)
- CF 538B(Quasi Binary-贪心)
- cf 540b School Marks 贪心
- cf-538B Quasi Binary【贪心】
- CF 557B(Pasha and Tea-贪心)
- CF#321-B - Kefa and Company-贪心-
- cf 349 B. Color the Fence(贪心)
- CF 601B(Lipshitz Sequence-贪心)
- CF 779B Weird Rounding 贪心
- Chips
- CF 196B(Psychos in a Line-单调队列贪心)
- 如何从Windows7系统找回Windows.old文件夹【xitongshoucang】
- js中this的用法
- poj 3468 A Simple Problem with Integers
- 软件设计之UML—UML中的六大关系
- NSString
- 贪心 CF 333B Chips
- 最小值堆-Java实现
- Ubuntu下配置JDK
- android接触--新版本编译OK,系统却起不来
- 长按手势获取UITableView的indexPath值,删除某行
- linux下安装配置R环境相关依赖包
- HDU 1257 最少拦截系统
- 25个增强iOS应用程序性能的提示和技巧--中级篇
- 查找窗口的几种方法