Codeforces Round #295 (Div. 1) B. Cubes (STL+类拓扑)
来源:互联网 发布:app拍照软件 编辑:程序博客网 时间:2024/06/07 01:58
最近课业繁重,这题写了两天。。昨晚睡觉的时候才突然想到了最后一点的解决方法。
不知道该不该叫做拓扑。。感觉还是挺像的。。就把标题称之为类拓扑了。。这题的方法是用map来标记状态是否存在,然后用类似拓扑的方法不断的找拿走后依然稳定的方块,我用了两个优先队列来维护,分别取最大和最小。然后就是模拟这个过程取方块了。
代码如下:
#include <iostream>#include <string.h>#include <math.h>#include <queue>#include <algorithm>#include <stdlib.h>#include <map>#include <set>#include <stdio.h>using namespace std;#define LL long long#define pi acos(-1.0)const int mod=1e9+9;const int INF=0x3f3f3f3f;const double eqs=1e-9;struct node{ int x, y;}fei[110000];priority_queue<int,vector<int>,greater<int> >q1;priority_queue<int,vector<int>,less<int> >q2;map<pair<int,int>, int> mp;int vis[110000];bool check(int x, int y){ if(mp.find(make_pair(x-1,y+1))!=mp.end()){ if(mp.find(make_pair(x-2,y))==mp.end()&&mp.find(make_pair(x-1,y))==mp.end()) return 0; } if(mp.find(make_pair(x,y+1))!=mp.end()){ if(mp.find(make_pair(x-1,y))==mp.end()&&mp.find(make_pair(x+1,y))==mp.end()) return 0; } if(mp.find(make_pair(x+1,y+1))!=mp.end()){ if(mp.find(make_pair(x+1,y))==mp.end()&&mp.find(make_pair(x+2,y))==mp.end()) return 0; } return 1;}void topo(int n){ int i, j, k=0, u, x, y, v; LL ans=0; map<pair<int,int>,int>::iterator it; for(it=mp.begin();it!=mp.end();it++){ if(check(it->first.first,it->first.second)){ u=it->second; q1.push(u);q2.push(u); } } while(k<n){ if((k&1)==0){ while(!q2.empty()){ u=q2.top(); q2.pop(); if(!vis[u]&&check(fei[u].x,fei[u].y)){ vis[u]=1; break; } } } else{ while(!q1.empty()){ u=q1.top(); q1.pop(); if(!vis[u]&&check(fei[u].x,fei[u].y)){ vis[u]=1; break; } } } ans=(ans*n%mod+u)%mod; mp.erase(make_pair(fei[u].x,fei[u].y)); //printf("%d\n",u); x=fei[u].x-1;y=fei[u].y-1; if(mp.find(make_pair(x,y))!=mp.end()){ v=mp[make_pair(x,y)]; if(!vis[v]&&check(x,y)){ q1.push(v); q2.push(v); } } x=fei[u].x;y=fei[u].y-1; if(mp.find(make_pair(x,y))!=mp.end()){ v=mp[make_pair(x,y)]; if(!vis[v]&&check(x,y)){ q1.push(v); q2.push(v); } } x=fei[u].x+1;y=fei[u].y-1; if(mp.find(make_pair(x,y))!=mp.end()){ v=mp[make_pair(x,y)]; if(!vis[v]&&check(x,y)){ q1.push(v); q2.push(v); } } k++; } printf("%I64d\n",ans);}int main(){ int n, i, j, pos, x, y; scanf("%d",&n); mp.clear(); memset(vis,0,sizeof(vis)); for(i=0;i<n;i++){ scanf("%d%d",&fei[i].x,&fei[i].y); mp[make_pair(fei[i].x,fei[i].y)]=i; } topo(n); return 0;}
1 0
- Codeforces Round #295 (Div. 1) B. Cubes (STL+类拓扑)
- stl模拟 Codeforces Round #295 (Div. 1) B. Cubes
- Codeforces Round #295 (Div. 1) B. Cubes
- Codeforces Round #295 (Div. 1) B. Cubes(最大最小堆+拓扑模拟)
- Codeforces Round #295 (Div. 2) D.Cubes(STL)
- Codeforces Round #395(Div. 2)B. Timofey and cubes【模拟】
- Codeforces Round #444 (Div. 2) B. Cubes for Masha
- Codeforces Round #444 (Div. 2) B. Cubes for Masha
- Codeforces Round #444(Div.2) B. Cubes for Masha
- Codeforces Round #295 (Div. 2) D.Cubes(STL SET应用)
- Codeforces Round #356 (Div. 1)-B. Bear and Tower of Cubes
- Codeforces Round #295 (Div. 1) (A B)
- 【Codeforces Round #395 (Div. 2)】Codeforces 764B Timofey and cubes
- Codeforces Round #286 (Div. 1) B. Mr. Kitayuta's Technology 连通分量 拓扑排序
- Codeforces Round #292 (Div. 1) B. Drazil and Tiles(拓扑排序)
- Codeforces Round #395 (Div. 2) B. Timofey and cubes(水题)
- Codeforces Round #315 (Div. 2) B. Inventory (STL)
- Codeforces Round #294 (Div. 2)(B)STL multiset
- 【ssh】——Struts2从前端传值到后台的三种方法(从属性到ModelDriven)
- 横向合并查询结果
- javaMail异常 NoClassDefFoundError: com/sun/mail/util/LineInputStream
- 不用第三个变量交换2个变量的值
- select与pselect的信号屏蔽
- Codeforces Round #295 (Div. 1) B. Cubes (STL+类拓扑)
- MFC创建线程(工作线程和界面线程)
- Git客户端使用 —— TortoiseGit
- leetcode Reverse Integer
- AutoCompleteExtender详细介绍(二)
- Python获取时间
- Sass、LESS 和 Stylus
- sigprocmask 阻塞进程
- sourceinsight软件添加Include文件技巧