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集合中是否存在,统计存在个数(分子),分母就是两个集合大小减去分 ...
随机推荐
- Software Engineering at Google
Google的Fergus Henderson在Software Engineering at Google中介绍了Google的软件工程实践. 软件开发 源码仓库 单一源代码仓库,除了核心配置和安全 ...
- VS2015自带v120的Platform Toolset
在VS2015安装组件时,勾选 “Windows 8.1 和 Windows Phone 8.0/8.1”下面的“工具和 Windows SDK”,将会安装Visual Studio 2013 (v1 ...
- oepnstack笔记
openstack简介: 组件:Nova 提供计算资源池neutron 网络资源管理horizon 基于openstack API借口使用django开发的web管理 组件:Nova 提供计算资源池n ...
- 27-THREE.JS 平面
<!DOCTYPE html> <html> <head> <title></title> <script src="htt ...
- STM32F407: USART 遇到的问题
今天初次使用STM32F407进行USART串口通讯实验,按照f103的代码写完了,发现没法发送数据, 查看文档后发现是由于没有将端口映射到USART1,然后添加如下代码: 1 GPIO_PinAFC ...
- 【poj2155】Matrix(二维树状数组区间更新+单点查询)
Description Given an N*N matrix A, whose elements are either 0 or 1. A[i, j] means the number in the ...
- LeetCode OJ:Spiral Matrix(螺旋矩阵)
Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral or ...
- DOM解析XML文件例子
DOM解析XML文件是一次性将目标文件中的所有节点都读入,然后再进行后续操作的方式. 一般分为以下几步: 1. 定义好目标XML文件路径path . 2. 实例化DOM解析工厂对象 ,Document ...
- Vue: webpack js basic structure
vue webpack所用基础包: nom install vue vue-loader webpack webpack-cli webpack-dev-server vue-template-com ...
- 《Drools7.0.0.Final规则引擎教程》第4章 4.2 no-loop
no-loop 定义当前的规则是否不允许多次循环执行,默认是 false,也就是当前的规则只要满足条件,可以无限次执行.什么情况下会出现规则被多次重复执行呢?下面看一个实例: package com. ...