CF 243C Colorado Potato Beetle(BFS+离散化)
来源:互联网 发布:matlab k聚类算法 编辑:程序博客网 时间:2024/05/19 16:33
转载请注明出处,谢谢http://blog.csdn.net/ACM_cxlove?viewmode=contents by---cxlove
题意:给出一个非常大的农田,农夫从中心出发,走过的地方,都会撒农药。
害虫可以按4邻接扩散,问有多少块农田没有被破坏
http://codeforces.com/problemset/problem/243/C
我会说我题目看了很久?
哎,这两天真心后悔六级没报上名,我急着要六级证书啊, 不过估计也过了。
虽然地图非常大,但是路径是有限的,而且相对于只是细细的长条,所以直接成了矩形面积并。
而且由于是细细的长条,那么直接离散化后暴力染色。
然后从边界开始,BFS搜索,把害虫能覆盖的染色
最后继续暴力统计,最后还挺快,呵呵,最多也就2000*2000吧。
#include<iostream> #include<cstdio> #include<map> #include<cstring> #include<cmath> #include<vector> #include<stack>#include<algorithm> #include<set> #include<string> #include<queue> #define inf 10000000005LL#define M 1000005 #define N 1000005#define maxn 2000005 #define eps 1e-7#define zero(a) fabs(a)<eps #define Min(a,b) ((a)<(b)?(a):(b)) #define Max(a,b) ((a)>(b)?(a):(b)) #define pb(a) push_back(a) #define mp(a,b) make_pair(a,b) #define mem(a,b) memset(a,b,sizeof(a)) #define LL long long #define MOD 1000000007#define lson step<<1#define rson step<<1|1#define sqr(a) ((a)*(a)) #define Key_value ch[ch[root][1]][0] #define test puts("OK");#define pi acos(-1.0)#define lowbit(x) ((x)&(-(x)))#pragma comment(linker, "/STACK:1024000000,1024000000") using namespace std;struct Node{ int x1,x2,y1,y2; Node(){} Node(int _x1,int _y1,int _x2,int _y2):x1(_x1),y1(_y1),x2(_x2),y2(_y2){}}rec[1005];int way[4][2]={0,1,0,-1,1,0,-1,0};int m;int vis[2005][2005]={0};vector<LL>x,y;queue<pair<LL,LL> >que;int id(char ch){ if(ch=='R') return 0; if(ch=='L') return 1; if(ch=='U') return 3; return 2;}int Bin(vector<LL>v,LL num){ return find(v.begin(),v.end(),num)-v.begin();}int main(){ int x1=0,y1=0,x2,y2; scanf("%d",&m); x.pb(-inf);x.pb(inf); y.pb(-inf);y.pb(inf); for(int i=0;i<m;i++){ char str[5];int val; scanf("%s%d",&str,&val); int idx=id(str[0]); x2=x1+way[idx][0]*val;y2=y1+way[idx][1]*val; x.pb(min(x1,x2));x.pb(max(x1,x2)+1); y.pb(min(y1,y2));y.pb(max(y1,y2)+1); rec[i]=Node(min(x1,x2),min(y1,y2),max(x1,x2)+1,max(y1,y2)+1); x1=x2;y1=y2; } sort(x.begin(), x.end()); sort(y.begin(), y.end()); x.resize(unique(x.begin(), x.end())-x.begin()); y.resize(unique(y.begin(), y.end())-y.begin()); for(int i=0;i<m;i++){ x1=Bin(x,rec[i].x1);x2=Bin(x,rec[i].x2)-1; y1=Bin(y,rec[i].y1);y2=Bin(y,rec[i].y2)-1; for(int j=x1;j<=x2;j++) for(int k=y1;k<=y2;k++) vis[j][k]=1; } que.push(mp(0,0)); vis[0][0]=2; while(!que.empty()){ pair<LL,LL>u,v; u=que.front(); que.pop(); for(int i=0;i<4;i++){ v=u; v.first+=way[i][0]; v.second+=way[i][1]; if(v.first>=0&&v.first<x.size()&&v.second>=0&&v.second<y.size()&&vis[v.first][v.second]==0){ vis[v.first][v.second]=2; que.push(v); } } } LL ans=0; for(int i=0;i<x.size()-1;i++) for(int j=0;j<y.size()-1;j++) if(vis[i][j]!=2) ans+=(LL)(x[i+1]-x[i])*(y[j+1]-y[j]); printf("%I64d\n",ans); return 0;}
- CF 243C Colorado Potato Beetle(BFS+离散化)
- codeforce-243C:Colorado Potato Beetle(BFS+离散化+暴力)
- CF-29C - Mail Stamps(DFS+离散化)
- cf#345-C - Watchmen-map离散化
- Ice Cave-CF-C(bfs)
- 【CF 713C】Sonya and Problem Wihtout a Legend(离散化+dp)<POJ 3666变形>
- 动态规划,离散化(Sonya and Problem Wihtout a Legend,cf 713C)
- hdu5925 离散化+bfs
- CF 558C 暴力,bfs
- Beetle
- C. Ice Cave (CF #301 (Div. 2) 搜索bfs)
- (CF 788)C. The Great Mixing <BFS>
- hdu5925 Coconuts(离散化+BFS)
- hdu5925 Coconuts 【离散化+bfs】
- hdu 5925(离散化+BFS)
- cf#301-C. Ice Cave-BFS
- CF Cleaner Robot (BFS)
- Potato项目文档(2)
- 获取新数据的主键值
- centos下adsl自动拨号设置
- free问题
- 中国网民在裸奔
- 图及其遍历的各种算法小结
- CF 243C Colorado Potato Beetle(BFS+离散化)
- YUM常用命令介绍
- 中国互联网的耻辱
- 安装centos开发包
- 关于网易的回忆
- Unity3D基础知识梳理<转>
- 将返回的数据集转换成树
- 暴风和网易,谁是流氓?
- 关于思科发现协议cdp的几点注意事项