比赛 |
20120704 |
评测结果 |
AAAAWTTTTT |
题目名称 |
椰子 |
最终得分 |
40 |
用户昵称 |
ZhouHang |
运行时间 |
0.000 s |
代码语言 |
C++ |
内存使用 |
0.00 MiB |
提交时间 |
2012-07-04 10:51:11 |
显示代码纯文本
- /**
- *Prob : coconuts
- *Data : 2012-7-4
- *Sol : 模拟
- */
-
- #include <cstdio>
- #include <cstring>
- #include <algorithm>
-
- using namespace std;
-
- struct node {
- int x,h;
- } ans[1010];
- int n;
- int num[3010][1010];
- int h[3010],w[3010];
-
- void Find(int k,int x,int we)
- {
- int nowx = x,nowh = h[x]+1;
- while (true) {
- if (h[x-1]>=nowh-1&&h[x+1]>=nowh-1) {
- num[nowx][nowh] = k;
- h[nowx] = nowh;
- ans[k].x = nowx; ans[k].h = nowh;
- break;
- }
- //左右都空
- if (h[x-1]<nowh-1&&h[x+1]<nowh-1) {
- //重
- int nw = w[num[nowx][nowh-1]];
- if (we > nw) {
- Find(num[nowx][nowh-1],nowx+1,nw);
- nowh--;
- }
- if (we < nw) {
- nowh--; nowx--;
- }
- }
- //左空
- if (h[x-1]<nowh-1&&h[x+1]>=nowh-1) {
- int nw = w[num[nowx][nowh-1]];
- if (we > nw) {
- Find(num[nowx][nowh-1],nowx-1,nw);
- num[nowx][--nowh] = k;
- ans[k].x = nowx; ans[k].h = nowh;
- }
- if (we < nw) {
- nowh--; nowx--;
- }
- }
- //右空
- if (h[x+1]<nowh-1&&h[x-1]>=nowh-1) {
- int nw = w[num[nowx][nowh-1]];
- if (we > nw) {
- Find(num[nowx][nowh-1],nowx+1,nw);
- num[nowx][--nowh] = k;
- ans[k].x = nowx; ans[k].h = nowh;
- }
- if (we < nw) {
- nowx++; nowh--;
- }
- }
- }
- }
-
- int main()
- {
- freopen("coconuts.in","r",stdin);
- freopen("coconuts.out","w",stdout);
-
- int T,p;
- scanf("%d",&T);
- for (;T>0;T--) {
- memset(w,0,sizeof(w));
- memset(num,0,sizeof(num));
- memset(h,0,sizeof(h));
- memset(ans,0,sizeof(ans));
- scanf("%d",&n);
- for (int i=1; i<=n; i++) {
- scanf("%d%d",&p,&w[i]);
- p +=1000;
- Find(i,p,w[i]);
- }
-
- for (int i=1; i<=n; i++) {
- printf("%d %d\n",ans[i].h,ans[i].x-1000);
- }
- printf("\n");
- }
-
- fclose(stdin); fclose(stdout);
- return 0;
- }