Problem Description
It is well known that small groups are not conducive of the development of a team. Therefore, there shouldn’t be any small groups in a good team.
In a team with n members,if there are three or more members are not friends with each other or there are three or more members who are friends with each other. The team meeting the above conditions can be called a bad team.Otherwise,the team is a good team.
A company is going to make an assessment of each team in this company. We have known the team with n members and all the friend relationship among these n individuals. Please judge whether it is a good team.
In a team with n members,if there are three or more members are not friends with each other or there are three or more members who are friends with each other. The team meeting the above conditions can be called a bad team.Otherwise,the team is a good team.
A company is going to make an assessment of each team in this company. We have known the team with n members and all the friend relationship among these n individuals. Please judge whether it is a good team.
Input
The first line of the input gives the number of test cases T; T test cases follow.(T<=15)
The first line od each case should contain one integers n, representing the number of people of the team.( n≤3000
)
Then there are n-1 rows. The i
th row should contain n-i numbers, in which number
a
ij![]()
represents the relationship between member i and member j+i. 0 means these two individuals are not friends. 1 means these two individuals are friends.
The first line od each case should contain one integers n, representing the number of people of the team.( n≤3000
Then there are n-1 rows. The i
Output
Please output ”Great Team!” if this team is a good team, otherwise please output “Bad Team!”.
Sample Input
1 4 1 1 0 0 0 1
Sample Output
Great Team!
Source
题目思路:
这题可以用两种方法来写,第一种因为实际上是一个完全图,所以根据拉姆齐定理,大于等于6的直接输出no,剩下的暴力找三元环。
第二种根据题目意思很容易知道是找三元环了,对于每一个点我们去找符合题意的三元环,就是找一个有边的,找一个没有边的,最后去下重,然后判断是不是等于全部三元环的个数就行了。
第一种:
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cstring>
#include<iostream>
#include<sstream>
#include<cmath>
#include<vector>
#define LL long long
#define INF 0x3f3f3f3f
#define eps 1e-6
using namespace std;
using namespace std;
const LL mod = 1e9 + 7;
int mp[10][10];
int n;
int T;
int main()
{
scanf("%d",&T);
while(T--){
scanf("%d",&n);
memset(mp,0,sizeof(mp));
if(n>=6){
for(int i = 1;i<=n;i++){
for(int j = 1;j<=n-i;j++){
int x;
scanf("%d",&x);
}
}
}
else{
for(int i = 1;i<=n;i++){
for(int j = 1;j<=n-i;j++){
int x;
scanf("%d",&x);
mp[i][i+j] =x;
mp[i+j][i] = x;
}
}
}
if(n>=6){
puts("Bad Team!");
}
else{
int falg = 1;
for(int i = 1;i<=n;i++){
for(int j = 1;j<=n;j++){
for(int k = 1;k<=n;k++){
if(i==j||j==k||i==k)
continue;
if(mp[i][j]==1&&mp[i][k]==1&&mp[j][k]==1){
falg= 0;
//cout<<"fuck1"<<endl;
}
if(mp[i][j]==0&&mp[i][k]==0&&mp[j][k]==0){
//cout<<i<<' '<<j<<' '<<k<<endl;
//cout<<"fuck2"<<endl;
falg = 0;
}
}
}
}
if(falg)
puts("Great Team!");
else
puts("Bad Team!");
}
}
}
第二种:
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
#include<memory.h>
#include<iostream>
#define eps 1e-6
#define LL long long
using namespace std;
int cnt[3005];
int n;
int T;
int main()
{
scanf("%d",&T);
while(T--){
scanf("%d",&n);
memset(cnt,0,sizeof(cnt));
for(int i = 1;i<=n;i++){
for(int j = 1;j<=n-i;j++){
int x;
scanf("%d",&x);
if(x){
cnt[i]++;
cnt[i+j]++;
}
}
}
LL sum = (LL)n*(n-1)*(n-2)/6;
LL sum2 = 0;
for(int i = 1;i<=n;i++){
sum2+=(LL)(cnt[i])*(n-cnt[i]-1);
}
if(sum2/2==sum)
puts("Great Team!");
else
puts("Bad Team!");
}
}