Triangle LOVE

Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/65536K (Java/Other)
Total Submission(s) : 40   Accepted Submission(s) : 27
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
 
Author
BJTU
 
Source
2012 Multi-University Training Contest 3


#include<stdio.h>
#include<string.h>
char map[2010][2010];
int dre[2010];
int main()
{
int t,cot=0;
scanf("%d",&t);
while(t--)
{
int n,i,j,p;
//memset(map,0,sizeof(map));
scanf("%d",&n);
memset(dre,0,sizeof(dre));
getchar();
for(i=0;i<n;i++)
{
scanf("%s",&map[i]);
getchar();
for(j=0;j<n;j++)
if(map[i][j]=='1')
dre[j]++;
}
for(i=0;i<n;i++)
{
p=-1;
for(j=0;j<n;j++)
{
if(dre[j]==0)
{
dre[j]--;
p=j;
break;
}
}
if(p==-1)
break;
for(j=0;j<n;j++)
{
if(map[p][j]=='1')
{
dre[j]--;
map[p][j]='0';
}
}
}
printf("Case #%d: ",++cot);
if(i<n)
{
printf("Yes\n");
}
else
printf("No\n");
}
}

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

  1. Triangle LOVE(拓扑排序)

    Triangle LOVE Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/65536K (Java/Other) Total ...

  2. HDU 4324 Triangle LOVE 拓扑排序

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

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

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

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

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

  5. HDU4324 Triangle LOVE【拓扑排序】

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

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

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

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

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

  8. hdu4324 Triangle LOVE (拓扑排序)

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

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

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

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

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

随机推荐

  1. Bootstrap中container与container-fluid的区别

    /*0-768px以上宽度container为100%*/ .container { padding-right: 15px; padding-left: 15px; margin-right: au ...

  2. 我和CSDN的那些事

    作者:朱金灿 来源:http://blog.csdn.net/clever101 前些日子收到这样一个邀请: CSDN的工作人员还来电给我确认是否能参加.开始我有点犹豫,毕竟是在工作日的晚上,毕竟离我 ...

  3. 【sqli-labs】 less26 GET- Error based -All you SPACES and COMMENTS belong to us(GET型基于错误的去除了空格和注释的注入)

    看了下源码 所有的注释形式和反斜线,and,or都被了过滤掉了 单引号没有过滤 空格也被过滤了 http://localhost/sqli-labs-master/Less-26/?id=1' htt ...

  4. c# 读取 XML

    XmlDocument xmldoc = new XmlDocument(); string xmlPath = HttpContext.Server.MapPath("~/*****.xm ...

  5. Maven服务器的使用之Maven桌面项目和Maven Web项目的创建

    Maven的使用 Maven功能强大, 可以参与管理软件的整个生命周期. Java软件开发中的jar包管理更是Maven的绝技. 1.创建Maven桌面项目 1.1 选择菜单创建Maven项目 1.2 ...

  6. C# --MVC实现简单上传下载

    首先创建一个默认的控制器Defaultcontroller 然后生成视图View 在视图里面 创建文件选择器 创建上传.下载按钮 代码如下 <body> <div> <f ...

  7. webpack学习(二)

    时下很火的react项目多用到webpack+ES6,本文只实践webpack的打包功能,不涉及react. 1.新建项目 新建的项目,命令模式下切换到项目根路径,用npm init命令生成packa ...

  8. PAT_A1116#Come on! Let's C

    Source: PAT A1116 Come on! Let's C (20 分) Description: "Let's C" is a popular and fun prog ...

  9. 15.3 Task 语法和语义

    15.3.1 声明异步方法和返回类型 async static void GetStringAsync() { using (var client = new HttpClient()) { Task ...

  10. Mysql入门详解

    目录 数据库之Mysql 一 .简单了解数据库 二.Mysql的使用 三.多表查询 数据库之Mysql 本篇文章为观看某教学视频后所作个人总结 一 .简单了解数据库 1.1常见关系型数据库 mysql ...