离散题目17
来源:互联网 发布:rar解压软件下载 编辑:程序博客网 时间:2024/05/29 02:21
离散题目17
Time Limit: 1000MS Memory Limit: 65536KB
Submit Statistic
Problem Description
给出集合X和X上的关系R,求关系R在X上的对称闭包s(R)。
例如:
X={1,2,3,4,5} , R={<1,1>,<2,1>,<3,3>,<2,3>,<3,2>,<4,5>}
s(R)= {<1,1>,<1,2>,<2,1>,<2,3>,<3,2>,<3,3>,<4,5>,<5,4>}
Input
多组输入,每组输入第一行为集合X的元素;第二行为一个整数n ( n > 0 ),代表X上的关系R中序偶的个数;接下来n行用来描述X上的关系R,每行两个数字,表示关系R中的一个序偶。细节参考示例输入。
非空集合X的元素个数不大于500,每个元素的绝对值不大于2^32 - 1。
Output
每组输入对应一行输出,为X上关系R的对称闭包s(R),s(R)中的序偶根据序偶中的第一个值升序排列,如果第一个值相同则根据第二个值升序排列;具体输出格式见样例(注意:样例每个逗号后有一个空格)。
Example Input
1 2 3 4 5
6
1 1
2 1
3 3
2 3
3 2
4 5
Example Output
[(1, 1), (1, 2), (2, 1), (2, 3), (3, 2), (3, 2), (3, 3), (4, 5), (5, 4)]
#include <iostream>#include <cstring>#include <cstdio>#include <algorithm>using namespace std;struct node{ int x,y;}a[1000010];bool cmp(struct node q,struct node w){ if (q.x != w.x){ return q.x < w.x; } return q.y < w.y;}int main(){ char s[1111000]; int n,aa,bb; while(gets(s)){ scanf("%d",&n); int xx=0; for (int i=0;i<n;i++){ scanf("%d%d",&aa,&bb); if (aa==bb){ a[xx].x=aa; a[xx++].y=bb; } else{ a[xx].x=aa; a[xx++].y=bb; a[xx].x=bb; a[xx++].y=aa; } } sort(a,a+xx,cmp); for(int i=0;i<xx;i++){ if (i==0){ printf("[(%d, %d)",a[i].x,a[i].y); } else { printf(", (%d, %d)",a[i].x,a[i].y); } } printf("]\n"); gets(s); } return 0;}
阅读全文
0 0
- 离散题目17
- 离散题目17
- 离散题目17
- 离散题目17
- 离散题目17
- SDUT-离散题目17
- 3811-->>离散题目17
- SDUT 3811 离散题目17
- 离散题目17--求对称闭包
- 离散题目17 对称闭包
- 离散题目3
- 离散题目7
- sdut离散题目11
- sdut离散题目13
- sdut离散题目14
- 离散题目12
- 离散题目15
- 3799-->离散题目5
- Burn the Linked Camp 【区间 差分约束】
- uml系列(五)——对象图和包图
- Handler实现的打地鼠游戏
- Magic Numbers CodeForces
- 机器学习+周志华+第五章习题+解决异或问题的单层RBF神经网络
- 离散题目17
- synchronized
- Android view的单击,双击,长按事件监听
- jquery效果总结
- hadoop 性能调优与运维
- [BZOJ 2142]礼物:扩展Lucas定理
- Spring学习记录—容器后处理器和Bean后处理器
- url的三个js编码函数escape(),encodeURI(),encodeURIComponent()简介
- POJ3009