19年冬季第二题 PAT甲级 1166 Summit (25分)
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.
主要是写出流程图,做题之前1.仔细仔细仔细审题。2.建模。和那啥哈密顿图很像?还是啥图来着
//如果没有人和这里的人全部是朋友,且这里的人两两都是朋友,就是ok
//如果还有人和这里的所有人都是朋友,就直接输出这个人
//如果不全都是朋友,就输出need help
#include<iostream>
#include<algorithm>
#include<vector>
#include<cstdio>
using namespace std;
const int maxn = 205;
const int INF = 1000000000;
int G[maxn][maxn];int main(){fill(G[0],G[0]+maxn*maxn,INF);int n,m;//人是从0开始的 cin>>n>>m;int u,v;for(int i = 0;i < m; i++){cin>>u>>v;G[u][v] = G[v][u] = 1;}int q,k,dian;cin>>q;for(int i = 1; i <= q; i++){vector<int> v;cin>>k;bool needHelp = false;bool mayInvite = false;int inviteIndex;for(int j = 0; j < k; j++){cin>>dian;v.push_back(dian);}for(int j = 0; j < k -1;j++){for(int l = j+1;l < k; l++){if(G[v[j]][v[l]] == INF){needHelp = true;}}}for(int j = 1; j <= n; j++){bool flag = true;for(int l = 0; l < k; l++){if(G[j][v[l]] == INF){flag = false;break;}}if(flag == true){mayInvite = true;inviteIndex = j;break;}}if(needHelp == true) printf("Area %d needs help.\n",i);else if(mayInvite == true) printf("Area %d may invite more people, such as %d.\n",i,inviteIndex);else printf("Area %d is OK.\n",i);}return 0;
}
搞清楚判断的是G[v[j]][v[l]]不是j和l!
19年冬季第二题 PAT甲级 1166 Summit (25分)相关推荐
- 19年冬季第二题 PAT甲级 1165 Block Reversing (25分) 跟1133类似的题目
题目 Given a singly linked list L. Let us consider every K nodes as a block (if there are less than K ...
- PAT甲级——1166 Summit (25 分)
思路: 模拟,用两位vector表示edge相连关系 然后,看是否两两相连和是否有其他点与其都相连 src // 不需要并查 #include<bits/stdc++.h> using n ...
- 19年春季第二题 PAT甲级 1157 Anniversary(25 分)
英文题目 Zhejiang University is about to celebrate her 122th anniversary in 2019. To prepare for the cel ...
- 19年秋季第一题 PAT甲级 1161 Forever (20 分) 有点儿意思
如果喜欢我的文章请点赞让我知道噢 题目 7-1 Forever (20 分) "Forever number" is a positive integer A with K dig ...
- 17冬第二题 PAT甲级 1141 Ranking of Institutions (25分) 有点鸡贼
题目 After each PAT, the PAT Center will announce the ranking of institutions based on their students' ...
- PAT甲级 1166 Summit
update202302 for(j = 1; j <= N; j++) 编号从1~N,要记得加上<= #include<iostream> #include<uno ...
- PAT 甲级 A1010 Radix (25 分)
题目传送门 这个题用二分做,我自己写的二分呢太菜了,只能拿到19分,不放出来丢人了.后面看了yxc的代码,美妙绝伦哈. 慢慢来拜读一下. #include "bits/stdc++.h&qu ...
- PAT甲级 1032 Sharing (25分) 测试点5陷阱
题目 1032 Sharing 分析 suffix是后缀,题目的意思是求两个单词的公共后缀的第一个字符的地址.我看有些博客说求的是首个共用结点的地址,我觉得是不对的. 晴神/柳神的解法,是把第一个单词 ...
- PAT (Advanced Level) Practice 1166 Summit (25 分)
题目 因为只是判断是否是直接相连,所以觉得直接用暴力模拟,而且数据范围也很小.果然,许久不练题,A题的效率都下降了.不过,练题真的是打发时间的好途径. #include <bits/stdc++ ...
最新文章
- bool类型返回值_Python 到底是强类型语言,还是弱类型语言?
- PHP输入流php://input介绍
- .NET Core 2.0终于发布了
- 每天学一点儿shell:Linux三剑客——awk命令
- python保存的是什么类型文件_python-----基本的数据类型和文件操作
- 牛客IOI周赛16-普及组
- centos uninstall teamviewer11
- 20155229《网络对抗技术》Exp9:Web安全基础
- ie6中兼容性问题总结
- 利用after和before伪元素在文字两边写横线
- 使用 artitalk + LeanCloud 配置给个人博客搭建说说
- 宝塔面板关键目录解析
- 我为什么离开华为加入ThoughtWorks(思特沃克)
- 吐血推荐:无解的完成图
- word中使用通配符替换【持续更新系列】
- 《Effective C++》 目录
- Android_GitHub_xUtils之DbUtils、ViewUtils、HttpUtils、BitmapUtils
- 南京计算机图书,计算机中心附近图书馆
- 模仿京东登录页面(HTML、CSS、JavaScript / jQuery)
- 005 ps基础之图像旋转、裁剪