PAT-2019年冬季考试 - Grade 7-3 Summit (25 minutes) (the adjacency matrix storage, direct violence)

7-3 Summit (25 minutes)
 

A summit (峰会) is a meeting of heads of state or government. Arranging the rest areas for the summit is not a simple job. The ideal arrangement of one area is to invite those heads so that everyone is a direct friend of everyone.

Now given a set of tentative arrangements, your job is to tell the organizers whether or not each area is all set.

Input Specification:

Each input file contains one test case. For each case, the first line gives two positive integers N (≤ 200), the number of heads in the summit, and M, the number of friendship relations. Then M lines follow, each gives a pair of indices of the heads who are friends to each other. The heads are indexed from 1 to N.

Then there is another positive integer K (≤ 100), and K lines of tentative arrangement of rest areas follow, each first gives a positive number L (≤ N), then followed by a sequence of L distinct indices of the heads. All the numbers in a line are separated by a space.

Output Specification:

For each of the K areas, print in a line your advice in the following format:

  • if in this area everyone is a direct friend of everyone, and no friend is missing (that is, no one else is a direct friend of everyone in this area), print Area X is OK..

  • if in this area everyone is a direct friend of everyone, yet there are some other heads who may also be invited without breaking the ideal arrangement, print Area X may invite more people, such as H. where H is the smallest index of the head who may be invited.

  • if in this area the arrangement is not an ideal one, then print Area X needs help. so the host can provide some special service to help the heads get to know each other.

Here X is the index of an area, starting from 1 to K.

Sample Input:

8 10
5 6
7 8
6 4
3 6
4 5
2 3
8 2
2 7
5 3
3 4
6
4 5 4 3 6
3 2 8 7
2 2 3
1 1
2 4 6
3 3 2 1

Sample Output:

Area 1 is OK.
Area 2 is OK.
Area 3 is OK.
Area 4 is OK.
Area 5 may invite more people, such as 3.
Area 6 needs help.

 

Meaning of the questions:

To N points, M edges. The K inquiry. Each inquiry is given L points, ask the L twenty-two point is not connected.

If any two connected:

  A memory other do not exist, are connected to the L points:

    Have:Area i may invite more people, such as 这个点.

    No:Area i is OK.

Twenty-two not connected:Area i needs help.

 

answer:

 
Understand the meaning of problems found quite a simple thing, you do not need to check and set, direct adjacency matrix storage, direct violence ok, when the exam again before, surprise!
 

AC Code:

 

#include<bits/stdc++.h>
using namespace std;
int e[205][205];
int a[205];
int v[205];
int n,m;
int main(){
    cin>>n>>m;
    memset(e,0,sizeof(e));
    for(int i=1;i<=m;i++){
        int u,v;
        cin>>u>>v;
        e[u][v]=e[v][u]=1;//Storing adjacency matrix 
    }
     int K; 
    CIN >> K;
     int NUM;
     for ( int I = . 1 ; I <= K; I ++) { // K th interrogation 
        CIN >> NUM; 
        Memset (V, 0 , the sizeof (V) ); // V asked to mark num points 
        for ( int J = . 1 ; J <= num; J ++ ) { 
            CIN >> a [J]; 
            V [a [J]] = . 1 ; // cook flag 
        }
         int F = . 1; // is not twenty-two connected 
        for ( int J = . 1 ; J <= NUM; J ++ ) {
             for ( int P = J + . 1 ; P <= NUM; P ++ ) {
                 IF (E [A [J]] [A ! [P]] = . 1 ) F = 0 ;
                 BREAK ; 
            } 
        } 
        IF (F) COUT <<! " Area " << I << " Needs Help. " ;
         the else { // If pairwise connected 
            int ANS = - 1 ; // if there is
            for ( int J = . 1 ; J <= n-; J ++) { // query exists or not a point which points are connected num 
                IF (V [J]) Continue ; // se num point is not in the 
                int FF = . 1 ; 
                 for ( int P = . 1 ; P <= NUM; P ++ ) {
                     IF (E [A [P]] [J] =! . 1 ) { 
                        FF = 0 ;
                         BREAK ;     
                    } 
                } 
                IF (FF) { // meet with each point are connected in num
                    ans=j;//存在 
                    break;
                }
            }
            if(ans!=-1){//存在 
                cout<<"Area "<<i<<" may invite more people, such as "<<ans<<".";
            }else{//不存在 
                cout<<"Area "<<i<<" is OK."; 
            }
        }
        if(i!=k) cout<<endl;// end of the no blank lines 
    }
     return  0 ; 
}

 

 

 

Guess you like

Origin www.cnblogs.com/caiyishuai/p/12005418.html