记录编号 |
101130 |
评测结果 |
AA |
题目名称 |
[UVa 101] 木块问题 |
最终得分 |
100 |
用户昵称 |
wolf |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
0.000 s |
提交时间 |
2014-05-09 21:57:37 |
内存使用 |
0.32 MiB |
显示代码纯文本
#include<iostream>
#include<cstdio>
#include<vector>
#include<vector>
using namespace std;
FILE *open;
FILE *out;
int n;
vector<vector<int> > AA;
vector<int>::iterator y;
vector<int>::iterator a1;
vector<int>::iterator a2;
vector<int>::iterator b1;
vector<int>::iterator b2;
int seek(int number){
for(int i=0;i!=AA.size();++i){
y=AA[i].begin();
for(int q=0;q!=AA[i].size();++q){
if(number==AA[i][q]){
y=y+q;
return i;
}
}
}
return n+1;
}
int move_onto(int a,int b){
int A,B;
A=seek(a);
a1=y;
B=seek(b);
b1=y;
if(A==B||*a1==*b1){
return 0;
}
++b1;
AA[B].insert(b1,*a1);
AA[A].erase(a1);
return 1;
}
int move_over(int a,int b){
int A,B;
A=seek(a);
a1=y;
B=seek(b);
b1=y;
if(A==B||*a1==*b1){
return 0;
}
AA[B].push_back(*a1);
AA[A].erase(a1);
return 1;
}
int pile_onto(int a,int b){
int A,B;
A=seek(a);
a1=y;
B=seek(b);
b1=y;
if(A==B||*a1==*b1){
return 0;
}
a2=AA[A].end();
++b1;
AA[B].insert(b1,a1,a2);
AA[A].erase(a1,a2);
return 1;
}
int pile_over(int a,int b){
int A,B;
A=seek(a);
a1=y;
B=seek(b);
b1=y;
//cout<<"a1 "<<*a1;
if(A==B||*a1==*b1){
return 0;
}
a2=AA[A].end();
b2=AA[B].end();
AA[B].insert(b2,a1,a2);
AA[A].erase(a1,a2);
return 1;
}
int main(){
open=fopen("uvablock.in","r");
out=fopen("uvablock.out","w");
fscanf(open,"%d",&n);
AA.resize(n);
for(int i=0;i!=n;++i){
AA[i].push_back(i);
}
bool end=1;
while(end){
char e[4];
char r[4];
int a,b;
fscanf(open," %s %d %s %d",&e,&a,&r,&b);
//cout<<a<<" "<<b<<endl;
if(e[0]=='q')
break;
if(e[0]=='m'){
if(r[1]=='n'){
move_onto(a,b);
}else{
move_over(a,b);
}
}else{
if(r[1]=='n'){
pile_onto(a,b);
}else{
pile_over(a,b);
}
}
}
//cout<<endl;
for(int i=0;i!=AA.size();++i){
fprintf(out,"%d:",i);
//cout<<i<<":";
for(int q=0;q!=AA[i].size();++q){
fprintf(out,"%d ",AA[i][q]);
//cout<<AA[i][q]<<" ";
}
fprintf(out,"\n");
//cout<<endl;
}
return 0;
}
//desugned by wolf