记录编号 101130 评测结果 AA
题目名称 [UVa 101] 木块问题 最终得分 100
用户昵称 Gravatarwolf 是否通过 通过
代码语言 C++ 运行时间 0.000 s
提交时间 2014-05-09 21:57:37 内存使用 0.32 MiB
显示代码纯文本
  1. #include<iostream>
  2. #include<cstdio>
  3. #include<vector>
  4. #include<vector>
  5. using namespace std;
  6. FILE *open;
  7. FILE *out;
  8. int n;
  9. vector<vector<int> > AA;
  10. vector<int>::iterator y;
  11. vector<int>::iterator a1;
  12. vector<int>::iterator a2;
  13. vector<int>::iterator b1;
  14. vector<int>::iterator b2;
  15. int seek(int number){
  16. for(int i=0;i!=AA.size();++i){
  17. y=AA[i].begin();
  18. for(int q=0;q!=AA[i].size();++q){
  19. if(number==AA[i][q]){
  20. y=y+q;
  21. return i;
  22. }
  23. }
  24. }
  25. return n+1;
  26. }
  27. int move_onto(int a,int b){
  28. int A,B;
  29. A=seek(a);
  30. a1=y;
  31. B=seek(b);
  32. b1=y;
  33. if(A==B||*a1==*b1){
  34. return 0;
  35. }
  36. ++b1;
  37. AA[B].insert(b1,*a1);
  38. AA[A].erase(a1);
  39. return 1;
  40. }
  41. int move_over(int a,int b){
  42. int A,B;
  43. A=seek(a);
  44. a1=y;
  45. B=seek(b);
  46. b1=y;
  47. if(A==B||*a1==*b1){
  48. return 0;
  49. }
  50. AA[B].push_back(*a1);
  51. AA[A].erase(a1);
  52. return 1;
  53. }
  54. int pile_onto(int a,int b){
  55. int A,B;
  56. A=seek(a);
  57. a1=y;
  58. B=seek(b);
  59. b1=y;
  60. if(A==B||*a1==*b1){
  61. return 0;
  62. }
  63. a2=AA[A].end();
  64. ++b1;
  65. AA[B].insert(b1,a1,a2);
  66. AA[A].erase(a1,a2);
  67. return 1;
  68. }
  69. int pile_over(int a,int b){
  70. int A,B;
  71. A=seek(a);
  72. a1=y;
  73. B=seek(b);
  74. b1=y;
  75. //cout<<"a1 "<<*a1;
  76. if(A==B||*a1==*b1){
  77. return 0;
  78. }
  79. a2=AA[A].end();
  80. b2=AA[B].end();
  81. AA[B].insert(b2,a1,a2);
  82. AA[A].erase(a1,a2);
  83. return 1;
  84. }
  85. int main(){
  86. open=fopen("uvablock.in","r");
  87. out=fopen("uvablock.out","w");
  88. fscanf(open,"%d",&n);
  89. AA.resize(n);
  90. for(int i=0;i!=n;++i){
  91. AA[i].push_back(i);
  92. }
  93. bool end=1;
  94. while(end){
  95. char e[4];
  96. char r[4];
  97. int a,b;
  98. fscanf(open," %s %d %s %d",&e,&a,&r,&b);
  99. //cout<<a<<" "<<b<<endl;
  100. if(e[0]=='q')
  101. break;
  102. if(e[0]=='m'){
  103. if(r[1]=='n'){
  104. move_onto(a,b);
  105. }else{
  106. move_over(a,b);
  107. }
  108. }else{
  109. if(r[1]=='n'){
  110. pile_onto(a,b);
  111. }else{
  112. pile_over(a,b);
  113. }
  114. }
  115. }
  116. //cout<<endl;
  117. for(int i=0;i!=AA.size();++i){
  118. fprintf(out,"%d:",i);
  119. //cout<<i<<":";
  120. for(int q=0;q!=AA[i].size();++q){
  121. fprintf(out,"%d ",AA[i][q]);
  122. //cout<<AA[i][q]<<" ";
  123. }
  124. fprintf(out,"\n");
  125. //cout<<endl;
  126. }
  127. return 0;
  128. }
  129. //desugned by wolf