http://codeforces.com/problemset/problem/315/A

题目意思是第ai的瓶子能开bi的瓶子。给你相应的数据,求无法用其他瓶子打开的数量(即需要外力)。
一开始看错题了,以为是并查集。。。
AC代码:
  1. #include<iostream>
  2. #include<cstring>
  3. #include<algorithm>
  4. #include<cstdio>
  5. using namespace std;
  6. struct node
  7. {
  8. int a,b; //a能开b
  9. } q[108];
  10. bool cmp(node x,node y)
  11. {
  12. return x.a<y.a;
  13. }
  14. int w[108]; //标记第i个瓶子是否被开过
  15. int main()
  16. {
  17. int n,i,j,sum;
  18. while(~scanf("%d",&n) && n)
  19. {
  20. sum=0;
  21. for(i=1; i<=n; i++)
  22. {
  23. scanf("%d%d",&q[i].a,&q[i].b);
  24. }
  25. sort(q+1,q+1+n,cmp);
  26. memset(w,0,sizeof(w));
  27. for(i=1; i<=n; i++)
  28. {
  29. for(j=1; j<=n; j++)
  30. {
  31. if(j != i && q[i].b==q[j].a && w[j] == 0)
  32. {
  33. sum++;
  34. w[j]=1;
  35. }
  36. }
  37. }
  38. printf("%d\n",n-sum);
  39. }
  40. return 0;
  41. }

Sereja and Bottles的更多相关文章

  1. codeforces A. Sereja and Bottles 解题报告

    题目链接:http://codeforces.com/problemset/problem/315/A 题目意思:有n个soda bottles,随后给出这n个soda bottles的信息.已知第 ...

  2. Sereja and Bottles-水题有点坑爹

    CodeForces - 315A Sereja and Bottles Time Limit: 2000MS   Memory Limit: 262144KB   64bit IO Format:  ...

  3. JSU 2013 Summer Individual Ranking Contest - 5

    JSU 2013 Summer Individual Ranking Contest - 5 密码:本套题选题权归JSU所有,需要密码请联系(http://blog.csdn.net/yew1eb). ...

  4. java线程大全一讲通

    Java线程:概念与原理 一.操作系统中线程和进程的概念 现在的操作系统是多任务操作系统.多线程是实现多任务的一种方式. 进程是指一个内存中运行的应用程序,每个进程都有自己独立的一块内存空间,一个进程 ...

  5. ACM团队周赛题解(1)

    这次周赛题目拉了CF315和CF349两套题. 因为我代码模板较长,便只放出关键代码部分 #define ll long long #define MMT(s,a) memset(s, a, size ...

  6. Codeforces Round #187 (Div. 1 + Div. 2)

    A. Sereja and Bottles 模拟. B. Sereja and Array 维护全局增量\(Y\),对于操作1(即\(a_{v_i}=x\))操作,改为\(a_{v_i}=x-Y\). ...

  7. CF380C. Sereja and Brackets[线段树 区间合并]

    C. Sereja and Brackets time limit per test 1 second memory limit per test 256 megabytes input standa ...

  8. CF 672C Recycling Bottles[最优次优 贪心]

    C. Recycling Bottles time limit per test 2 seconds memory limit per test 256 megabytes input standar ...

  9. Codeforces Round #352 (Div. 2) C. Recycling Bottles 贪心

    C. Recycling Bottles   It was recycling day in Kekoland. To celebrate it Adil and Bera went to Centr ...

随机推荐

  1. NHibernate 的 ID 标识选择器

    在 Hibernate 中,每个对象需要一个标识 ID,通过这个标识 ID 建立对象与数据库中记录的对应关系. Nhibernate 提供了多种方式来建立这个 POID.基于不同的生成策略,可以选择更 ...

  2. HDU 1398 Square Coins

    题目大意:有面值分别为.1,4,9,.......17^2的硬币无数多个.问你组成面值为n的钱的方法数. 最简单的母函数模板题: #include <cstdio> #include &l ...

  3. HDU题解索引

    HDU 1000 A + B Problem  I/O HDU 1001 Sum Problem  数学 HDU 1002 A + B Problem II  高精度加法 HDU 1003 Maxsu ...

  4. 什么是Thrift

    起源 百度百科怎么说 thrift是一个软件框架,用来进行可扩展且跨语言的服务的开发. 它结合了功能强大的软件堆栈和代码生成引擎,以构建在 C++, Java, Python, PHP, Ruby, ...

  5. 【cocos2d-x】Win7下配置Cocos2d-x开发环境

    一.下载安装包 先去Cocos2d-x官网下载安装包,最新版本为cocos2d-2.1.5 http://www.cocos2d-x.org/news/134 二.解压安装包 下载完成后,解压文件,解 ...

  6. Ext JS学习第十天 Ext基础之 扩展原生的javascript对象(二)

    此文来记录学习笔记: 今天继续说Ext.Array,Ext.Function,Ext.Date,Ext.Error ------------------------------------------ ...

  7. document.execCommand()函数可用参数解析

    隐藏在暗处的方法-execCommand() 关键字: javascript document document.execCommand()方法可用来执行很多我们无法实现的操作. execComman ...

  8. 常用类库StringBuilder

    1.使用StringBuilder拼接字符串实例: string[] lines = File.ReadAllLines("sdjk.txt", Encoding.Default) ...

  9. C++创建对象的三种方式

    C++在创建对象的时候,有三种方式: #include <iostream> using namespace std; class A { private: int n; public: ...

  10. Shell Script(1)----variable compare

    PS:在学习python的时间里,抽空复习自己学习的Linux下的shell脚本知识点 1.数据类型 学习一门语言,比较关心其数据的表示方式,以及数据的类型,这里首先看一个bash shell的脚本 ...