2019.12.7PAT冬季考试第二题 - 7-3 Summit (25分)

Unity四部曲(核心) 需要先改成Cube复杂的展开留到unity进阶再说。 阅读详情

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.

读懂题意很重要。

这道题看上去像是图题,其实更多的是一道模拟题,自己唯一一道AC的题,花了太多的时间,惭愧。

AC的时候距离考试结束已经只有13分钟了,没有时间做第4道题,其实,第4道题更简单分值又高。

1.自己的解法

// ConsoleApplication4.cpp : 定义控制台应用程序的入口点。
//


#include<cstdio>
#include<vector>
#include<iostream>
#include<queue>
#include<stack>
#include<cstring>
#include<string>
#include<set>
#include<algorithm>
using namespace std;


int n, m, l;
const int maxn = 210;
vector<int> wait;
vector<int> Adj[maxn], add;
int add_cnt[maxn] = {0};
int G[maxn][maxn] ={0};
int area_num = 1;
/*
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
*/
void makejudge(){
	add.clear();
	fill(add_cnt, add_cnt + maxn, 0);
	sort(wait.begin(), wait.end());
	int head_num = wait.size();
	int cnt; 
	vector<int> friends;
	int flag = 1;
	for(int i = 0; i < head_num; i++){
		if(flag == 0) break;
		for(int j = i + 1; j < head_num; j++){
			if(G[wait[i]][wait[j]] != 1){
				flag = 0;
				break;
			}
		}	
	}
	if(flag == 0){
		printf("Area %d needs help.\n", area_num);
		return;
	}
	set <int> friend_set;
	for(int i = 0; i < head_num; i++){
		friend_set.insert(wait[i]);
	}
	for(int i = 0; i < head_num; i++){
		int head = wait[i];
		for(int j = 0; j < Adj[head].size(); j++){
			int head_friend = Adj[head][j];
			if(friend_set.find(head_friend) == friend_set.end()){
				add_cnt[head_friend]++;
			}
		}
	}
	for(int i = 0; i < maxn; i++){
		if(add_cnt[i] == head_num) add.push_back(i);
	}
	if(add.empty()){
		printf("Area %d is OK.\n", area_num);
	}
	else{
		sort(add.begin(), add.end());
		printf("Area %d may invite more people, such as %d.\n", area_num, add[0]);
	}

}

int main(){
	cin>>n>>m;
	for(int i = 0; i < m; i++){
		int v1, v2;
		scanf("%d%d", &v1, &v2);
		G[v1][v2] = 1;
		G[v2][v1] = 1;
		Adj[v1].push_back(v2);
		Adj[v2].push_back(v1);
	}
	cin>>l;
	for(int i = 0; i< l; i++){
		int num;
		scanf("%d", &num);
		wait.clear();
		for(int j = 0; j < num ; j++){
			int head;
			scanf("%d", &head);
			wait.push_back(head);
		}
		makejudge();
		area_num++;
	}


	return 0;
}

 2大神的解法

isOk判断是否任意两人是friends,if not ok,直接print need help; if ok, 进行下一步判断。

set<>的方法, st.find(),如果找不到,返回st.end()

判断的步骤,找一个不在的head  -> 尝试将head加入summit -> 判断 -> 如果ok,提出建议。 如果遍历完了,还是没有可加入的,打印 area x is ok.

#include <cstdio>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;
const int INF=1000000000;
const int maxN=210;
int G[maxN][maxN]={0};
int isOk(vector<int> summit){
	for (int i=0; i<summit.size(); i++){
		for (int j=i+1; j<summit.size(); j++){
			int u=summit[i];
			int v=summit[j];
			if (G[u][v]!=1){
				return 0;
//				printf("%d %d\n",i,j);
			}
		}
	}
	return 1;
}
int main(){
	int n,m;
	scanf("%d %d",&n,&m);
	for (int i=1; i<=n; i++){
		G[i][i]=1;
	}
	for (int i=0; i<m; i++){
		int u,v;
		scanf("%d %d",&u, &v);
		G[u][v]=G[v][u]=1;
	}
	int k;
	scanf("%d",&k);
	for (int i=0; i<k; i++){
		int l;
		scanf("%d",&l);
		vector<int> summit;
		set<int> st;
		for (int j=0; j<l; j++){
			int index;
			scanf("%d",&index);
			summit.push_back(index);
			st.insert(index);
		}
		if (!isOk(summit)){
			printf("Area %d needs help.\n",i+1);
			continue;
		}
		int k=1;
		for (k=1; k<=n; k++){
			if (st.find(k)==st.end()){
				vector<int> temp=summit;
				temp.push_back(k);
				if (isOk(temp)){
					printf("Area %d may invite more people, such as %d.\n",i+1, k);
					break;
				}
			}
		}
		if (k==n+1) {
			printf("Area %d is OK.\n",i+1);
		}
	}
}

3总结

这道题自己虽然是做出来了,但是实在是做的太烂了,而且思路也很混乱。

