比赛 20120704 评测结果 AAAAWTTTTT
题目名称 椰子 最终得分 40
用户昵称 ZhouHang 运行时间 0.000 s
代码语言 C++ 内存使用 0.00 MiB
提交时间 2012-07-04 10:51:11
显示代码纯文本
  1. /**
  2. *Prob : coconuts
  3. *Data : 2012-7-4
  4. *Sol : 模拟
  5. */
  6.  
  7. #include <cstdio>
  8. #include <cstring>
  9. #include <algorithm>
  10.  
  11. using namespace std;
  12.  
  13. struct node {
  14. int x,h;
  15. } ans[1010];
  16. int n;
  17. int num[3010][1010];
  18. int h[3010],w[3010];
  19.  
  20. void Find(int k,int x,int we)
  21. {
  22. int nowx = x,nowh = h[x]+1;
  23. while (true) {
  24. if (h[x-1]>=nowh-1&&h[x+1]>=nowh-1) {
  25. num[nowx][nowh] = k;
  26. h[nowx] = nowh;
  27. ans[k].x = nowx; ans[k].h = nowh;
  28. break;
  29. }
  30. //左右都空
  31. if (h[x-1]<nowh-1&&h[x+1]<nowh-1) {
  32. //重
  33. int nw = w[num[nowx][nowh-1]];
  34. if (we > nw) {
  35. Find(num[nowx][nowh-1],nowx+1,nw);
  36. nowh--;
  37. }
  38. if (we < nw) {
  39. nowh--; nowx--;
  40. }
  41. }
  42. //左空
  43. if (h[x-1]<nowh-1&&h[x+1]>=nowh-1) {
  44. int nw = w[num[nowx][nowh-1]];
  45. if (we > nw) {
  46. Find(num[nowx][nowh-1],nowx-1,nw);
  47. num[nowx][--nowh] = k;
  48. ans[k].x = nowx; ans[k].h = nowh;
  49. }
  50. if (we < nw) {
  51. nowh--; nowx--;
  52. }
  53. }
  54. //右空
  55. if (h[x+1]<nowh-1&&h[x-1]>=nowh-1) {
  56. int nw = w[num[nowx][nowh-1]];
  57. if (we > nw) {
  58. Find(num[nowx][nowh-1],nowx+1,nw);
  59. num[nowx][--nowh] = k;
  60. ans[k].x = nowx; ans[k].h = nowh;
  61. }
  62. if (we < nw) {
  63. nowx++; nowh--;
  64. }
  65. }
  66. }
  67. }
  68.  
  69. int main()
  70. {
  71. freopen("coconuts.in","r",stdin);
  72. freopen("coconuts.out","w",stdout);
  73. int T,p;
  74. scanf("%d",&T);
  75. for (;T>0;T--) {
  76. memset(w,0,sizeof(w));
  77. memset(num,0,sizeof(num));
  78. memset(h,0,sizeof(h));
  79. memset(ans,0,sizeof(ans));
  80. scanf("%d",&n);
  81. for (int i=1; i<=n; i++) {
  82. scanf("%d%d",&p,&w[i]);
  83. p +=1000;
  84. Find(i,p,w[i]);
  85. }
  86. for (int i=1; i<=n; i++) {
  87. printf("%d %d\n",ans[i].h,ans[i].x-1000);
  88. }
  89. printf("\n");
  90. }
  91. fclose(stdin); fclose(stdout);
  92. return 0;
  93. }