1779. The Great Team
Time limit: 0.5 second
Memory limit: 64 MB
When a few students of the Ural State University finished their sport career, the university encountered a lot of problems in team composition. Veterans of sports programming decided to play their role and create the most successful team in the history of the Ural SU.
Veterans assumed that success of a team strongly depends on the number of friends in the ACM community the members of this team have. After more discussions they developed the
criterion of success: all three members of the team should have the same number of friends.
Unfortunately, the veterans failed to compose a team, as it turned out that there were no three programmers in the Ural SU that together satisfied this criterion.
You should use this information to determine which students are friends of each other.
Input
The first line contains a single integer
n
(3 ≤
n ≤ 200)
, which is the number of students in the Ural SU participating in programming contests.
Output
If the veterans' calculations are correct, the first line should contain an integer
k, which is the number of pairs of students that are friends of each other. The following
k lines should contain these pairs. Students should be numbered 1 through
n. If a problem has multiple correct answers, output any of them.
If the veterans are wrong and the problem has no solution, output a single line containing a number −1.
|
#include<iostream>
#include<stdio.h>
using namespace std;
int main ()
{
int i,temp,n,flag,j,k;
while(scanf("%d",&n)!=EOF)
{
temp=n;
if(temp%2)
{
printf("%d\n",(temp-1)*(temp-1)/4);
k=n;
for(i=temp-2,j=k;i>0;i=i-2)
{
flag=i;
while(flag--)
{
j--;
printf("%d %d\n",j,k);
}
k--;
j=k;
}
}
else
{
printf("%d\n",temp*(temp-2)/4);
k=n;
for(i=temp-2,j=k;i>0;i=i-2)
{
flag=i;
while(flag--)
{
j--;
printf("%d %d\n",j,k);
}
k--;
j=k;
}
}
}
return 0;
}
1779. The Great Team
Time limit: 0.5 second
Memory limit: 64 MB
When a few students of the Ural State University finished their sport career, the university encountered a lot of problems in team composition. Veterans of sports programming decided to play their role and create the most successful team in the history of the Ural SU.
Veterans assumed that success of a team strongly depends on the number of friends in the ACM community the members of this team have. After more discussions they developed the
criterion of success: all three members of the team should have the same number of friends.
Unfortunately, the veterans failed to compose a team, as it turned out that there were no three programmers in the Ural SU that together satisfied this criterion.
You should use this information to determine which students are friends of each other.
Input
The first line contains a single integer
n
(3 ≤
n ≤ 200)
, which is the number of students in the Ural SU participating in programming contests.
Output
If the veterans' calculations are correct, the first line should contain an integer
k, which is the number of pairs of students that are friends of each other. The following
k lines should contain these pairs. Students should be numbered 1 through
n. If a problem has multiple correct answers, output any of them.
If the veterans are wrong and the problem has no solution, output a single line containing a number −1.
|
#include<iostream>
#include<stdio.h>
using namespace std;
int main ()
{
int i,temp,n,flag,j,k;
while(scanf("%d",&n)!=EOF)
{
temp=n;
if(temp%2)
{
printf("%d\n",(temp-1)*(temp-1)/4);
k=n;
for(i=temp-2,j=k;i>0;i=i-2)
{
flag=i;
while(flag--)
{
j--;
printf("%d %d\n",j,k);
}
k--;
j=k;
}
}
else
{
printf("%d\n",temp*(temp-2)/4);
k=n;
for(i=temp-2,j=k;i>0;i=i-2)
{
flag=i;
while(flag--)
{
j--;
printf("%d %d\n",j,k);
}
k--;
j=k;
}
}
}
return 0;
}