A. Sereja and Bottles
来源:互联网 发布:用php写99乘法表思路 编辑:程序博客网 时间:2024/05/16 14:53
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.
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.
In a single line print a single integer — the answer to the problem.
41 12 23 34 4
4
41 22 33 44 1
0
解题说明:题目的意思虽然是开瓶盖,其实只需要保证每一行中这一对数不同即可,因为第一个瓶子无论是否打开都可以打开后一个瓶子。于是问题转变为判断一组数中,每一行中的一对数不同的个数,再用总数减去即为答案。
#include <iostream>#include<algorithm>#include<cstdio>#include<cmath>#include<cstring>#include<cstdlib>using namespace std;int main(){int an=0,n,y,i,j,k,x,a[1001],b[1001];scanf("%d",&n);for(i=0;i<n;i++){scanf("%d%d",&a[i],&b[i]);}for(i=0;i<n;i++){for(j=0;j<n;j++){if((a[i]==b[j])&&(i!=j)){an++;break;}}}printf("%d\n",n-an);return 0;}
- A. Sereja and Bottles
- CodeForces 315A Sereja and Bottles
- Sereja and Bottles
- Sereja and Bottles
- CF 315A(Sereja and Bottles-开易拉罐)
- Sereja and Bottles-水题有点坑爹
- A. Sereja and Dima
- A. Sereja and Mugs
- A. Sereja and Mugs
- A. Sereja and Coat Rack
- codeforces --A - Sereja and Algorithm
- A. Sereja and Prefixes----模拟
- Code Forces 380 A. Sereja and Prefixes
- CF 380A Sereja and Prefixes(二分)
- Codeforces 380 A. Sereja and Prefixes
- cf-381A-Sereja and Dima
- Codeforces 367A Sereja and Algorithm
- CodeForces 425A Sereja and Swaps
- Delphi for iOS开发指南(4):在iOS应用程序中使用不同风格的Button组件
- 编译android源码
- Delphi for iOS开发指南(5):在iOS应用程序中使用Calendar组件来选择日期
- Linux第一次安装,设置Root密码!
- Delphi for iOS开发指南(6):在iOS应用程序中使用ComboBox组件来从列表中选择某一项
- A. Sereja and Bottles
- Add-in Express for Office and .NET v7.3支持VS 2013预览
- Android平台的信息推送实现
- utu2440内核移植根文件移植配置nfs
- 4步windows下简单FTP服务器搭建(试验成功)
- Spring AOP概念理解
- Regional 2011, Asia - Kuala Lumpur 解题报告
- 关于php_apc的一个疑问
- Android源码编译 首发ViVo Xplay X510w 2.14.8 完美root/美颜相机/状态栏美化/支持官方OTA/纯净,稳定ROM