您的位置:首页 > 运维架构 > Shell

Shell Game (类似找骰子游戏)

2014-03-24 12:05 776 查看
F- Shell Game p
Time Limit: 2000MSMemory Limit: 65536K64bit IO Format: %I64d& %I64u
[Submit] [GoBack]
[Status]DescriptionToday the «Z» city residents enjoy a shell game competition. Theresidents are gathered on the main square to watch thebreath-taking performance. The performer puts 3 non-transparentcups upside down in a row. Then he openly puts a small ball underone of the
cups and starts to shuffle the cups around very quicklyso that on the whole he makes exactly 3 shuffles. After that thespectators have exactly one attempt to guess in which cup theythink the ball is and if the answer is correct they get a prize.Maybe you can
try to find the ball too?InputThe first input line contains an integer from 1 to 3 — index ofthe cup which covers the ball before the shuffles. The followingthree lines describe the shuffles. Each description of a shufflecontains two distinct integers from 1 to 3 — indexes of the cupswhich
the performer shuffled this time. The cups are numbered fromleft to right and are renumbered after each shuffle from left toright again. In other words, the cup on the left always has index1, the one in the middle — index 2 and the one on the right — index3.OutputIn the first line output an integer from 1 to 3 — index of thecup which will have the ball after all the shuffles.Sample InputInput
1

1 2

2 1

2 1
Output
2
Input
1

2 1

3 1

1 3
Output
2


#include<iostream>
using namespace std;
int main()
{
int n,a1,b1,a2,b2,a3,b3;
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);while(cin>>n)
{cin>>a1>>b1;
cin>>a2>>b2;
cin>>a3>>b3;
if(a1==n||b1==n)
{
if(a1==n) n=b1;
else n=a1;
}
if(a2==n||b2==n)
{
if(a2==n) n=b2;
else n=a2;
}if(a3==n||b3==n)
{
if(a3==n) n=b3;
else n=a3;
}
cout<<n<<endl;
}
return 0;}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: