TOJ 2933 ZOJ 1589 Professor John / floyd
2013-11-13 18:15
351 查看
Professor John
时间限制(普通/Java):1000MS/3000MS 运行内存限制:65536KByte描述
Professor John is investigating a math problem. He has obtained some relations among several variables. Now he would like to know if there are any other relations that can be deduced
from these obtained ones. Since he has been working for too long, Professor John decides to grant himself a vacation while assigning you to do the job. Are you ready?
输入
The first line of input contains an integer N, which is the number of test cases. Then N test cases follow.
For each test case:
the 1st line contains a positive integer m (<= 100) which is the number of given relations;
the following m lines each contains a given relation, in the format
Variable1<Variable2
or
Variable1>Variable2
A "Variable" is represented by a capital character. There will not be conflicting relations given.
输出
For each test case, first print in one line "Case d:" where d is the number of the test case, start counting from 1.
Then output all the relations which can be deduced from the given relations in alphabetical order, in the format Variable1<Variable2. Each relation occupies one line. No extra space shall be printed. The given relations must NOT be included.
If no new relation is found, output "NONE" in one line.
样例输入
[code]2 3 A<strong c="">B C<D 2 A<B C<D </strong>
样例输出
[code]Case 1: A<C A<D B<D Case 2: NONE
floyd求传递闭包
#include<stdio.h> #include<string.h> #define inf 0x7fffffff const int MAX = 33; int a[MAX][MAX]; int flag[MAX][MAX]; void floyd() { int i,j,k; for(k = 1; k <= 30; k++) for(i = 1; i <= 30; i++) for(j = 1; j <= 30; j++) if(a[i][k] && a[k][j]) a[i][j] = 1; } int main() { char ss[5]; int t,i,m,j,f,cas = 1; scanf("%d",&t); while(t--) { f = 0; memset(a,0,sizeof(a)); memset(flag,0,sizeof(flag)); scanf("%d",&m); while(m--) { scanf("%s",ss); if(ss[1] == '<') { a[ss[0]-'A'+1][ss[2]-'A'+1] = 1; flag[ss[0]-'A'+1][ss[2]-'A'+1] = 1; } else { a[ss[2]-'A'+1][ss[0]-'A'+1] = 1; flag[ss[2]-'A'+1][ss[0]-'A'+1] = 1; } } floyd(); printf("Case %d:\n",cas++); for(i = 1;i <= 30; i++) for(j = 1;j <= 30; j++) if(a[i][j] && !flag[i][j]) { printf("%c<%c\n",i+'A'-1,j+'A'-1); f++; } if(!f) printf("NONE\n"); } return 0; }
相关文章推荐
- JQuery 选择器(锋利的Jquery)
- 【javascript 技巧】Array.prototype.slice的妙用
- js实现页面跳转的几种方式
- js实现页面跳转的几种方式
- js实现页面跳转的几种方式
- js实现页面跳转的几种方式
- 博客园样式排版自定义
- JAVA并发编程学习笔记之Unsafe类
- 源码剖析之sun.misc.Unsafe
- js checkbox的click事件,触发这个复选框的onchange事件的问题
- JavaScript逻辑运算符及优先级
- 浅析JavaScript中三个等号(===)和两个等号(==)的区别
- webstorm安装时遇到问题的解决方法
- ie8浏览器下,input框中的文字显示的位置不居中,解决方法
- ExtJs ButtonGroup按钮组
- extjs之Panel
- jQuery验证控件jquery.validate.js使用说明+中文API
- css:节点li中子元素浮动,即使固定高度,溢出隐藏,在ie6、7中仍有缝隙的解决办法
- Javascript Framework Scenario
- Authentication Error,status: 102 message: IP/SN/SCODE/REFERER Illegal:console-service