hdu5925 Coconuts
来源:互联网 发布:js时间转换日期格式 编辑:程序博客网 时间:2024/06/06 18:12
比完看acdream说这题是签到题 怎么都不会写
我现在补完也觉得 这不是傻逼题么
我我这个这么快5题的人真的不应该啊
#include<bits/stdc++.h>using namespace std;typedef long long ll;#define sz(X) ((int)X.size())const int MAXN = 505;const int INF = 0x3f3f3f3f;int R,C,n;int dir[][4] = { {1,0}, {-1,0}, {0,-1}, {0,1} };int X[MAXN], Y[MAXN];int has[MAXN]; int pos[MAXN]; int tot;int v1[MAXN]; int vx;int v2[MAXN]; int vy;vector<ll> Ans;int vis[MAXN][MAXN];void bfs(int x,int y) {// printf("%d %d\n",x,y); queue<pair<int,int>> Q; Q.push({x,y}); vis[x][y] = 1; ll ans = 0; while(!Q.empty()) { int t1 = Q.front().first; int t2 = Q.front().second; Q.pop(); ans += 1ll*v1[t1]*v2[t2]; for(int i = 0; i < 4; ++i) { int xx = t1+dir[i][0]; int yy = t2+dir[i][1]; if(xx >= 1 && xx <= vx && yy >= 1 && yy <= vy && !vis[xx][yy]) { vis[xx][yy] = 1; Q.push({xx,yy}); } } } Ans.push_back(ans);}int main(){ int _; scanf("%d",&_); for(int cas=1;cas<=_;cas++) { Ans.clear(); memset(vis,0,sizeof(vis)); scanf("%d %d %d",&R,&C,&n); for(int i = 0; i < n; ++i) { scanf("%d %d",&X[i],&Y[i]); } tot = 0; for(int i = 0; i < n; ++i) { has[tot++] = X[i]; } sort(has,has+tot); tot = unique(has,has+tot) - has; int pre = 0; vx = 0; for(int i = 0; i < tot; ++i) { if(pre+1 < has[i]) v1[++vx] = has[i]-pre-1; v1[++vx] = 1; pos[i] = vx; pre = has[i]; } if(has[tot-1] < R) v1[++vx] = R-has[n-1]; for(int i = 0; i < n; ++i) { int tt = lower_bound(has,has+tot,X[i]) - has; X[i] = pos[tt]; } tot = 0; for(int i = 0; i < n; ++i) { has[tot++] = Y[i]; } sort(has,has+tot); tot = unique(has,has+tot) - has; pre = 0; vy = 0; for(int i = 0; i < tot; ++i) { if(pre+1 < has[i]) v2[++vy] = has[i]-pre-1; v2[++vy] = 1; pos[i] = vy; pre = has[i]; } if(has[tot-1] < C) v2[++vy] = C-has[n-1]; for(int i = 0; i < n; ++i) { int tt = lower_bound(has,has+tot,Y[i]) - has; Y[i] = pos[tt]; } for(int i = 0; i < n; ++i) { vis[X[i]][Y[i]] = 1; } // printf("hh\n"); for(int i = 1; i <= vx; ++i) for(int j = 1; j <= vy; ++j) { if(!vis[i][j]) { bfs(i,j); } } // for(int i = 1; i <= vx; ++i) printf("%d ",v1[i]); printf("\n"); // for(int i = 1; i <= vy; ++i) printf("%d ",v2[i]); printf("\n"); // for(int i = 0; i < n; ++i) printf("%d %d\n",X[i],Y[i]); sort(Ans.begin(), Ans.end()); printf("Case #%d:\n%d\n",cas,sz(Ans)); for(int i = 0; i < sz(Ans); ++i) { if(i) printf(" "); printf("%lld",Ans[i]); } printf("\n"); } return 0; }
0 0
- hdu5925 Coconuts
- HDU5925-Coconuts
- hdu5925 Coconuts(离散化+BFS)
- hdu5925 Coconuts 【离散化+bfs】
- HDU5925:Coconuts(二维坐标离散化 + DFS)
- hdu5925 Coconuts 离散化 dfs搜索 TWT Tokyo Olympic 1combo-1
- Coconuts
- 【HDU5925 2016CCPC东北地区大学生程序设计竞赛 - 重现赛 D】【离散化 BFS】Coconuts 大地图少数坏点输出每个联通块的大小
- Coconuts, Revisited
- Coconuts HDU
- hdu5925 离散化+bfs
- fjnu 1688 Coconuts, Revisited
- hdu 1346 Coconuts, Revisited
- 【spoj1693】【最小割】Coconuts
- hdu 1346 Coconuts, Revisited
- Coconuts----DFS+离散化
- D - Coconuts HDU - 5925
- HDU 5925Coconuts
- 四路红外循迹
- python字符串2
- 稳定排序和不稳定排序
- 自我修行经典书籍
- 穿秋裤啦
- hdu5925 Coconuts
- KMP模式匹配算法
- ssh秘钥配置
- Android Studio查看Gradle版本
- P3143 [USACO16OPEN]钻石收藏家Diamond Collector
- JVM是什么?
- 不一样的国庆
- 堆排序算法
- Android中View的setTag和getTag方法