POJ 2419 Forests

来源:互联网 发布:网络工程施工费用 编辑:程序博客网 时间:2024/06/05 03:12

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 41 23 31 32 23 22 4

Sample Output

2

Source

Waterloo Local 2002.01.26
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

二进制~

(其实我也不知道该分为什么……明明就是大暴力嘛……

用两个long long记录每个人听见的树,然后暴力比对就可以了~

读入优化不可以用在EOF里面啊!


#include<cstdio>#include<iostream>#include<algorithm>using namespace std;#define ll long longint n,m,tot,x,y;ll a[101][2],num[101][2];bool flag;int read(){int x=0,f=1;char ch=getchar();while(ch<'0' || ch>'9') {if(ch=='-') f=-1;ch=getchar();}while(ch>='0' && ch<='9') {x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}return x*f; }int main(){n=read();m=read();while(scanf("%d",&x)!=EOF){y=read();y--;if(y<50) a[x][0]|=(1<<y);else a[x][1]|=(1<<(y-50));}for(int i=1;i<=n;i++){flag=0;for(int j=1;j<=tot;j++)  if(a[i][0]==num[j][0] && a[i][1]==num[j][1])  {flag=1;break;  }if(!flag) num[++tot][0]=a[i][0],num[tot][1]=a[i][1];}printf("%d\n",tot);return 0;}


1 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 六个月宝宝鼻塞怎么办速效办法 两个月小孩鼻子不通气怎么办 一岁宝宝流清鼻涕怎么办 孩子鼻子里有鼻涕怎么办 宝宝晚上睡觉鼻子不通气怎么办 宝宝感冒睡觉鼻子不通气怎么办 宝宝3个月流鼻涕怎么办 小孩吃着了发烧怎么办 半岁宝宝鼻子塞怎么办 宝宝伤风鼻子不通气怎么办 二十天的宝宝伤风鼻子不通怎么办 一个多月的宝宝鼻子有鼻屎怎么办 2个月宝宝鼻子里有鼻屎怎么办 四个月婴儿感冒发烧怎么办 一个月婴儿感冒发烧怎么办 五个月婴儿感冒发烧怎么办 两个月的婴儿感冒发烧怎么办 9个月婴儿感冒发烧怎么办 两个月婴儿感冒鼻塞咳嗽怎么办 两个月婴儿感冒咳嗽流鼻涕怎么办 小孩感冒发烧怎么办速效办法 宝宝打喷嚏流清鼻涕怎么办 宝宝感冒流清鼻涕怎么办 2岁感冒流清鼻涕怎么办 小孩感冒流清鼻涕怎么办 4岁宝宝半夜发烧怎么办 四岁宝宝免疫力低下怎么办 两岁宝宝咳嗽流鼻涕怎么办 小婴儿流清鼻涕怎么办 14个月宝宝流鼻涕怎么办 小孩一直流黄鼻涕怎么办 咳嗽有痰 浓鼻涕怎么办 儿童鼻窦炎总反复流脓鼻涕怎么办? 宝宝感冒咳嗽流黄鼻涕怎么办 哺乳期感冒流清鼻涕怎么办 哺乳期打喷嚏流清鼻涕怎么办 哺乳期妈妈感冒流清鼻涕怎么办 哺乳期严重流清鼻涕怎么办 小孩每天都是脓鼻涕怎么办 夏天小孩咳嗽流黄脓鼻涕怎么办? 受凉了流清鼻涕怎么办