Forests
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 5782   Accepted: 2218

Description

If a tree falls in the forest, and there's nobody there to hear, does it make a sound? This classic conundrum was coined by George Berkeley (1685-1753), the Bishop and influential Irish philosopher whose primary philosophical achievement is the advancement of what has come to be called subjective idealism. He wrote a number of works, of which the most widely-read are Treatise Concerning the Principles of Human Knowledge (1710) and Three Dialogues between Hylas and Philonous (1713) (Philonous, the "lover of the mind," representing Berkeley himself).

Input

A forest contains T trees numbered from 1 to T and P people numbered from 1 to P. Standard input consists of a line containing P and T followed by several lines, containing a pair of integers i and j, indicating that person i has heard tree j fall.

Output

People may have different opinions as to which trees, according to Berkeley, have made a sound. Output how many different opinions are represented in the input? Two people hold the same opinion only if they hear exactly the same set of trees. You may assume that P < 100 and T < 100.

Sample Input

3 4
1 2
3 3
1 3
2 2
3 2
2 4

Sample Output

2

Source

 #include<stdio.h>
#include<set>
#include<string.h>
using namespace std; set <int> a[] ;
bool flag [] ;
int t , p ;
//set <int> :: iterator it ;迭代器 int main ()
{
//freopen ("a.txt" , "r" , stdin ) ;
memset (flag , , sizeof(flag) ) ;
scanf ("%d%d" , &t , &p ) ;
int i , j ;
int cnt = ;
while (~ scanf ("%d%d" , &i , &j) ) {
a[i].insert (j) ;
}
for (int i = ; i < p ; i++) {
if (flag[i] == ) {
flag[i] = ;
for (int j = i + ; j <= p ; j++) {
if (a[i] == a[j]) {
flag [j] = ;
}
}
cnt ++ ;
}
}
printf ("%d\n" , cnt ) ;
return ;
}

从师兄们那学来的orz ,首先知道了如何把set中的元素输出:

set <int> ::iterator it ;

for (it = a.begin () ; it <= a.end () ; i++ )

  printf ("%d " , *it ) ;

----------接下来是如何判断两个set集合相等----------

简单粗暴orz:

set <int> a , b ;

if (a == b) {

  puts ("Yes") ;

}

else {
  puts ("No") ;

}

poj.2419.Forests (枚举 + set用法)的更多相关文章

  1. POJ 2419 Forests(模拟)

    题目链接: https://cn.vjudge.net/problem/POJ-2419 题目描述: If a tree falls in the forest, and there's nobody ...

  2. poj 1873 凸包+枚举

    The Fortified Forest Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 6198   Accepted: 1 ...

  3. C++枚举类型Enum及C++11强枚举类型用法

    C++中的枚举类型常常和switch配合使用,这里用一个简单的switch控制键盘回调的代码片段来说明枚举的用法: //W A S D 前.后.左.右行走 enum Keydown{ Forward= ...

  4. Java enum(枚举)的用法详解(转)

    用法一:常量 在JDK1.5 之前,我们定义常量都是: public static fianl.... .现在好了,有了枚举,可以把相关的常量分组到一个枚举类型里,而且枚举提供了比常量更多的方法. p ...

  5. poj 1106 Transmitters (枚举+叉积运用)

    题目链接:http://poj.org/problem?id=1106 算法思路:由于圆心和半径都确定,又是180度,这里枚举过一点的直径,求出这个直径的一个在圆上的端点,就可以用叉积的大于,等于,小 ...

  6. POJ 1018 【枚举+剪枝】.cpp

    题意: 给出n个工厂的产品参数带宽b和价格p,在这n个工厂里分别选1件产品共n件,使B/P最小,其中B表示n件产品中最小的b值,P表示n件产品p值的和. 输入 iCase n 表示iCase个样例n个 ...

  7. (转载)C# 枚举 FlagsAttribute用法

    这是读过几篇文章后发现整理的最完整的一篇文章 转载地址:枚举特性FlagsAttribute的用法 先看官方的解释:指示可以将枚举作为位域(即一组标志)处理. 看起来并不好理解,到底什么是作为位域处理 ...

  8. C# 枚举基本用法及扩展方法

    没什么好说的,都是些基础! 代码如下: using System; using System.Collections.Generic; using System.ComponentModel; usi ...

  9. Java ENUM枚举的用法

    DK1.5引入了新的类型——枚举.在 Java 中它虽然算个“小”功能,却给我的开发带来了“大”方便. 用法一:常量 在JDK1.5 之前,我们定义常量都是: publicstaticfianl... ...

随机推荐

  1. 慢牛系列四:好玩的React Native

    在上次随笔(系列三)中,我试着用RN实现了一个Demo,感觉很不错,当时遇到的问题这篇文章里基本都解决了,比如导航动画问题,这篇文章里主要介绍RN的动画,学会动画以后,各种小创意都可以实现了^^ 下面 ...

  2. WP8.1&Win10开发:TextBox获取和失去焦点小技巧

    获取焦点:用Focus方法让Textbox获取焦点.代码示例:textbox.Focus(FocusState.Pointer); 失去焦点:让其他控件获取焦点,如Textblock控件(注意要将Te ...

  3. grootJs的属性绑定指令

    index6.html 绑定文本text gt-text="{属性名}" 绑定标签属性attr gt-attr="vm属性名称(标签属性,value表达式)" ...

  4. CocoaPods Podfile 文件写法有讲究

    最近做到一些项目想到用 OC/Swift混编的问题.为了搞懂 bridge header 这个文件是咋个情况.却一致报错.最后不知不觉发现问题问题居然出在 Podfile 上. 开始我是从 IT 江湖 ...

  5. ncp的简单实用

    'use strict';//这是一个简单的应用var Promise = require('bluebird');var ncp = require('ncp').ncp;var fs = requ ...

  6. Linq之Expression高级篇(常用表达式类型)

    目录 写在前面 系列文章 变量表达式 常量表达式 条件表达式 赋值表达式 二元运算符表达式 一元运算符表达式 循环表达式 块表达式 总结 写在前面 首先回顾一下上篇文章的内容,上篇文章介绍了表达式树的 ...

  7. java日期处理总结

    Java日期时间使用总结   一.Java中的日期概述   日期在Java中是一块非常复杂的内容,对于一个日期在不同的语言国别环境中,日期的国际化,日期和时间之间的转换,日期的加减运算,日期的展示格式 ...

  8. 警告: [SetContextPropertiesRule]{Context} Setting property 'source' to 'org.eclipse.jst.jee.server:CurrencyClientServe

    有的说: 在Servers视图里双击创建的server,然后在其server的配置界面中选中"Publish module contexts to separate XML files&qu ...

  9. 【HDU 2955】Robberies(DP)

    题意是给你抢劫每个银行可获得的钱m和被抓的概率p,求被抓的概率小于P,最多能抢多少钱.01背包问题,体积是m,价值是p.被抓的概率不是简单相加,而应该是1−Π(1−p[i])DP:dp[i]表示抢到i ...

  10. Day4_计算器

    read me 1.构造三个函数,乘除(mad),加减(aas),去括号(par): 2.获取表达式字符串之后,判断是否包含“+-*/()”等字符,包含则下一步3:不包含,返回字符串: 3.par 函 ...