2014
03-06

# Snakes and Ladders

Snakes and Ladders is a board game played on a 10 by 10 grid. The squares of the grid are numbered 1 to 100. Each player has a token which is placed on the square numbered 1 at the beginning of the game. Players take turns rolling a die which provides a random number between 1 and 6. After rolling, the player advances his or her token the number of squares shown on the die. If this would put the token past the square numbered 100, the token is advanced to 100. After advancing, if the token is on a square containing the bottom of a ladder, the token must be moved to the square containing the top of the ladder. Similarly, if the token is on a square containing the mouth of a snake, the token must be moved to the square containing the tail of the snake. No square contains more than one endpoint of any snake or ladder. The token numbered 100 does not contain the mouth of a snake or the bottom of a ladder. A player wins when his or her token reached the square numbered 100. At that point, the game ends.

Given the configuration of the snakes and ladders on a game board and a sequence of die rolls, you are to determine the positions of all the tokens on the game board. The sequence of die rolls need not be complete (i.e. it need not lead to any player winning). The sequence of die rolls may also continue after the game is over; in this case, the die rolls after the end of the game should be ignored.

The first line contains three positive integers: the number a of players, the number b of snakes or ladders, and the number c of die rolls. There will be no more than 1000000 players and no more than 1000000 die rolls. Each of the next b lines contains two integers specifying a snake or ladder. The first integer indicates the square containing the mouth of the snake or the bottom of the ladder. The second integer indicates the square containing the tail of the snake or the top of the ladder. The following c lines each contain one integer giving number rolled on the die.

The first line contains three positive integers: the number a of players, the number b of snakes or ladders, and the number c of die rolls. There will be no more than 1000000 players and no more than 1000000 die rolls. Each of the next b lines contains two integers specifying a snake or ladder. The first integer indicates the square containing the mouth of the snake or the bottom of the ladder. The second integer indicates the square containing the tail of the snake or the top of the ladder. The following c lines each contain one integer giving number rolled on the die.

3 1 3
4 20
3
4
5

Position of player 1 is 20.
Position of player 2 is 5.
Position of player 3 is 6.

/*
ID:1192432
PROG: castle
LANG: C++
*/
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <map>
#include <vector>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
const int MAX=1000005,MAXN=105,INF=1<<30;
int n,b,c;
int hash[MAXN],
pos[MAX];

//inline
//void end(const int &b){
// int t;
// for(int i=b+1;i<c;i++){
// scanf("%d",&t);
// cout<<"TT: "<<t<<endl;
// }
// return ;
//}

int main()
{
#ifndef ONLINE_JUDGE
freopen("i.txt", "r", stdin);
#endif
bool endFlag;
//while(cin>>n>>b>>c){
while(scanf("%d %d %d",&n,&b,&c)==3){
memset(hash,0,sizeof(hash));
for(int i=0;i<n;i++) pos[i]=1;
for(int i=0;i<b;i++){
scanf("%d %d",&u,&v);
hash[u]=v;
}
endFlag=0;
for(int i=0;i<c;i++){
scanf("%d",&ft);
if(endFlag){
continue;
}
p=i%n;
else
pos[p]=100;
if(pos[p]==100){
endFlag=1;
}
}
for(int i=0;i<n;i++)
printf("Position of player %d is %d.\n",i+1,pos[i]);
//cout<<endl;
}
return 0;
}

1. 第一句可以忽略不计了吧。从第二句开始分析，说明这个花色下的所有牌都会在其它里面出现，那么还剩下♠️和♦️。第三句，可以排除2和7，因为在两种花色里有。现在是第四句，因为♠️还剩下多个，只有是♦️B才能知道答案。

2. 有两个重复的话结果是正确的，但解法不够严谨，后面重复的覆盖掉前面的，由于题目数据限制也比较严，所以能提交通过。已更新算法

3. 网站做得很好看，内容也多，全。前段时间在博客园里看到有人说：网页的好坏看字体。觉得微软雅黑的字体很好看，然后现在这个网站也用的这个字体！nice!