| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
WA了N次,哪位好心人帮小弟看看错在那里,谢谢先!(代码有详细注释)#include<iostream.h>
int main()
{
int n;//date number
int nj[101][103];//room records 其中nj[i][0]为房间i未开的门数,
/////////////nj[i][101]为来房间i上一个房间,nj[i][102]为房间i的recorder值
////////////////////////////其他为与房间i相连的房间的门数
cin >> n;
while(n--){
int i=0;
for(i=0;i<101;i++){
for(int j=0;j<103;j++){
nj[i][j]=0;
if(j>=101)
nj[i][j]=1002;
}
}////////初始化数组
int c;
int now=1,red=0;///now当前房间,red当前房间的recorder值
i=1;
while(1)
{
cin >> c;
if(c==0)break;
if(c>0)////c>0
{
if(i>1){
red=nj[now][102];//
nj[i][101]=now,nj[i][102]=red+1;
nj[i][0]=c-1,nj[now][0]--;//
nj[i][now]+=1,nj[now][i]+=1;
now=i;
i++;
}
else////i==1
{
nj[1][0]=c;
nj[1][101]=0;
nj[1][102]=0;
now=1;
}
}
else
{
int t;
for(t=now-1;t>0;t--)
{
if(c+nj[now][102]==nj[t][102])///找(recorder值)+c=(当前房间recorder值)的房间
{ //从当前房间往下找的第一个(不知是不是错在这里)
if(nj[t][0]==0)continue;//房间未开的门数为0
else break;
}
}
nj[t][0]--,nj[now][0]--;//
nj[now][t]++,nj[t][now]++;
while(nj[now][0]==0){/////当前房间未开门数为0,退回上一个房间
now=nj[now][101];
if(now==0) break;
}
}
}
for(int k=1;k<i;k++){
cout << k ;
for(int j=1;j<i;j++){
if(nj[k][j]!=0){
for(int ii=0;ii<nj[k][j];ii++){
cout <<' '<< j ;
}
}
}
}
}
return 0;
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator