PAT-2019年冬季考试-甲级 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.whereHis 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.
题解:
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分) (邻接矩阵存储,直接暴力)的更多相关文章
- 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 ( ...
- 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 ...
- 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 ...
- PAT (Basic Level) Practice (中文)1055 集体照 (25 分) 凌宸1642
PAT (Basic Level) Practice (中文)1055 集体照 (25 分) 凌宸1642 题目描述: 拍集体照时队形很重要,这里对给定的 N 个人 K 排的队形设计排队规则如下: 每 ...
- 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 ...
- 【PAT甲级】1070 Mooncake (25 分)(贪心水中水)
题意: 输入两个正整数N和M(存疑M是否为整数,N<=1000,M<=500)表示月饼的种数和市场对于月饼的最大需求,接着输入N个正整数表示某种月饼的库存,再输入N个正数表示某种月饼库存全 ...
- PAT 甲级 1020 Tree Traversals (25分)(后序中序链表建树,求层序)***重点复习
1020 Tree Traversals (25分) Suppose that all the keys in a binary tree are distinct positive intege ...
- PAT 甲级 1146 Topological Order (25 分)(拓扑较简单,保存入度数和出度的节点即可)
1146 Topological Order (25 分) This is a problem given in the Graduate Entrance Exam in 2018: Which ...
- PAT 甲级 1071 Speech Patterns (25 分)(map)
1071 Speech Patterns (25 分) People often have a preference among synonyms of the same word. For ex ...
随机推荐
- Vuex准备
(1)简介 每一个 Vuex 应用的核心就是 store(仓库).“store”基本上就是一个容器,它包含着你的应用中大部分的状态 (state).Vuex 和单纯的全局对象有以下两点不同: Vuex ...
- flex布局--小实例
圣杯布局(Holy Grail Layout)指的是一种最常见的网站布局.页面从上到下,分成三个部分:头部(header),躯干(body),尾部(footer).其中躯干又水平分成三栏,从左到右为: ...
- 警告:Establishing SSL connection without server’s identity verification is not recommended
SpringBoot启东时红色警告: Mon Jun 04 00:53:48 CST 2018 WARN: Establishing SSL connection without server's i ...
- Ofbiz项目学习——阶段性小结——更新数据
一.根据一个字段进行修改 /** * 根据一个字段进行修改(这个条件字段可以是主键, 也可以不是主键) * @param dctx * @param context * @return */ publ ...
- learning shell check host dependent pkg
[Purpose] Shell script check host dependent pkg [Eevironment] Ubuntu 16.04 bash env ...
- benchmarkdotnet docker 运行
使用docker 运行基准测试是一个不错的选择,可以减少我们环境搭建的时间,同时也可以加速ci/cd 环境准备 docker-compose 文件 version: "3" ser ...
- nginx.conf 配置解析之 http配置
官方文档 http://nginx.org/en/docs/参考链接: https://segmentfault.com/a/1190000012672431参考链接: https://segment ...
- Java 整数间的除法运算如何保留所有小数位?
1.情景展示 double d = 1/10; System.out.println(d); 返回的结果居然是0.0!这是怎么回事儿? 2.原因分析 第一步:你会发现用运算结果也可以用int类型接 ...
- [BUAA软工]Beta阶段测试报告
Beta阶段测试报告 Bug发现与报告 BUG 出现原因 解决方案 将shell加上编辑器UI以后,两边显示的文件不同步 两边的根目录不一致 修改编辑器获取根目录的函数,使其与shell的/home目 ...
- 闲话Dicom
最近在准备一场有关DICOM应用的讲座,整理了一下思路.想了几个问题,发现挺有意思的,想与大家共同分享.接触过DICOM,应该了解普通DICOM 文件包含的四级属性,病人,检查,序列,影像.每一级别需 ...