Forests
来源:互联网 发布:linux sublime tarbz2 编辑:程序博客网 时间:2024/05/16 01:24
1389. Forests
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 areTreatise Concerning the Principles of Human Knowledge (1710) and Three Dialogues between Hylas and Philonous (1713) (Philonous, the "lover of the mind," representing Berkeley himself).
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 areTreatise Concerning the Principles of Human Knowledge (1710) and Three Dialogues between Hylas and Philonous (1713) (Philonous, the "lover of the mind," representing Berkeley himself).
A forest contains T trees numbered from 1 to T and P people numbered from 1 toP. Standard input consists of a line containing P and T followed by several lines, containing a pair of integersi and j, indicating that person i has heard tree j fall. People may have different opinions as to which trees, according to Berkeley, have made a sound. 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 thatP < 100 and T < 100.
Sample Input
3 41 23 31 32 23 22 4
Output for Sample Input
2
题目解析:
一共3个人 4棵树其中第1个人认为第2和第3棵树倒了其中第2个人认为第2和第4棵树倒了其中第3个人认为第2和第3棵树倒了以上共有2种不同的看法,其中第1个人和第3个人的看法视为一致
刚看到题目的时候不知道怎么办,后来查阅了别人的代码后明白了,先定义一个二维数组num[][],初始化为0,输入一对i,j就把对应的num[i][j]置为1;然后通过判断数组中有几行不同的0,1组合来输出结果。
#include<iostream>#include<string>#include<stdio.h>#define N 100using namespace std;int main(){int i,j,P,T,num[N][N],count,flag;char s[30];while(cin>>P>>T){getchar();for(i=1;i<=P;i++)for(j=1;j<=T;j++)num[i][j]=0;while(gets(s)&&s[0]){sscanf(s,"%d %d",&i,&j);num[i][j]=1;}count=P; for(i=2;i<=P;i++) for(j=1;j<i;j++) { if(num[j][1]==-1) continue; flag=1; for(int k=1;k<=T;k++) if(num[i][k]!=num[j][k]) { flag=0;break;} if(flag) { count--; num[i][1]=-1; } }cout<<count<<endl;}system("pause");return 0;}
0 0
- Forests
- Random Forests
- random forests
- Random Forests
- Random forests, 随机森林,online random forests
- Random Forests原理
- [基础算法] Random Forests
- UVA 10227 - Forests
- poj 2419 Forests
- Random Forests原理
- UVa 10227 - Forests
- Forests of randomized trees
- Deep Neural Decision Forests
- Mahout Random Forests
- POJ 2419 Forests
- POJ 1268 Forests 笔记
- Random Forests in Python
- POJ 2419 Forests 笔记
- 一个奋斗十年的程序员从无到有买系5
- Redis性能调优:保存SNAPSHOT对性能的影响
- 选择排序
- mysql
- Spring Security3 页面 权限标签
- Forests
- iOS: 枚举类型 enum,NS_ENUM,NS_OPTIONS
- scala学习(二)
- Linux下Chrome标题栏中文乱码
- iPhone 6现身日本亚马逊 加尺寸不加重量
- sysfs接口函数DEVICE_ATTR和sysfs_create_group
- linux驱动摸索-- LCD显示(mini2440_T35)
- 关于ImageView定义数组,索引下标递增求余的原因分析
- MYSQL 存储引擎InnoDB与Myisam的六大区别