7-3 Summit (25分)
 

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.

题意:

给N个点,M条边。K个询问。每个询问给出L个点,问这L个点是不是两两相连的。

如果两两相连:

  存不存在一个其它的点,与这L个点都有连接:

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

    没有:Area i is OK.

不是两两相连:Area i needs help.

 

题解:

 
看懂题意发现挺简单的嘛,不需要并查集,直接邻接矩阵存储,直接暴力就ok了,考试的时候一遍过,惊喜!
 

AC代码:

#include<bits/stdc++.h>
using namespace std;
int e[][];
int a[];
int v[];
int n,m;
int main(){
cin>>n>>m;
memset(e,,sizeof(e));
for(int i=;i<=m;i++){
int u,v;
cin>>u>>v;
e[u][v]=e[v][u]=;//邻接矩阵存储
}
int k;
cin>>k;
int num;
for(int i=;i<=k;i++){//k个询问
cin>>num;
memset(v,,sizeof(v));//v来标记所询问的num个点
for(int j=;j<=num;j++) {
cin>>a[j];
v[a[j]]=;//做上标记
}
int f=;//是不是两两相连
for(int j=;j<=num;j++){
for(int p=j+;p<=num;p++){
if(e[a[j]][a[p]]!=) f=;
break;
}
}
if(!f) cout<<"Area "<<i<<" needs help.";
else{//如果是两两相连
int ans=-;//是否存在
for(int j=;j<=n;j++){//查询存不存在一个点与这num个点都相连
if(v[j]) continue;//本身是num个点里的不算
int ff=;
for(int p=;p<=num;p++){
if(e[a[p]][j]!=){
ff=;
break;
}
}
if(ff) {//满足与num中的每个点都相连
ans=j;//存在
break;
}
}
if(ans!=-){//存在
cout<<"Area "<<i<<" may invite more people, such as "<<ans<<".";
}else{//不存在
cout<<"Area "<<i<<" is OK.";
}
}
if(i!=k) cout<<endl;//行末无空行
}
return ;
}

PAT-2019年冬季考试-甲级 7-3 Summit (25分) (邻接矩阵存储,直接暴力)的更多相关文章

  1. PAT-2019年冬季考试-甲级 7-2 Block Reversing (25分) (链表转置)

    7-2 Block Reversing (25分)   Given a singly linked list L. Let us consider every K nodes as a block ( ...

  2. PAT-2019年冬季考试-甲级 7-4 Cartesian Tree (30分)(最小堆的中序遍历求层序遍历,递归建树bfs层序)

    7-4 Cartesian Tree (30分)   A Cartesian tree is a binary tree constructed from a sequence of distinct ...

  3. PAT (Advanced Level) Practice 1002 A+B for Polynomials (25 分) 凌宸1642

    PAT (Advanced Level) Practice 1002 A+B for Polynomials (25 分) 凌宸1642 题目描述: This time, you are suppos ...

  4. PAT (Basic Level) Practice (中文)1055 集体照 (25 分) 凌宸1642

    PAT (Basic Level) Practice (中文)1055 集体照 (25 分) 凌宸1642 题目描述: 拍集体照时队形很重要,这里对给定的 N 个人 K 排的队形设计排队规则如下: 每 ...

  5. PAT-2019年冬季考试-甲级 7-1 Good in C (20分)

    7-1 Good in C (20分)   When your interviewer asks you to write "Hello World" using C, can y ...

  6. 【PAT甲级】1070 Mooncake (25 分)(贪心水中水)

    题意: 输入两个正整数N和M(存疑M是否为整数,N<=1000,M<=500)表示月饼的种数和市场对于月饼的最大需求,接着输入N个正整数表示某种月饼的库存,再输入N个正数表示某种月饼库存全 ...

  7. PAT 甲级 1020 Tree Traversals (25分)(后序中序链表建树,求层序)***重点复习

    1020 Tree Traversals (25分)   Suppose that all the keys in a binary tree are distinct positive intege ...

  8. PAT 甲级 1146 Topological Order (25 分)(拓扑较简单,保存入度数和出度的节点即可)

    1146 Topological Order (25 分)   This is a problem given in the Graduate Entrance Exam in 2018: Which ...

  9. PAT 甲级 1071 Speech Patterns (25 分)(map)

    1071 Speech Patterns (25 分)   People often have a preference among synonyms of the same word. For ex ...

随机推荐

  1. asp.net中的参数传递:Context.Handler 的用法

    网上天天有人问怎么在webform页面之间传值,基本上来说,大家熟悉的是     (1)url字符串传值     (2)session传值     (3)直接读取server.transfer过来的页 ...

  2. 初识Java(Java数字处理类-大数字运算)

    一.大数字运算 在 Java 中提供了大数字的操作类,即 java.math.BigInteger 类与  java.math.BigDecimal 类.这两个类用于高精度计算,体重 BigInteg ...

  3. Normalize.css重置化样式表

    Normalize.css是一种CSS reset的替代方案.它在默认的HTML元素样式上提供了跨浏览器的高度一致性.相比于传统的CSS reset,Normalize.css是一种现代的.为HTML ...

  4. JQuery系列(7) - JQuery最佳实践

    上篇文章是一篇入门教程,从设计思想的角度,讲解"怎么使用jQuery".今天的文章则是更进一步,讲解"如何用好jQuery". 我主要参考了Addy Osman ...

  5. Can总线上的电平及物理层仲裁

    CAN总线采用差分信号传输,通常情况下只需要两根信号线(CAN-H和CAN-L)就可以进行正常的通信.在干扰比较强的场合,还需要用到屏蔽地即CAN-G(主要功能是屏蔽干扰信号),CAN协议推荐用户使用 ...

  6. Linux中的查找与替换

    grep只能用于查找文件中的内容sed可以查找,然后替换或者插入想要的内容 a :新增,a的后面可以接字串,而这些字串会在新的一行出现(目前的下一行):d :删除,因为是删除啊,所以d后面通常不接任何 ...

  7. Nginx 代理到Jetty 页面跳转端口改变问题

    Nginx安装 Windows下部署Nginx只需下载安装包,解压启动服务器即可.下载官网:http://nginx.org/en/download.html 操作Nginx首先进入安装文件夹: 查看 ...

  8. JS线程机制与事件机制

    JS线程机制与事件机制 1.进程与线程 (1).定义: 进程:程序的一次执行,它占有一片独有的内存空间 CPU的基本调度单位,是程序执行的一个完整的流程 (2).进程与线程的关联 一个进程一般至少有一 ...

  9. 第五届新疆ACM H-虚无的后缀

    来源 第五届新疆省ACM-ICPC程序设计竞赛nowcoder重现赛 H-虚无的后缀 思路1 好菜哦. 首先后缀零的个数最多,我们只需要考虑他的质因子2和5的个数就行了(存为a,b). 因为其他因子对 ...

  10. linux下 调试C#代码

    参考两位大神的帖子: https://blog.csdn.net/soband_xiang/article/details/82914195 https://blog.csdn.net/weixin_ ...