离散题目15
来源:互联网 发布:直播软件商业计划书 编辑:程序博客网 时间:2024/05/20 16:34
离散题目15
Time Limit: 1000MS Memory Limit: 65536KB
Problem Description
给出集合X、X上的关系R,判断关系R是不是传递的。
例如: A={1,2,3} , R={<1,1>,<1,2>,<2,1>,<3,3>,<2,3>,<3,2>, <2,2>,<1,3>,<3,1>} 显然,R具有传递性。
Input
多组输入,每组输入第一行为集合X的元素;第二行为一个整数n ( n > 0 ),代表X上的关系R中序偶的个数;接下来n行用来描述X上的关系R,每行两个数字,表示关系R中的一个序偶。细节参考示例输入。
非空集合X的元素个数不大于500,每个元素的绝对值不大于2^32 - 1。
Output
每组输入对应一行输出,如果关系R具有传递性输出 ”true”,否则输出 ”yes”。
Example Input
1 2 391 12 23 31 22 11 33 12 33 21 2 361 11 23 32 33 22 2
Example Output
trueyes
#include <bits/stdc++.h>using namespace std;struct node{ int x; int y;}q[110001];set<int> s;string cc;bool input(){ s.clear(); string si; if(!getline(cin,si)) return false; stringstream ss(si); int t; while(ss>>t) { s.insert(t); } return true;}int main(){ int i,j; int n,m; while(input())//这个函数看得我眼前一亮 因吹斯挺 { int flag=1; cin>>n; for(i=0;i<n;i++) { scanf("%d %d", &q[i].x, &q[i].y); if(s.count(q[i].x)==0||s.count(q[i].y)==0) flag=0; } if(flag) { for(i=0;i<n;i++) { for(j=0;j<n;j++) { if(q[i].y==q[j].x) { int judge_f=0; for(int k=0;k<n;k++) { if(q[k].x==q[i].x&&q[k].y==q[j].y) //传递定义 { judge_f=1; break; } } if(judge_f==0) { flag=0; break; } } }if(flag==0) break; } } if(flag==1) printf("true\n"); else printf("yes\n"); getline(cin,cc); } return 0;}
阅读全文
0 0
- 离散题目15
- 离散题目15
- 离散题目15
- 离散题目15
- 离散题目15
- 离散题目15
- sdut-离散题目15
- 离散题目15
- SDUT 3809 离散题目15
- 离散题目3
- 离散题目7
- sdut离散题目11
- sdut离散题目13
- sdut离散题目14
- 离散题目12
- 3799-->离散题目5
- 3800-->离散题目6
- 离散题目1
- Unity自定义组件之(五) 目录树 UITree
- 一点关于cookie的知识
- 逻辑运算
- 之江学院2017ACM 校赛Problem G qwb去面试
- mysql中文乱码问题
- 离散题目15
- Win32 Socket select模型
- JPA Spring-Data-JPA hibernate mybatis
- caffe中solver.prototxt参数说明
- Android DataBinding使用总结(五)结合MultiType展示多类型列表
- JAVA初涉反射
- Ubuntu下安装QQ国际版
- WebBrowser与IE的关系,如何设置WebBrowser工作在IE9、10、11模式下?
- 真是该警觉了