杭电oj
When the old year is leaving and the New Year is coming, people are always looking back over the past while looking forward to the future. "What do you think is the most important events in the past year 2006?", a friend asked me. "Well, maybe the World Cup.", I replied. "Yeah, do you know, in a football match, how to arrange a proper match table for a group?" "That's easy. In the World Cup, there are only 4 teams in a group. Everyone knows how to do it." "Yes, it's easy for four-team’s arrangement. But if there are six teams or more games, can you arrange that?" "OK, let me have a try". I answered. In fact, I tried many times to solve the problem, but got failure in the end. Can you help me? Input The input contains data for several test cases. Each case contains a single even integer, which is less than 2007, indicate the number of teams in a group. and n-1 lines followed, indicate the match table.each line indicate one round in the contest.For example, 4 1-2 3-4 // the first round 1-3 2-4 // the second round 1-4 2-3 // the third round Output For each test case output "Yes" means the match table is correct, or "No" otherwise. Sample Input 2 1-2 4 1-2 3-4 1-3 2-4 1-4 2-3 4 1-3 2-4 1-2 3-4 1-4 2-3 4 1-2 3-2 1-3 2-4 1-4 2-3 Sample Output Yes Yes Yes No |
#include<iOStream>
#include<cstring>
#include <cstdio>
using namespace std;
bool vis[2020];
int main()
{
//freopen("C:\\Users\\23535\\Desktop\\in.txt","r",stdin); //输入重定向,输入数据将从D盘根目录下的in.txt文件中读取
// freopen("C:\\Users\\23535\\Desktop\\out.txt","w",stdout); //输出重定向,输出数据将保存在D盘根目录下的out.txt文件中
int n;
int a,b;
while(cin>>n)
{
int dui[20020]={0};
int flag=1;
for(int i=1;i<=n-1;i++)
{
for(int j=1;j<=n/2;j++ )
{
scanf("%d-%d",&a,&b);
if(vis[a]||vis[a]){
flag=0;
}
vis[a]=1;
vis[b]=1;
dui[a]++;
dui[b]++;
}
}
if(flag){
for(int i=1;i<=n;i++)
{
if(dui[i]!=n-1)
{
flag=0;
break;
}
}
}
//cout<<flag;
if(flag==1)
cout<<"Yes"<<endl;
else
cout<<"No"<<endl;
/* for(int i=0;i<10;i++)
{
cout<<dui[i];
}
*/
}
//fclose(stdin);//关闭重定向输入
//fclose(stdout);//关闭重定向输出
return 0;
}
相关阅读
Bone Collector Time Limit: 2000/1000 MS (Java/Others)