11459 - Snakes and Ladders

All about problems in Volume 114. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

apurba
New poster
Posts: 42
Joined: Sun Oct 07, 2007 10:29 pm

Re: 11459 - Snakes and Ladders

Post by apurba » Wed May 27, 2009 5:56 pm

Anyone please give some special I/O............
getting wa and wa.....

Code: Select all

keep dreaming...

lucastan
New poster
Posts: 10
Joined: Sat Jul 02, 2011 6:46 am

Re: 11459 - Snakes and Ladders

Post by lucastan » Mon Aug 01, 2011 3:03 am

the biggest trick is that the input is formatted nicely for you already ...

Be very careful of the meaning of mouth/tail of snake.

The input is specified as X, Y where X is bottom of ladder or mouth of snake (Entrance)
Y is top of ladder or tail of snake (Exit)

Also terminate ASAP when a player reaches 100

lukai
New poster
Posts: 25
Joined: Wed Dec 05, 2012 8:11 pm

11459 - Snakes and Ladders

Post by lukai » Sun Apr 28, 2013 2:21 am

This is so frustrating , I didn't understand what is the problem , why I am getting WA .
Anybody plz help me out . give me some critical I/O

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;
}

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 11459 - Snakes and Ladders

Post by brianfry713 » Fri May 17, 2013 2:08 am

Input:

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
AC output:

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.
Check input and AC output for thousands of problems on uDebug!

lukai
New poster
Posts: 25
Joined: Wed Dec 05, 2012 8:11 pm

Re: 11459 - Snakes and Ladders

Post by lukai » Sat May 18, 2013 10:13 am

AC

User avatar
uDebug
A great helper
Posts: 475
Joined: Tue Jul 24, 2012 4:23 pm

Re: 11459 - Snakes and Ladders

Post by uDebug » Sat Mar 01, 2014 3:31 pm

brianfry713,

Thanks so much for these great test cases.

Also, anyone else looking for test cases, please be sure to consider checking out the other thread on this problem here

http://online-judge.uva.es/board/viewto ... ilit=11459

There's a great test case by jurajz that you might (absolutely) want to look into, also.
Check input and AC output for over 7,500 problems on uDebug!

Find us on Facebook. Follow us on Twitter.

User avatar
uDebug
A great helper
Posts: 475
Joined: Tue Jul 24, 2012 4:23 pm

Re: 11459 - Snakes and Ladders

Post by uDebug » Sat Mar 01, 2014 3:35 pm

jurajz,

Thanks for this great test case.

Also, anyone looking for test cases on this problem, please be sure to consider checking out the other thread on this problem here

http://online-judge.uva.es/board/viewto ... 51#p368251

brianfry713's shared some excellent test cases there.
Check input and AC output for over 7,500 problems on uDebug!

Find us on Facebook. Follow us on Twitter.

axelblaze
New poster
Posts: 34
Joined: Mon Jun 23, 2014 7:45 pm

Re: 11459 - Snakes and Ladders

Post by axelblaze » Fri Aug 08, 2014 2:58 pm

do I need to terminate as soon any player reaches 100..?

lbv
Experienced poster
Posts: 128
Joined: Tue Nov 29, 2011 8:40 am

Re: 11459 - Snakes and Ladders

Post by lbv » Fri Aug 08, 2014 9:20 pm

axelblaze wrote:do I need to terminate as soon any player reaches 100..?
From the problem statement: A player wins when his or her token reached the square numbered 100. At that point, the game ends.

Shahidul.CSE
Experienced poster
Posts: 148
Joined: Sun Jul 13, 2014 4:32 am
Location: Rangpur, Bangladesh

Re: 11459 - Snakes and Ladders

Post by Shahidul.CSE » Thu Aug 21, 2014 7:48 pm

Code: Select all

Removed after AC
Last edited by Shahidul.CSE on Thu Sep 04, 2014 5:47 pm, edited 2 times in total.
Md. Shahidul Islam
Dept. of CSE at Begum Rokeya University, Rangpur, Bangladesh
UVa id: http://uhunt.felix-halim.net/id/438420
My facebook account,
Email me: shahidul.cse.brur@gmail.com

Shahidul.CSE
Experienced poster
Posts: 148
Joined: Sun Jul 13, 2014 4:32 am
Location: Rangpur, Bangladesh

Re: 11459 - Snakes and Ladders

Post by Shahidul.CSE » Thu Aug 21, 2014 7:54 pm

Code: Select all

Code removed !
Last edited by Shahidul.CSE on Thu Sep 04, 2014 5:44 pm, edited 1 time in total.
Md. Shahidul Islam
Dept. of CSE at Begum Rokeya University, Rangpur, Bangladesh
UVa id: http://uhunt.felix-halim.net/id/438420
My facebook account,
Email me: shahidul.cse.brur@gmail.com

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 11459 - Snakes and Ladders

Post by brianfry713 » Thu Sep 04, 2014 1:34 am

Input:

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
AC output:

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.
Check input and AC output for thousands of problems on uDebug!

Shahidul.CSE
Experienced poster
Posts: 148
Joined: Sun Jul 13, 2014 4:32 am
Location: Rangpur, Bangladesh

Re: 11459 - Snakes and Ladders

Post by Shahidul.CSE » Thu Sep 04, 2014 5:49 pm

Thanks brianfry713, got accepted !! :D :D
Md. Shahidul Islam
Dept. of CSE at Begum Rokeya University, Rangpur, Bangladesh
UVa id: http://uhunt.felix-halim.net/id/438420
My facebook account,
Email me: shahidul.cse.brur@gmail.com

naheed
New poster
Posts: 8
Joined: Sun Oct 25, 2009 7:20 pm

Re: 11459 - Snakes and Ladders

Post by naheed » Fri Nov 14, 2014 5:55 pm

Tried all the test cases available here. Still WA (6 times :( ).

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();
    }
}

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 11459 - Snakes and Ladders

Post by brianfry713 » Tue Nov 18, 2014 3:33 am

That is AC code.
Check input and AC output for thousands of problems on uDebug!

Post Reply

Return to “Volume 114 (11400-11499)”