1. 程式人生 > >hdu 6152 Friend-Graph

hdu 6152 Friend-Graph

scrip number problem else -1 source condition test case tween

Friend-Graph

Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 968 Accepted Submission(s): 507

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. 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.(n3000)

Then there are n-1 rows. The ith row should contain n-i numbers, in which number aij 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.

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 2017中國大學生程序設計競賽 - 網絡選拔賽 Recommend liuyiding | We have carefully selected several similar problems for you: 6160 6159 6158 6157 6156 題解大意: 判斷這n個人組成的是一個great team還是bad team, 如果在這n個人中有3人及以上相互不認識貨值有三人及以上相互認識,則是bad team,否則great team 題解: 推出,一個點最多連兩個點,當點數>=6,要把這些點連起來,必然變成bad team 前五個暴力即可,這題當時mle了兩次,下次要註意開的數組大小和題目中的限制
#include <iostream>
#include
<bits/stdc++.h> using namespace std; bool a[3002][3002]; int t,n; bool work() { for(int i=1;i<=n;i++) { for(int j=i+1;j<=n;j++) if(a[i][j]==1) { for(int k=j+1;k<=n;k++) if (a[j][k]==1 && a[k][i]==1) return 0; } else { for(int k=j+1;k<=n;k++) if(a[j][k]==0 && a[k][i]==0) return 0; } } return 1; } int main() { scanf("%d",&t); while(t--) { scanf("%d",&n); for(int i=1;i<=n;i++) { for(int j=1;j<=n-i;j++) { int x; scanf("%d",&x); a[i][i+j]=x; a[i+j][i]=x; } } if (n>5) {printf("Bad Team!\n"); continue;} if(work()) printf("Great Team!\n"); else printf("Bad Team!\n"); } return 0; }

hdu 6152 Friend-Graph