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

题目意思是第ai的瓶子能开bi的瓶子。给你相应的数据,求无法用其他瓶子打开的数量(即需要外力)。
一开始看错题了,以为是并查集。。。
AC代码:
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
using namespace std;
struct node
{
int a,b; //a能开b
} q[108];
bool cmp(node x,node y)
{
return x.a<y.a;
}
int w[108]; //标记第i个瓶子是否被开过
int main()
{
int n,i,j,sum;
while(~scanf("%d",&n) && n)
{
sum=0;
for(i=1; i<=n; i++)
{
scanf("%d%d",&q[i].a,&q[i].b);
}
sort(q+1,q+1+n,cmp);
memset(w,0,sizeof(w));
for(i=1; i<=n; i++)
{
for(j=1; j<=n; j++)
{
if(j != i && q[i].b==q[j].a && w[j] == 0)
{
sum++;
w[j]=1;
}
}
}
printf("%d\n",n-sum);
}
return 0;
}

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. html文件中文在浏览器中显示乱码问题解决

    利用浏览器打开html文件时,中文显示乱码,如下是原文件的内容 1 <html>   2         <head>   3             <title> ...

  2. android天气查询(一)websevice之ksoap2软件包的使用

    对于用到天气信息,首先我想: 第一:数据不可能是我测得的,必须是网上的信息. 第二:网上的信息分为好多种,具体哪种比较好一点,这里我总结了两种. 第三:数据JSON怎么解析. 第四:如何提出数据与显示 ...

  3. Hibernate 知识提高

    主键生成策略有: UUID,increment.Hilo.assigned:对数据库无依赖 identity:依赖Mysql或sql server,主键值不由hibernate维护 sequence: ...

  4. ADO.NET基础笔记

    ADO.NET 程序要和数据库交互要通过ADO.NET进行,通过ADO.Net就能在程序中执行SQL了. ADO.Net中提供了对各种不同的数据库的统一操作接口. 连接字符串: 程序通过连接字符串指定 ...

  5. 关于hibernate子查询参数的问题

    private Map<String, Object> createWblHqlContext(boolean needGroup, String startDate, String en ...

  6. HDU 1045(质因数分解)

    Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u   Description Tomor ...

  7. 设计模式值六大原则——接口隔离原则 (ISP)

    接口隔离原则 Interface Segregation Principle    定义: 客户端不应该依赖它不需要的接口 类间的依赖关系应该建立在最小的接口上 我们可以把这两个定义概括为一句话:建立 ...

  8. 模仿jquery的一些实现

    wylUtil.js //w作为window的形参,就表示window (function(w) { // 定义一个全局的window.wyl变量,就类似于jquery里的$,Jquery对象 w.w ...

  9. python第二步,类对象部分

    类创建: class 类名: '类说明' def __init__ (self,参数):#类似php类的构造函数,self不知道什么东东 方法体 实例创建: 变量名 = 类名() #构造函数后的参数, ...

  10. Windows 8.1 RTM初体验

    Windows 8.1正式发布在10月17日,现在可以在MSDN/TechNet进行订阅下载. 操作系统版本号和Windows Server 2012 R2保持一致. 开始屏幕动态磁贴现在有4种尺寸可 ...