多多色-多人伦交性欧美在线观看-多人伦精品一区二区三区视频-多色视频-免费黄色视屏网站-免费黄色在线

國內最全IT社區平臺 聯系我們 | 收藏本站
阿里云優惠2
您當前位置:首頁 > php開源 > php教程 > Codeforces 520D. Cubes 貪心模擬

Codeforces 520D. Cubes 貪心模擬

來源:程序員人生   發布時間:2015-04-11 09:25:06 閱讀次數:3964次



每步都取當前穩定的格子里面數字最大或最小的數.

用1個set保護當前可取的格子 *begin 最大  *(--end) 最小

每刪除1個格子都要對這個格子周圍的6個格子進行穩定性檢查

1個格子上面的3個格子肯定了這個格子的穩定性

D. Cubes
time limit per test
3 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Once Vasya and Petya assembled a figure of m cubes, each of them is associated with a number between 0 and m?-?1 (inclusive, each number appeared exactly once). Let's consider a coordinate system such that the OX is the ground, and the OY is directed upwards. Each cube is associated with the coordinates of its lower left corner, these coordinates are integers for each cube.

The figure turned out to be stable. This means that for any cube that is not on the ground, there is at least one cube under it such that those two cubes touch by a side or a corner. More formally, this means that for the cube with coordinates (x,?y) either y?=?0, or there is a cube with coordinates (x?-?1,?y?-?1)(x,?y?-?1) or (x?+?1,?y?-?1).

Now the boys want to disassemble the figure and put all the cubes in a row. In one step the cube is removed from the figure and being put to the right of the blocks that have already been laid. The guys remove the cubes in such order that the figure remains stable. To make the process more interesting, the guys decided to play the following game. The guys take out the cubes from the figure in turns. It is easy to see that after the figure is disassembled, the integers written on the cubes form a number, written in the m-ary positional numerical system (possibly, with a leading zero). Vasya wants the resulting number to be maximum possible, and Petya, on the contrary, tries to make it as small as possible. Vasya starts the game.

Your task is to determine what number is formed after the figure is disassembled, if the boys play optimally. Determine the remainder of the answer modulo 109?+?9.

Input

The first line contains number m (2?≤?m?≤?105).

The following m lines contain the coordinates of the cubes xi,?yi (?-?109?≤?xi?≤?1090?≤?yi?≤?109) in ascending order of numbers written on them. It is guaranteed that the original figure is stable.

No two cubes occupy the same place.

Output

In the only line print the answer to the problem.

Sample test(s)
input
3 2 1 1 0 0 1
output
19
input
5 0 0 0 1 0 2 0 3 0 4
output
2930


/* *********************************************** Author :CKboss Created Time :2015Äê03ÔÂ03ÈÕ ÐÇÆÚ¶þ 23ʱ46·Ö15Ãë File Name :D.cpp ************************************************ */ #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <string> #include <cmath> #include <cstdlib> #include <vector> #include <queue> #include <set> #include <map> using namespace std; typedef long long int LL; const LL mod = 1e9+9; const int maxn=100100; struct BOX { int x,y,id; }box[maxn]; typedef pair<int,int> pII; int n; map<pII,int> mPI; set<pII> Pt; set<int> St; bool isST(int id) { int x=box[id].x; int y=box[id].y; pII tp; /// check (x⑴,y+1) tp = make_pair(x⑴,y+1); if(Pt.count(tp)==1) { if(Pt.count( make_pair(x⑵,y) ) || Pt.count( make_pair(x⑴,y) )) ; else return false; } /// check (x,y+1) tp = make_pair(x,y+1); if(Pt.count(tp)==1) { if(Pt.count( make_pair(x⑴,y) ) || Pt.count( make_pair(x+1,y) )) ; else return false; } /// check (x+1,y+1) tp = make_pair(x+1,y+1); if(Pt.count(tp)==1) { if(Pt.count( make_pair(x+1,y) ) || Pt.count( make_pair(x+2,y) )) ; else return false; } return true; } void checkST(int id) { if(isST(id)) { St.insert(id); } else { if(St.count(id)) St.erase(id); } } void checkround(int id) { int x=box[id].x; int y=box[id].y; checkST(id); for(int i=⑴;i<=1;i++) /// dx { for(int j=⑴;j<=1;j+=2) /// dy { int nx=x+i,ny=y+j; pII tp = make_pair(nx,ny); if(Pt.count(tp)==1) { int dd=mPI[tp]; checkST(dd); } } } } void Remove(int id) { int x=box[id].x; int y=box[id].y; /// erase Pt.erase(make_pair(x,y)); St.erase(id); /// check other stable box for(int i=⑴;i<=1;i++) // dx { for(int j=⑴;j<=1;j+=2) // dy { int nx=x+i,ny=y+j; pII tp = make_pair(nx,ny); if(Pt.count(tp)==1) { int ID=mPI[tp]; checkround(ID); } } } } int main() { //freopen("in.txt","r",stdin); //freopen("out.txt","w",stdout); scanf("%d",&n); for(int i=0;i<n;i++) { int x,y; scanf("%d%d",&x,&y); box[i]=(BOX){x,y,i}; mPI[make_pair(x,y)]=i; Pt.insert(make_pair(x,y)); } /// check stable disassemble box int mxid=0,miid=0; for(int i=0;i<n;i++) { if(isST(i)) { St.insert(i); mxid=max(mxid,i); miid=min(miid,i); } } vector<int> vi; for(int loop=0;loop<n;loop++) { if(loop%2==0) //find max { vi.push_back(mxid); Remove(mxid); } else // find min { vi.push_back(miid); Remove(miid); } if(loop==n⑴) continue; miid=*St.begin(); mxid=*(--St.end()); } LL ans=0,base=1; for(int sz=vi.size(),i=sz⑴;i>=0;i--) { ans=(ans+base*vi[i]%mod)%mod; base=(base*n)%mod; } cout<<ans%mod<<endl; return 0; }




生活不易,碼農辛苦
如果您覺得本網站對您的學習有所幫助,可以手機掃描二維碼進行捐贈
程序員人生
------分隔線----------------------------
分享到:
------分隔線----------------------------
關閉
程序員人生
主站蜘蛛池模板: 极品丝袜高跟91极品系列 | 亚洲精品高清在线 | 欧美精品一区二区三区视频 | 亚洲精品久久久成人 | 99视频精品免视3 | 99精品一区二区三区 | 性激烈的欧美三级视频中文字幕 | 一区二区视频在线观看免费的 | 欧美成人精品福利网站 | 中文字幕123 | 午夜dj在线观看免费高清在线 | 噜噜噜噜噜在线观看视频 | 国产精品国产国产aⅴ | 久久久国产一区二区三区 | 久久午夜羞羞影院免费观看 | 日本a∨在线播放高清 | 欧美黑人性生活 | 2019国内精品久久久久久 | 国产人成午夜免费看 | 黄大片日本一级在线a | yellow中文字幕视频在线 | 久久不卡免费视频 | 麻豆亚洲精品一区二区 | 伊人青青操 | 欧美国产日韩1区俺去了 | 国产第一区二区三区在线观看 | jizz日本免费| 亚洲欧美日韩综合在线 | 欧美日韩第一页 | 亚洲综合精品成人 | xxxxxx日本处大片免费看 | 亚洲美女福利 | 亚洲视频一区 | 久久久国产高清 | 麻豆高清视频在线观看 | 免费一区二区三区四区五区 | 国产精品99一区二区三区 | yellow中文字幕官网是什么 | 国产成人一区 | 一区二区三区 日韩 | 黄色毛片免费网站 |