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!
文章浏览阅读5.4w次,点赞89次,收藏746次。java常见面试题_java面试题
文章浏览阅读5.4k次,点赞6次,收藏73次。编程总结每每刷完一道题后,其思想和精妙之处没有地方记录,本篇博客用以记录刷题过程中的遇到的算法和技巧001)两数之和给定一个整数数组 nums 和一个目标值 target,请你在该数组中找出和为目标值的两个整数。你可以假设每种输入只会对应一个答案。但是,你不能重复利用这个数组中同样的元素。给定 nums = [2, 7, 11, 15], target = 9因为 nums[0] ..._leetcode c语言
文章浏览阅读125次。检查请求头中的’sec-fetch-dest’: ‘document’ ,是否进行了特殊处理(node层)_苹果 sec-fetch-dest
文章浏览阅读321次。服务器初始化(这是在建立在新的服务器基础上做的初始化)关闭防火墙、selinux,添加epel常用源,安装常用工具、添加普通用户并禁止root1、服务器批量初始化[root@fwd ansible]# cat init.yml 系统初始化脚本---- hosts: all tasks: - name: disable selinux、firew..._ansible批量安装zabbix-agent
文章浏览阅读1.4w次,点赞3次,收藏2次。Logger.getLogger(Test.class);从getLogger开始,就启动了log4j的整个工作流程,通过调用LogManager获取logger实例return LogManager.getLogger(clazz.getName());LogManager类里面有个静态块static{},【初始化重要信息】【root logger】,做一些配置,其中url = Loader.ge_log4j 源码分析 读取配置
文章浏览阅读533次。无奈的父亲有一个美丽的小女孩,她的名字叫余艳,她有一双亮晶晶的大眼睛她有一颗透明的童心.她是一个孤儿,她在这个世界上只活了8年,她留在这个世界上最后的一句话是“我来过,我很乖”她希望死在秋天,纤瘦的身体就像一朵花自然开谢的过程.在遍地黄花堆积,落叶空中旋舞的时候,她会看见横空远行的雁儿们.她自愿放弃治疗,把全世界华人捐给她的54万分成了7份,把生命当成希望的蛋糕分给了7个正徘徊在生死线上的小
文章浏览阅读1.6k次,点赞42次,收藏35次。什么是牵引逆变器?从本质上讲,牵引逆变器是电动汽车动力系统中的一个子系统,它从电池中获取高电压,并将其转换为交流电压——因此被称为逆变器——并基本上为电机供电。它控制电机速度和扭矩,直接影响效率和可靠性,这正成为牵引逆变器设计的设计挑战。此图片来源于网络如今的电动汽车至少有一个牵引逆变器。有些型号实际上不止一个。一个在前轴上,一个在后轴上。甚至一些高端车型实际上每个车轮都有一个牵引逆变器。因此,效率和可靠性非常重要。所以,从逆变器和电机控制的市场趋势来看——从技术趋势来看,我们看到了功率水平的提高。
文章浏览阅读134次。简介apt-cache和apt-get是apt包的管理工具,他们根据/etc/apt/sources.list里的软件源地址列表搜索目标软件、并通过维护本地软件包列表来安装和卸载软件。查看本机是否安装软件:whereis package_name 或者which package_name1.搜索软件sudo apt-cache search pa..._ubuntu18.04 atp命令使用技巧
文章浏览阅读150次。【代码】查询Dynamics 365的Audit History。_dynamics 审核历史记录如何查询
文章浏览阅读1.3w次,点赞15次,收藏66次。什么是yield函数?yield函数是python里面的关键字,带有yield的函数相当于一个生成器generator.当你使用一个yield的时候,对应的函数就是一个生成器在python里面类似于return函数,他们主要的区别就是:遇到return会直接返回值,不会执行接下来的语句.但是yield并不是,在本次迭代返回之后,yield函数在下一次迭代时,从上一次迭代遇到的yield后面的代码(下一行)开始执行下面是案例分析:案例一:def gen_generator(): yiel_yield函数
文章浏览阅读917次。如果不用seek(0)的话,默认是自己会把读取文件的指针后移的,不用手动后移;_qfileread后指针会移动吗
文章浏览阅读2.5k次。整理了网上一份简单的dw8051测试示例,共享到云盘:http://pan.baidu.com/s/1bnu9lZT1.目录如下:---dut ---rtl:DW8051的core文件 ---model:ROM和RAM的model文件---testbench ---rtl.f:filelist文件 ---test_top.v:仿真的top_dw8051 part1