1121 Damn Single
题意:
给出n对情侣,然后给出聚会上的m个人,问这m个人中有几个人事落单的。
思路:
首先,开一个数组couple[]存储情侣间的映射关系;然后,用exist[]标记聚会上出现过的人;最后遍历0~N,如果当前这个id在聚会中出现过,就考察其对应的couple即可。需要注意的是,由于人的id是从00000~99999,所以要注意输出格式的控制,还有,在初始化couple的时候要设置成-1,而不可是0(因为id可能是0);
代码:
#include <cstdio>
#include <cstring>
;
int couple[N];
int exist[N];
int main()
{
//freopen("pat.txt","r",stdin);
memset(couple,-,sizeof(couple));
memset(exist,,sizeof(exist));
int n,m;
int u,v;
scanf("%d",&n);
;i<n;i++){
scanf("%d%d",&u,&v);
couple[u]=v;
couple[v]=u;
}
scanf("%d",&m);
;i<m;i++){
scanf("%d",&u);
exist[u]=;
}
;
];
;id<N;id++){
if(exist[id]){
|| exist[couple[id]]==) ans[cnt++]=id;
}
}
printf("%d\n",cnt);
) printf(]);
;i<cnt;i++)
printf(" %05d",ans[i]);
;
}
1121 Damn Single的更多相关文章
- 1121 Damn Single (25 分)
1121 Damn Single (25 分) "Damn Single (单身狗)" is the Chinese nickname for someone who is bei ...
- PAT甲级 1121. Damn Single (25)
1121. Damn Single (25) 时间限制 300 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue "Dam ...
- PAT 1121 Damn Single[简单]
1121 Damn Single (25 分) "Damn Single (单身狗)" is the Chinese nickname for someone who is bei ...
- PTA 1121 Damn Single
题目链接:1121 Damn Single (25 分) "Damn Single (单身狗)" is the Chinese nickname for someone who i ...
- PAT 1121 Damn Single
"Damn Single (单身狗)" is the Chinese nickname for someone who is being single. You are suppo ...
- 1121. Damn Single (25)
"Damn Single (单身狗)" is the Chinese nickname for someone who is being single. You are suppo ...
- PAT甲题题解-1121. Damn Single (25)-水题
博主欢迎转载,但请给出本文链接,我尊重你,你尊重我,谢谢~http://www.cnblogs.com/chenxiwenruo/p/6789787.html特别不喜欢那些随便转载别人的原创文章又不给 ...
- PAT1121:Damn Single
1121. Damn Single (25) 时间限制 300 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue "Dam ...
- PAT 甲级真题题解(63-120)
2019/4/3 1063 Set Similarity n个序列分别先放进集合里去重.在询问的时候,遍历A集合中每个数,判断下该数在B集合中是否存在,统计存在个数(分子),分母就是两个集合大小减去分 ...
随机推荐
- CNI:容器网络接口
CNI 简介 不管是 docker 还是 kubernetes,在网络方面目前都没有一个完美的.终极的.普适性的解决方案,不同的用户和企业因为各种原因会使用不同的网络方案.目前存在网络方案 flann ...
- 测绘类SCI
GeoInformatica(国际地理信息系统计算机科学进展杂志)美国International Journal of Geographical Information Science(国际地理信息科 ...
- LeetCode第[4]题(Java):Median of Two Sorted Arrays (俩已排序数组求中位数)——HARD
题目难度:hard There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median ...
- SSH登陆阿里云服务器出现Permission denied (publickey)错误解决方案
操作环境: 操作系统:Mac10.11.5 阿里云服务器:Ubuntu16.04 远程连接:SSH 注:首先我们已假设你已经自己生成了SSH秘钥,并已经配置到阿里云.绑定了自己的云服务器. 但是后来发 ...
- shell 数组操作
1. 定义数组: var_array=(one two three four five) 2.常用操作 获取数组长度: ${#var_array[@]} 获取所有数组元素: ${var_array[ ...
- Selenium with Python 002 - 快速入门
一.简单实例演示 1.创建 python_org_search.py: #!/usr/bin/env python from selenium import webdriver from seleni ...
- 牛客比赛-假的字符串-Trie+拓扑
链接:https://www.nowcoder.com/acm/contest/59/B来源:牛客网 题目描述 给定n个字符串,互不相等,你可以任意指定字符之间的大小关系(即重定义字典序),求有多少个 ...
- bootstrap 操作提示placeholder
Javascript 部分 function checkForDefaultAlertPlaceholder() { if ($("#alertPlaceholder").leng ...
- Linux下的目录结构
1./ -根 每个文件和目录从根目录开始 只有root用户具有该目录下的写权限,请注意,/root是root用户的主目录,这与/.不一样. 2. /bin -用户二进制文件 包含二进制可执行的文件 ...
- WPF控件开源资源
(转)WPF控件开源资源 Textbox Drag/Drop in WPFhttp://www.codeproject.com/Articles/42696/Textbox-Drag-Drop-in- ...