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. Amzon MWS API开发之 上传数据

    亚马逊上传数据,现有能操作的功能有很多:库存数量.跟踪号.价格.商品....... 我们可以设置FeedType值,根据需要,再上传对应的xml文件即可. 下面可以看看FeedType类型 这次我们拿 ...

  2. 在 Inno Setup 中实现倒数N秒后激活按钮

    原文 http://restools.hanzify.org/article.asp?id=67 timectrl.dll 为一个 6.5 KB 的按钮激活时间控制插件.  引用来自 Example1 ...

  3. cf452A Eevee

    A. Eevee time limit per test 1 second memory limit per test 256 megabytes input standard input outpu ...

  4. SonarQube代码质量管理平台工具

    1.Sonar轮廓介绍 Sonar (SonarQube)是一个开源平台,用于管理源代码的质量.Sonar 不只是一个质量数据报告工具,更是代码质量管理平台.支持的语言包括:Java.PHP.C#.C ...

  5. [Leetcode][Python]46: Permutations

    # -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 46: Permutationshttps://leetcode.com/pr ...

  6. linux之SQL语句简明教程

    本教程参考http://www.1keydata.com/cn/sql/ 目的是让初学者了解linux下Mysql的操作,但是我仍想侧重于SQL语句的讲解 sql语句的学习将按照下图的流程: 当然在这 ...

  7. 蜂窝移动网络是什么,它和 Wi-Fi 有什么区别? 蓝牙和无线有什么区别?

    蜂窝移动网络是什么,它和 Wi-Fi 有什么区别? 转自知乎用户的一个回答: 原题问的是"数据流量是什么",不知道怎么又被改成"蜂窝移动网络是什么"了.说下个人 ...

  8. HDU2054_A == B ?【模拟题】【大数】【水的问题】

    A == B ? Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total S ...

  9. Oracle日志文件常用操作

    Oracle关于日志文件基本操作1.查询系统使用的是哪一组日志文件:select * from v$log; 2.查询正在使用的组所对应的日志文件:select * from v$logfile; 3 ...

  10. android Handler更新UI

    android中经常需要更新界面某个元素的值,但是在主线程中是不可以直接更新主线程的值.这里推荐通过handler机制来更新值. 一Handler的定义: 主要接受子线程发送的数据, 并用此数据配合主 ...