19年冬季第二题 PAT甲级 1166 Summit (25分)-程序员宅基地

技术标签: # 图  算法  PAT  

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!

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/J_avaSmallWhite/article/details/110359642

智能推荐

C#中STRING 怎么转换成 LONG ?_c# string转long-程序员宅基地

文章浏览阅读1.9k次。unity_c# string转long

R语言中计算混淆矩阵_r做混淆矩阵-程序员宅基地

文章浏览阅读249次。在混淆矩阵中,行表示预测结果,列表示真实标签。例如,上述混淆矩阵中有3个真正例(预测正确的正例)、4个真反例(预测正确的反例)、1个假正例(预测错误的正例)和2个假反例(预测错误的反例)。在R语言中,我们可以使用一些库来计算混淆矩阵,如caret和e1071。假设我们有一个二分类问题,类别分别为"正例"和"反例",并且已经得到了一个分类模型的预测结果和真实标签。通过使用R语言提供的库函数,我们可以轻松计算混淆矩阵并获取各种性能指标。除了混淆矩阵本身之外,我们还可以通过混淆矩阵对象获取其他性能指标。_r做混淆矩阵

vscode下.vue文件初始化_vscode初始化vue-程序员宅基地

文章浏览阅读1.8k次。vscode下.vue文件初始化当我们在使用vscode编写vue文件的时候,每次都需要输入&lt;template&gt;&lt;/template&gt;,&lt;script&gt;&lt;/script&gt;,&lt;style&gt;&lt;/style&gt;这些标签如何像我们之前一样写html使用emmet插件一样使用 !自动出来html的格式呢1 安装Vetur扩展让V..._vscode初始化vue

cglib动态代理(需导入cglib-nodep-2.1_3.jar)_导入一个架包:cglib-nodep-2.1.3.jar-程序员宅基地

文章浏览阅读1.7k次。这是一个简单的例子_导入一个架包:cglib-nodep-2.1.3.jar

【CDH】Cloudera manager 卸载并重新安装某一个节点_cdh卸载重装-程序员宅基地

文章浏览阅读2.2k次,点赞2次,收藏4次。完美卸载CDH一个节点并重新安装_cdh卸载重装

tp5缺少start.php,TP5报错Fatal error: require(): Failed opening required '/home/www/xx/public/../thinkphp...-程序员宅基地

文章浏览阅读3k次。PHP message: PHP Warning: require(/data/wwwroot/blog.sgfoot.com/bootstrap/autoload.php): failed to open stream: Operation not permitted in /data/wwwroot/blog.sgfoot.com/public/index.php on line 22PHP ..._notice: php message: php warning: require(/start.php): failed to open stream

随便推点

Learn from Demonstration-程序员宅基地

文章浏览阅读857次。Reference:http://blog.exbot.net/archives/249https://blog.csdn.net/weixin_43822994/article/details/85566552https://zhuanlan.zhihu.com/p/45845001https://blog.csdn.net/c2a2o2/article/details/77336551..._learn from demonstration

最新最详细的配置Node.js环境教程_node配置-程序员宅基地

文章浏览阅读1.6k次,点赞41次,收藏22次。最新最详细的配置Node.js环境教程,已经将所有坑都踩了一遍!!超级超级详细详细!!!_node配置

java web开发的mvc_java的web开发中的mvc模式-程序员宅基地

文章浏览阅读127次。mvc 1,什么是mvc? model,view,controller 是一种软件架构模式,其基本思想是:将一个软件的组成部分划分成三部分,即: 模型:封装业务逻辑 视图:数据展现,也就是表示逻辑(即将模型中提供的数据以合适的方法展示出来), 另外还提供UI(用户接口),用户通过视图向系统发送请求。 控制器:将视图与模型的关系解耦,即视图与模型的调用要通过..._web开发中的mvc

matlab粒子群运动模拟伪代码,基本粒子群优化算法(PSO)的matlab实现-程序员宅基地

文章浏览阅读1.2k次。粒子群优化算法是一种模拟鸟群社会行为的群体搜素算法。它分为全局最佳粒子优化和局部最佳粒子优化,对于全局最佳PSO,或者叫做gbest PSO,每个粒子的邻域都是整个群,其算法伪代码如下:创建并初始化一个n维的粒子群repeatfor 每个粒子i=1,2,…n do//设置个体最佳位置if f(i)y=f(i);end//设置全局最佳位置if yY=y;endendfor每个粒子i=1,2,…n ..._pso伪代码

Linux学习之CentOS(二十六)--Linux磁盘管理:LVM逻辑卷的创建及使用-程序员宅基地

文章浏览阅读370次。您可以通过点击 右下角 的按钮 来对文章内容作出评价, 也可以通过左下方的 关注按钮 来关注我的博客的最新动态。 如果文章内容对您有帮助, 不要忘记点击右下角的 推荐按钮 来支持一下哦 如果您对文章内容有任何疑问, 可以通过评论或发邮件的方式联系我: [email protected] / [email protected]如果需要转载,请注明出处,谢谢!..._can't obtain inputstream for linux-x86-64/libdwfcall.so] with root cause

chatgpt赋能python:Python中如何反转整数_python整数反转-程序员宅基地

文章浏览阅读513次。这篇文章介绍了两种Python中反转整数的方法。我们可以使用字符串反转,在将字符串转换为整数,也可以使用除余和乘法,一位位反转整数。根据实际情况和需要,选择不同的方法。无论使用哪种方法,都可以轻松实现反转整数的操作。反转一个整数虽然看起来很简单,但是这里介绍的方法可以帮助大家更好地理解Python中的字符串处理、循环和除余操作。在日常编程中,我们可以将这些技巧应用到实际的问题中。本文由chatgpt生成,文章没有在chatgpt生成的基础上进行任何的修改。以上只是chatgpt能力的冰山一角。作为通用的。_python整数反转

推荐文章

热门文章

相关标签