Re: 11459 - Snakes and Ladders
Posted: Wed May 27, 2009 5:56 pm
Anyone please give some special I/O............
getting wa and wa.....
Anyone please give some special I/O............
getting wa and wa.....
Code: Select all
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <cstdio>
using namespace std;
int main()
{
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
vector<int>snake_mouth,snake_tail,ladd_start,ladd_end;
vector<int>token_position;
long long int number_of_player,number_of_snakes,number_die_rolls;
long long int cases,start,end,temp,die_roll,mod,flag,vut,j;
while(cin>>cases){
while(cases--)
{
cin>>number_of_player>>number_of_snakes>>number_die_rolls;
while(number_of_snakes--)
{
cin>>start>>end;
if(start>end)
{
snake_mouth.push_back(start);
snake_tail.push_back(end);
}
else
{
ladd_start.push_back(start);
ladd_end.push_back(end);
}
}
temp=number_die_rolls;
while(number_die_rolls--)
{
token_position.push_back(1);
}
for( j=0;j<token_position.size();j++)
{
flag=0;
cin>>die_roll;
mod=(j+1)%number_of_player;
if(mod==0)
{
token_position[number_of_player-1]=token_position[number_of_player-1]+die_roll;
for(int i=0;i<snake_mouth.size();i++)
{
if((token_position[number_of_player-1])==snake_mouth[i])
{
token_position[number_of_player-1]=snake_tail[i];
flag=1;
break;
}
}
for(int i=0;i<ladd_start.size();i++)
{
if(flag==1)
{
break;
}
if((token_position[number_of_player-1])==ladd_start[i])
{
token_position[temp-1]=ladd_end[i];
break;
}
}
if(token_position[number_of_player-1]>=100)
{
token_position[number_of_player-1]=100;
vut=temp-(j+1);
while(vut--)
{
cin>>die_roll;
}
break;
}
}
else
{
token_position[mod-1]=token_position[mod-1]+die_roll;
for(int i=0;i<snake_mouth.size();i++)
{
if((token_position[mod-1])==snake_mouth[i])
{
token_position[mod-1]=snake_tail[i];
flag=1;
break;
}
}
for(int i=0;i<ladd_start.size();i++)
{
if(flag==1)
{
break;
}
if((token_position[mod-1])==ladd_start[i])
{
token_position[mod-1]=ladd_end[i];
break;
}
}
if(token_position[mod-1]>=100)
{
token_position[mod-1]=100;
vut=temp-(j+1);
while(vut--)
{
cin>>die_roll;
}
break;
}
}
}
for(int i=1;i<=number_of_player;i++)
{
cout<<"Position of player "<<i<<" is "<<token_position[i-1]<<"."<<endl;
}
snake_mouth.clear();
snake_tail.clear();
ladd_start.clear();
ladd_end.clear();
token_position.clear();
}
}
return 0;
}
Code: Select all
10
17 5 12
83 87
81 40
59 96
3 24
9 80
4
1
4
2
3
4
6
3
5
4
1
3
16 6 10
89 30
21 81
15 41
20 56
22 58
69 72
2
4
4
3
1
2
6
3
4
3
7 1 3
80 42
4
1
3
21 0 14
1
2
4
2
6
2
4
1
2
3
2
3
4
4
3 9 0
65 22
25 64
6 36
45 46
17 53
26 69
7 34
41 40
92 42
2 0 19
3
2
1
1
4
2
4
4
5
2
1
1
6
1
6
6
5
6
2
11 4 1
76 87
22 83
79 19
78 91
1
12 6 14
98 47
23 29
31 39
79 91
74 88
50 77
6
4
2
2
3
6
2
4
1
6
5
2
6
3
21 2 0
55 51
67 48
2 2 6
29 46
84 27
5
5
1
4
6
6
Code: Select all
Position of player 1 is 5.
Position of player 2 is 2.
Position of player 3 is 5.
Position of player 4 is 24.
Position of player 5 is 4.
Position of player 6 is 5.
Position of player 7 is 7.
Position of player 8 is 4.
Position of player 9 is 6.
Position of player 10 is 5.
Position of player 11 is 2.
Position of player 12 is 4.
Position of player 13 is 1.
Position of player 14 is 1.
Position of player 15 is 1.
Position of player 16 is 1.
Position of player 17 is 1.
Position of player 1 is 3.
Position of player 2 is 5.
Position of player 3 is 5.
Position of player 4 is 4.
Position of player 5 is 2.
Position of player 6 is 3.
Position of player 7 is 7.
Position of player 8 is 4.
Position of player 9 is 5.
Position of player 10 is 4.
Position of player 11 is 1.
Position of player 12 is 1.
Position of player 13 is 1.
Position of player 14 is 1.
Position of player 15 is 1.
Position of player 16 is 1.
Position of player 1 is 5.
Position of player 2 is 2.
Position of player 3 is 4.
Position of player 4 is 1.
Position of player 5 is 1.
Position of player 6 is 1.
Position of player 7 is 1.
Position of player 1 is 2.
Position of player 2 is 3.
Position of player 3 is 5.
Position of player 4 is 3.
Position of player 5 is 7.
Position of player 6 is 3.
Position of player 7 is 5.
Position of player 8 is 2.
Position of player 9 is 3.
Position of player 10 is 4.
Position of player 11 is 3.
Position of player 12 is 4.
Position of player 13 is 5.
Position of player 14 is 5.
Position of player 15 is 1.
Position of player 16 is 1.
Position of player 17 is 1.
Position of player 18 is 1.
Position of player 19 is 1.
Position of player 20 is 1.
Position of player 21 is 1.
Position of player 1 is 1.
Position of player 2 is 1.
Position of player 3 is 1.
Position of player 1 is 38.
Position of player 2 is 26.
Position of player 1 is 2.
Position of player 2 is 1.
Position of player 3 is 1.
Position of player 4 is 1.
Position of player 5 is 1.
Position of player 6 is 1.
Position of player 7 is 1.
Position of player 8 is 1.
Position of player 9 is 1.
Position of player 10 is 1.
Position of player 11 is 1.
Position of player 1 is 13.
Position of player 2 is 8.
Position of player 3 is 3.
Position of player 4 is 3.
Position of player 5 is 4.
Position of player 6 is 7.
Position of player 7 is 3.
Position of player 8 is 5.
Position of player 9 is 2.
Position of player 10 is 7.
Position of player 11 is 6.
Position of player 12 is 3.
Position of player 1 is 1.
Position of player 2 is 1.
Position of player 3 is 1.
Position of player 4 is 1.
Position of player 5 is 1.
Position of player 6 is 1.
Position of player 7 is 1.
Position of player 8 is 1.
Position of player 9 is 1.
Position of player 10 is 1.
Position of player 11 is 1.
Position of player 12 is 1.
Position of player 13 is 1.
Position of player 14 is 1.
Position of player 15 is 1.
Position of player 16 is 1.
Position of player 17 is 1.
Position of player 18 is 1.
Position of player 19 is 1.
Position of player 20 is 1.
Position of player 21 is 1.
Position of player 1 is 13.
Position of player 2 is 16.
From the problem statement: A player wins when his or her token reached the square numbered 100. At that point, the game ends.axelblaze wrote:do I need to terminate as soon any player reaches 100..?
Code: Select all
10
5 0 3
1
3
3
11 8 19
45 4
27 33
7 22
67 50
68 86
54 63
85 35
51 69
5
6
2
5
1
6
3
5
6
5
5
5
1
4
3
4
3
6
3
11 8 3
23 14
84 75
32 25
64 37
93 34
94 60
51 58
8 79
2
6
6
15 9 17
14 37
13 24
20 97
41 64
94 18
33 34
91 63
58 12
98 7
1
5
6
6
5
4
3
4
2
1
1
3
2
3
3
3
5
8 7 19
97 16
69 30
48 17
47 6
27 99
19 7
31 75
4
4
3
6
5
5
2
3
1
4
3
6
4
6
2
4
1
5
1
15 1 7
77 82
5
1
5
4
4
2
5
5 0 0
2 0 8
2
2
4
3
2
1
4
5
16 5 5
68 19
14 6
58 89
42 83
93 84
5
6
2
3
1
10 7 10
16 89
29 73
32 86
84 27
57 9
14 79
17 26
2
5
5
5
6
6
3
4
3
3
Code: Select all
Position of player 1 is 2.
Position of player 2 is 4.
Position of player 3 is 4.
Position of player 4 is 1.
Position of player 5 is 1.
Position of player 1 is 11.
Position of player 2 is 23.
Position of player 3 is 22.
Position of player 4 is 9.
Position of player 5 is 6.
Position of player 6 is 25.
Position of player 7 is 10.
Position of player 8 is 9.
Position of player 9 is 22.
Position of player 10 is 6.
Position of player 11 is 6.
Position of player 1 is 3.
Position of player 2 is 7.
Position of player 3 is 7.
Position of player 4 is 1.
Position of player 5 is 1.
Position of player 6 is 1.
Position of player 7 is 1.
Position of player 8 is 1.
Position of player 9 is 1.
Position of player 10 is 1.
Position of player 11 is 1.
Position of player 1 is 5.
Position of player 2 is 11.
Position of player 3 is 7.
Position of player 4 is 7.
Position of player 5 is 6.
Position of player 6 is 5.
Position of player 7 is 4.
Position of player 8 is 5.
Position of player 9 is 3.
Position of player 10 is 2.
Position of player 11 is 2.
Position of player 12 is 4.
Position of player 13 is 3.
Position of player 14 is 4.
Position of player 15 is 4.
Position of player 1 is 7.
Position of player 2 is 14.
Position of player 3 is 8.
Position of player 4 is 13.
Position of player 5 is 10.
Position of player 6 is 12.
Position of player 7 is 5.
Position of player 8 is 8.
Position of player 1 is 6.
Position of player 2 is 2.
Position of player 3 is 6.
Position of player 4 is 5.
Position of player 5 is 5.
Position of player 6 is 3.
Position of player 7 is 6.
Position of player 8 is 1.
Position of player 9 is 1.
Position of player 10 is 1.
Position of player 11 is 1.
Position of player 12 is 1.
Position of player 13 is 1.
Position of player 14 is 1.
Position of player 15 is 1.
Position of player 1 is 1.
Position of player 2 is 1.
Position of player 3 is 1.
Position of player 4 is 1.
Position of player 5 is 1.
Position of player 1 is 13.
Position of player 2 is 12.
Position of player 1 is 6.
Position of player 2 is 7.
Position of player 3 is 3.
Position of player 4 is 4.
Position of player 5 is 2.
Position of player 6 is 1.
Position of player 7 is 1.
Position of player 8 is 1.
Position of player 9 is 1.
Position of player 10 is 1.
Position of player 11 is 1.
Position of player 12 is 1.
Position of player 13 is 1.
Position of player 14 is 1.
Position of player 15 is 1.
Position of player 16 is 1.
Position of player 1 is 3.
Position of player 2 is 6.
Position of player 3 is 6.
Position of player 4 is 6.
Position of player 5 is 7.
Position of player 6 is 7.
Position of player 7 is 4.
Position of player 8 is 5.
Position of player 9 is 4.
Position of player 10 is 4.
Code: Select all
#include <cstdio>
#include <iostream>
#include <map>
#define MAX 1000000
using namespace std;
int main(){
char player[MAX+2];
int die;
int testcase;
int numplayers,numsnld,numdierol;
map <int,int> cellmp;
cin>>testcase;
//freopen("a.out","w",stdout);
while(testcase--){
scanf("%d %d %d",&numplayers,&numsnld,&numdierol);
bool end = false;
while(numsnld--){
int from,to;
scanf("%d %d",&from,&to);
cellmp[from] = to;
}
for(int i=1;i<=numplayers;i++)
player[i] = 1;
//cout<<"numplayers: "<<numplayers<<endl;
for(int i=0;i<numdierol;i++){
int playernum = i%(numplayers)+1;
int face;
scanf("%d",&face);
int next = player[playernum]+face;
if(!end){
// cout<<"next: "<<next<<endl;
int v = cellmp[next];
if(v){
//cout<<playernum<<"was at "<<(int)player[playernum]<<" now at: "<<v<<endl;
player[playernum] = v>100?100:v;
}
else{
//cout<<playernum<<"was at "<<(int)player[playernum]<<" now at: "<<next<<endl;
player[playernum] = next>100?100:next;
}
if(player[playernum]==100)
end = true;
}
}
for(int i=1;i<=numplayers;i++){
printf("Position of player %d is %d.\n",i,player[i]);
player[i] = 1;
}
cellmp.clear();
}
}