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. 省市区县的sql语句——城市

    /*SQLyog v10.2 MySQL - 5.5.48 : Database - 省市县****************************************************** ...

  2. node post和get请求原理

    重要:GET和POST请求他们都是上行请求,都是把数据从浏览器带向服务器的方式, GET 请求实际上就是识别URL中的querystring部分POST请求,一般用来发送大量的内容,此时node非常害 ...

  3. 通用功能类:改变WinForm窗体显示颜色

    一.显示窗体调用方法 protected override void OnLoad(EventArgs e)        {            MDIClientSupport.SetBevel ...

  4. HDU_5810_数学,概率,方差

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5810 大意:将n个球往m个盒子中投,每个球被投入每个盒子的概率相等,求方差. 看题解说,这是二项分布( ...

  5. webpack学习(六)—webpack+react+es6(第2篇)

    接上篇        webpack学习(五)—webpack+react+es6(第1篇) 本文做个简单的图片加文字的页面.其中,配置文件跟上篇一致.项目结构: index.html <!DO ...

  6. sql server time(7) 默认值

    语句为 ALTER TABLE dbo.YourTable ADD CONSTRAINT DF_TimeDefault DEFAULT '00:00:00' FOR YourTimeColumn 比如 ...

  7. Linux direct io使用例子

    Linux direct io使用 在linux 2.6内核上使用direct io不难,只需按照如下几点来做即可: 1,在open文件时加上O_DIRECT旗标,这样以通告内核我们想对该文件进行直接 ...

  8. 关于vcruntime140D.dll丢失问题

    电脑磁盘占用率100%,又检测出硬盘磁道坏了,要么装win7,要么换个SSD,无奈重装环境. 遇到这个问题,之前的电脑就遇到过,网上交的下载这个文件装到C盘Windows的SysWOW64,对于实验室 ...

  9. RF学习使用记录【4】

    四 Extending Robot Framework 4.1 Creating test libraries RF的测试能力由测试库支持决定,已经有许多的测试库,有一些随着RF框架安装,但是更多的需 ...

  10. echarts在地图上绘制散点图(任意点)

    项目需求:在省份地图上绘制散点图,散点位置不一定是哪个城市或哪个区县,即任意点 通过查询官网文档,找到一个与需求类似的Demo:https://www.echartsjs.com/gallery/ed ...