通过学习大神的解法,发现解这道题的思路是非常明确的。

1.核心问题:判断head之间是否都是朋友,如果不是,直接出局。因此,要将这一个函数独立出来。

2.在1满足的前提下,判断是否可以加入别的朋友,采用尝试法即可,尝试加入每一个不在set里的朋友,然后再进行判断。

3.如果经过2的检查,确保无遗漏,则可以输出ok。

自己的缺点! 思路不清晰!想要在一个函数中加入太多的功能,导致逻辑混乱,和玩云顶是一样的。

北京联通IPTV组播实战:OpenWRT软路由配置全解析 本文详细解析了在北京联通IPTV环境下,利用OpenWRT软路由和udpxy工具实现组播转单播的实战配置。内容涵盖网络接口设置、防火墙规则、udpxy安装配置、直播源M3U文件处理以及全平台播放指南,帮助用户无需机顶盒即可在家庭局域网内任何设备上流畅观看电视直播。 阅读详情

相关推荐

csp-j/s

CSP-J/S 是中国计算机学会(CCF)主办的 ‌‌(Certified Software Professional Junior/Senior),是信息学奥赛(NOI)体系的入门级选拔考试,也是国内最具权威性的青少年编程能力认证之一。

gxyxxrYYDS的博客 2032

PAT 1166 Summit

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.个人学习记录,代码难免不尽人意。

horsetaill的博客 170

【硬件】通俗易懂的讲解晶体管(三极管和MOS管)的工作原理

晶体管是一个简单的元器件,可用于构建许多有趣的项目。在本文中,我将用通俗易懂的语言给您讲解晶体管的工作原理,以便您可以在电路设计中更好的使用静态管。一旦你学习这些基础知识,对以后的设计和使用来说,将会变得非常容易。我们将重点介绍两种最常见的晶体管:双极型晶体管(三极管)和MOSFET。晶体管的工作原理其实是类似于电子开关。它可以打开和关闭电路。一个简单的思考方法是将晶体管视为无源的继电器。晶体管类似于继电器,从某种意义上说,您可以使用它来打开和关闭某些东西。但晶体管也可以部分导通,一般在放大电路中使用,这部

1万+

2019年12月PAT甲级 第三题 Summit(1166)题解

题目 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 ...

时间的玫瑰的博客 787

海思方案定制hi3531dv200/SS528 DVR方案解析:从硬件选型到编解码实战应用

海思方案,Hi3518EV100,Hi3518CV100,Hi3515CV100,Hi3516CV100,Hi3516ECV100,Hi3516D,Hi3516A,Hi3519,Hi3520D,Hi3521A,Hi3535,Hi3531,Hi3536,Hi3536C,Hi3536D,Hi3518EV200,Hi3518EV201,Hi3520DV200,Hi3516CV200,Hi3516CV300,Hi3516AV200,Hi3520DV300,Hi3519V101,sd3403,hi3519av200

1585

别再瞎试了!用Python+正交设计,5分钟搞定你的多因素实验方案

本文介绍了如何利用Python和正交设计高效优化多因素实验方案。正交设计通过精心设计的正交表,用最少的实验次数覆盖所有因素的水平组合,显著提升实验效率。文章详细讲解了正交设计的核心优势、Python实现工具链、实验实施与数据分析方法,以及高级技巧与常见问题解决方案,帮助读者快速掌握这一强大的实验优化技术。

weixin_42526087的博客 336

A1166 Summit(25分)PAT甲级 (Advanced Level) Practice(C++)满分题解【图】

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

qq_47677800的博客 296

YOLOv8独家原创改进:原创自研 | 自研独家创新DSAM注意力 ,基于BiLevelRoutingAttention注意力升级

提出新颖的注意力DSAM(Deformable Bi-level SpatialAttention Module),创新度极佳,适合科研创新,效果秒杀CBAM,Channel Attention+Spartial Attention升级为新颖的Deformable Bi-level Attention+Spartial Attention

①答疑群聊服务;②YOLO大模型知识问答系统;③计算机视觉论文生成智能体; 1515

PAT-2019年冬季考试-甲级 7-3 Summit (25分) (邻接矩阵存储,直接暴力)

7-3Summit(25分) Asummit(峰会) 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 tho...

蔡军帅 466

NR PUCCH(二)PUCCH format 2/3/4

继续看PUCCH2/3/4:PUCCH format 0和1所携带的信息bits少,UCI bits2bits,信息bit需要经过编码等过程下面分别来看。

ModemProtocol的博客 539

化工设计软件:AVEVA E3D二次开发_(8).管道系统设计

在 AVEVA E3D Design 中,管道规格的定义是确保设计一致性和标准化的关键。通过二次开发,可以自动生成并管理管道规格。下面是一个示例,展示如何通过编写脚本来定义和管理管道规格。# 导入必要的库 import clr。

kkchenjj的博客 978

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 ...

Eucalypt的博客 642

