Sereja and Bottles-水题有点坑爹
2015-07-30 01:33
471 查看
CodeForces
- 315A
Sereja and Bottles
Submit Status
Description
Sereja and his friends went to a picnic. The guys had n soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles.
Sereja knows that the i-th bottle is from brand ai, besides, you can use it to open other bottles
of brand bi. You can use one bottle to open multiple other bottles. Sereja can open bottle with opened bottle or closed bottle.
Knowing this, Sereja wants to find out the number of bottles they've got that they won't be able to open in any way. Help him and find this number.
Input
The first line contains integer n(1 ≤ n ≤ 100) — the number of bottles. The next n lines
contain the bottles' description. The i-th line contains two integers ai, bi(1 ≤ ai, bi ≤ 1000)—
the description of the i-th bottle.
Output
In a single line print a single integer — the answer to the problem.
Sample Input
Input
Output
Input
Output
0
理解题意即可
- 315A
Sereja and Bottles
Time Limit: 2000MS | Memory Limit: 262144KB | 64bit IO Format: %I64d & %I64u |
Description
Sereja and his friends went to a picnic. The guys had n soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles.
Sereja knows that the i-th bottle is from brand ai, besides, you can use it to open other bottles
of brand bi. You can use one bottle to open multiple other bottles. Sereja can open bottle with opened bottle or closed bottle.
Knowing this, Sereja wants to find out the number of bottles they've got that they won't be able to open in any way. Help him and find this number.
Input
The first line contains integer n(1 ≤ n ≤ 100) — the number of bottles. The next n lines
contain the bottles' description. The i-th line contains two integers ai, bi(1 ≤ ai, bi ≤ 1000)—
the description of the i-th bottle.
Output
In a single line print a single integer — the answer to the problem.
Sample Input
Input
4 1 1 2 2 3 3 4 4
Output
4
Input
41 2
2 3
3 44 1
Output
0
理解题意即可
/* Author: 2486 Memory: 812 KB Time: 60 MS Language: GNU G++ 4.9.2 Result: Accepted Public: No Yes */ #include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int maxn=1000+5; bool vd[maxn][maxn]; struct fs{ int a,b; }fss[maxn]; int main() { int b,n; scanf("%d",&n); memset(vd,false,sizeof(vd)); for(int i=1; i<=n; i++) { scanf("%d%d",&fss[i].a,&fss[i].b); vd[fss[i].b][fss[i].a]=true; } bool flag=true; int cnt=0; for(int i=1; i<=n; i++) { flag=false; for(int j=1; j<=n; j++) { if(i==j)continue; if(fss[i].a==fss[j].b) { flag=true; break; } } if(flag)cnt++; } printf("%d\n",n-cnt); return 0; }
相关文章推荐
- 微信公众平台开发
- 微信公众平台开发
- [codeforces-315D div2]模拟
- 自定义侧滑菜单
- jQuery 选择器
- onConfigurationChanged方法的使用
- 利用saltstack 部署lnmp环境(yum版本)
- 函数
- 推荐一个git辅助工具:TortoiseGit
- 使用keepalived搭建高可用的LVS-DR集群
- postgresql9.5 物化视图测试
- <input> 标签的 checked 属性
- [Android]实现简单的任务管理器(非root)
- 作业
- SQL中,WHERE HAVING的区别
- 只有小于65535端口编程可以用,查看哪些端口被打开netstat -anp,nc命令,nmap命令
- 只有小于65535端口编程可以用,查看哪些端口被打开netstat -anp,nc命令,nmap命令
- python excel操作
- Criteria Query—Hibernate之面向对象查询
- sublime ctags