Triangle LOVE

Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/65536K (Java/Other)
Total Submission(s) : 49   Accepted Submission(s) : 30
Problem Description
Recently, scientists find that there is love between any of two people. For example, between A and B, if A don’t love B, then B must love A, vice versa. And there is no possibility that two people love each other, what a crazy world!
Now, scientists want to know whether or not there is a “Triangle Love” among N people. “Triangle Love” means that among any three people (A,B and C) , A loves B, B loves C and C loves A.
  Your problem is writing a program to read the relationship among N people firstly, and return whether or not there is a “Triangle Love”.
 
Input
The first line contains a single integer t (1 <= t <= 15), the number of test cases. For each case, the first line contains one integer N (0 < N <= 2000). In the next N lines contain the adjacency matrix A of the relationship (without spaces). A[sub]i,j[/sub] = 1 means i-th people loves j-th people, otherwise A[sub]i,j[/sub] = 0. It is guaranteed that the given relationship is a tournament, that is, A[sub]i,i[/sub]= 0, A[sub]i,j[/sub] ≠ A[sub]j,i[/sub](1<=i, j<=n,i≠j).
 
Output
For each case, output the case number as shown and then print “Yes”, if there is a “Triangle Love” among these N people, otherwise print “No”. Take the sample output for more details.
 
Sample Input
2 5 00100 10000 01001 11101 11000 5 01111 00000 01000 01100 01110
 
Sample Output
Case #1: Yes Case #2: No
代码:
 

 #include<stdio.h>
#include<string.h>
#include<queue>
using namespace std;
const int MAXN=;
int map[MAXN][MAXN];
int que[MAXN],flot,N,tot=;
char c[MAXN][MAXN];
queue<int>dl;
void topsort(){
for(int i=;i<=N;i++)
if(!que[i])dl.push(i);
//printf("%d",dl.size());
//puts("asfaf");
while(!dl.empty()){
int k=dl.front();
flot++;
dl.pop();
que[k]=-;
// printf("%d",dl.size());
for(int j=;j<=N;j++){
if(map[k][j])que[j]--;
if(!que[j])dl.push(j);
}
}
// puts("asfaf");
if(flot==N)printf("Case #%d: No\n",tot);
else printf("Case #%d: Yes\n",tot);
}
void initial(){
memset(que,,sizeof(que));
while(!dl.empty()){
dl.pop();
}
flot=;
}
int main(){
int T;
scanf("%d",&T);
while(T--){
tot++;
initial();
scanf("%d",&N);
//puts("asfaf");
//printf("%d\n",N);
for(int i=;i<N;i++)scanf("%s",c[i]);
for(int i=;i<=N;i++){
for(int j=;j<=N;j++){
map[i][j]=c[i-][j-]-'';
if(map[i][j])que[j]++;
}
}
// puts("asfaf");
/* for(int i=1;i<=N;i++){
for(int j=1;j<=N;j++){
printf("%d",map[i][j]);
}
puts("");
}*/
//puts("asfaf");
topsort();
}
return ;
}

Triangle LOVE(拓扑排序)的更多相关文章

  1. HDU 4324 Triangle LOVE 拓扑排序

    Problem Description Recently, scientists find that there is love between any of two people. For exam ...

  2. hdoj 4324 Triangle LOVE【拓扑排序判断是否存在环】

    Triangle LOVE Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Tot ...

  3. HDU 4324 Triangle LOVE (拓扑排序)

    Triangle LOVE Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Tot ...

  4. HDU4324 Triangle LOVE【拓扑排序】

    Triangle LOVE Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) To ...

  5. HDU 4324 (拓扑排序) Triangle LOVE

    因为题目说了,两个人之间总有一个人喜欢另一个人,而且不会有两个人互相喜欢.所以只要所给的图中有一个环,那么一定存在一个三元环. 所以用拓扑排序判断一下图中是否有环就行了. #include <c ...

  6. hdu 4324 Triangle LOVE(拓扑排序,基础)

    题目 /***************************参考自****************************/ http://www.cnblogs.com/newpanderking ...

  7. hdu4324 Triangle LOVE (拓扑排序)

    这是一道最简单的拓扑排序题,好久没看这个算法了! 有点生疏了! 后附上百度的资料; #include<stdio.h> #include<string.h> int in[50 ...

  8. HDU - 4324 Triangle LOVE(拓扑排序)

    https://vjudge.net/problem/HDU-4324 题意 每组数据一个n表示n个人,接下n*n的矩阵表示这些人之间的关系,输入一定满足若A不喜欢B则B一定喜欢A,且不会出现A和B相 ...

  9. 拓扑排序/DFS HDOJ 4324 Triangle LOVE

    题目传送门 题意:判三角恋(三元环).如果A喜欢B,那么B一定不喜欢A,任意两人一定有关系连接 分析:正解应该是拓扑排序判环,如果有环,一定是三元环,证明. DFS:从任意一点开始搜索,搜索过的点标记 ...

随机推荐

  1. Web常用函数介绍(LoadRunner相关)

    介绍大纲:1. web_url2. web_image3. web_link4. web_submmit_form 详细介绍: 一. web_url web_url 语法: Int Web_url(c ...

  2. WorkFlow4.0--入门到精通系列-专题索引

    原文地址:http://www.cnblogs.com/hegezhou_hot/archive/2011/06/15/2081405.html 开篇 首先.非常感谢大家的支持和厚爱,才有了这个系列, ...

  3. 2.2.2 胸腰差和胸臀差的应用_米人NOONE_新浪博客

    2.2.2  胸腰差和胸臀差的应用_米人NOONE_新浪博客 腰差和胸臀差的应用(2009-06-16 19:24:57)转载▼标签:校园         前面已经对这两个概念作了简单的讲解.这两个概 ...

  4. Z.Studio高级成衣定制(双井店)价格,地址(图)-北京-大众点评网

    Z.Studio高级成衣定制(双井店)价格,地址(图)-北京-大众点评网 Z.Studio高级成衣定制(双井店)

  5. 【剑指offer】连续子数组的最大和

    个開始,到第3个为止).你会不会被他忽悠住? 输入: 输入有多组数据,每组測试数据包括两行. 第一行为一个整数n(0<=n<=100000),当n=0时,输入结束.接下去的一行包括n个整数 ...

  6. 演示如何通过 web api 上传文件MVC40

    演示如何通过 web api 上传文件WebApiWebFormHost/UploadFileController.cs /* * 通过 web api 上传文件 */ using System; u ...

  7. 动态代理双剑客--JDK Proxy与CGLIB

    背景: 研究过设计模式的同胞们都知道代理模式可以有两种实现方案: 1.接口实现(或继承抽象类) 核心代码片段 ProxySubject-->>doOperation() //dosomet ...

  8. 模块化的JavaScript

    我们再一次被计算机的名词,概念笼罩. backbone.emberjs.spinejs.batmanjs 等MVC框架侵袭而来. CommonJS.AMD.NodeJS.RequireJS.SeaJS ...

  9. 字符串聚合技术(String Aggregation Techniques)

    from: http://www.oracle-base.com/articles/misc/string-aggregation-techniques.php String Aggregation ...

  10. 【2012noip提高组】借教室

    在大学期间,经常需要租借教室.大到院系举办活动,小到学习小组自习讨论,都需要 向学校申请借教室.教室的大小功能不同,借教室人的身份不同,借教室的手续也不一样. 面对海量租借教室的信息,我们自然希望编程 ...