[游戏排查] Baldur‘s Gate 3 加载完成即崩溃?五步排查帮你快速定位问题

《博德之门3》加载崩溃问题解决方案:针对游戏进度条走完后闪退的情况,提供五步排查法。首先清除LevelCache缓存(成功率最高),其次检查Mod兼容性,然后切换Vulkan/DX11渲染API,再排查存档损坏问题,最后可删除配置目录(需备份存档)。重点提示Steam验证无法解决此类问题,建议按步骤顺序排查,多数情况下前两步即可解决问题。

技术小甜甜:传播可落地技术,帮助个人和企业降低解决真实场景问题的成本 3264

PAT甲级 2019年冬季12月7日 满分题解

写在前面 本次参加了2019年12月7日PAT冬季考试,考点在北京工业大学(土豪大学)。考试时间3个小时。一个半小时AK,其中第一道题提交了5次,第二道题提交2次,第三道题提交1次,第四道题提交1次,总排名好像是30。 这个报名是老早就报的,因为九月参加了一次,报名的时候发现北京赛区已满,只能去保定河北大学考试,成本着实有点高。 这学期其实很忙的,计网实践,算法,数据库,编译原理,操作系统,还有我...

冰冻三尺非一日之寒 1146

RU DOS版、EFI版32bit/64bit BIOS常用工具

DOS版、EFI版的RU工具,可用来查看IO、MEM、PCI、SMBIOS等资源。亲测在EFI SHELL下可用。

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

PAT(甲级)2019年冬季考试

PAT(甲级)2019年冬季考试7-1 Good in C (20分)7-2 Block Reversing (25分)7-3 Summit (25分)7-4 Cartesian Tree (30分) 7-1 Good in C (20分) 题意:给定 26 字母的写法,每个由 7×57\times 57×5 的字符矩阵组成。给定一个字符串 s,让你输出 s 中的每个单词。 思路:将 26 个字母存在三维数组中。然后在 s 中找到所有的单词。最后根据单词构造这个答案。每次都指定好,每个字母的位置即可。 细

qq_17080419的博客 378

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

PAT(甲级)2019年冬季考试 7-3 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 ...

faith_Dy的博客 308

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

PAT(甲级)2019年冬季考试7-3 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

shshbdhsjjd的博客 177

PAT(甲级)2019年冬季考试 7-1 Good in C (20分) 7-2 Block Reversing (25分) 7-3 Summit (25分) 7-4 Cartesian Tree (

7-1Good in C(20分) 读题比较麻烦,实际不难,注意输出格式就可以了。 #include<cstdio> #include<vector> #include<iostream> #include<queue> #include<cmath> #include<string> #include<alg...

Ike_Lin的博客 398

7-3 Summit (25分)

7-3Summit(25分) Asummit(峰会) 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...

~ 760

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

白小飞 354

1058 选择题(20 分)

1058 选择题(20 分) 批改多选题是比较麻烦的事情,本题就请你写个程序帮助老师批改多选题,并且指出哪道题错的人最多。 输入格式: 输入在第一行给出两个正整数 N(≤ 1000)和 M(≤ 100),分别是学生人数和多选题的个数。随后 M 行,每行顺次给出一道题的满分值(不超过 5 的正整数)、选项个数(不少于 2 且不超过 5 的正整数)、正确选项个数(不超过选项个数的正整数)、所有正...

YuannaY的博客 568

1166 Summit (25 point(s)) PAT甲级

1166 Summit (25 point(s)) 题目 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

neko的博客 569

1166 Summit (25 分) PAT

PAT 1166

zhang12308的博客 415

PAT甲级 2019年冬季 题解

题目1:7-1 Good in C (20分) When your interviewer asks you to write “Hello World” using C, can you do as the following figure shows? Input Specification: Each input file contains one test case. For each case, the first part gives the 26 capital English letters

我是没有梦想的小白 935

PAT甲级2019冬7-3 Summit(1166)(邻接矩阵存储,直接暴力)

PAT-2019年冬季考试-甲级 7-3 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 eve

0 590

鱼额宝 之 error LNK2001: 无法解析的外部符号 之 静态数据成员的定义

C5-1 “鱼额宝” 题目描述 请实现一个“鱼额宝”类,下面已给出代码模板,请根据main函数中对该类的操作,补充类实现部分完成代码。 “鱼额宝”类可以记录账户余额、存钱、取钱、计算利息。该类中有一个私有静态成员变量profitRate存储“鱼额宝”的利率,可以用共有静态成员函数setProfitRate修改利率的值。程序输入为第1天至第n天连续n天的账户操作,每天只能进行一次账户操作,或存...

DedicateToAI的博客 1096
上一篇: 2019.12.7PAT冬季考试第二题 - 7-2 Block Reversing (25分)
下一篇: 2019.12.7PAT冬季考试第四题 - 7-4 Cartesian Tree (30分)
DedicateToAI
博客等级 码龄9年 6粉丝 90原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值