Triangle LOVE(拓扑排序)
Triangle LOVE
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/65536K (Java/Other)
Total Submission(s) : 40 Accepted Submission(s) : 27
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”.
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).
2
5
00100
10000
01001
11101
11000
5
01111
00000
01000
01100
01110
Case #1: Yes
Case #2: No
#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(拓扑排序)的更多相关文章
- Triangle LOVE(拓扑排序)
Triangle LOVE Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/65536K (Java/Other) Total ...
- HDU 4324 Triangle LOVE 拓扑排序
Problem Description Recently, scientists find that there is love between any of two people. For exam ...
- hdoj 4324 Triangle LOVE【拓扑排序判断是否存在环】
Triangle LOVE Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Tot ...
- HDU 4324 Triangle LOVE (拓扑排序)
Triangle LOVE Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Tot ...
- HDU4324 Triangle LOVE【拓扑排序】
Triangle LOVE Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) To ...
- HDU 4324 (拓扑排序) Triangle LOVE
因为题目说了,两个人之间总有一个人喜欢另一个人,而且不会有两个人互相喜欢.所以只要所给的图中有一个环,那么一定存在一个三元环. 所以用拓扑排序判断一下图中是否有环就行了. #include <c ...
- hdu 4324 Triangle LOVE(拓扑排序,基础)
题目 /***************************参考自****************************/ http://www.cnblogs.com/newpanderking ...
- hdu4324 Triangle LOVE (拓扑排序)
这是一道最简单的拓扑排序题,好久没看这个算法了! 有点生疏了! 后附上百度的资料; #include<stdio.h> #include<string.h> int in[50 ...
- HDU - 4324 Triangle LOVE(拓扑排序)
https://vjudge.net/problem/HDU-4324 题意 每组数据一个n表示n个人,接下n*n的矩阵表示这些人之间的关系,输入一定满足若A不喜欢B则B一定喜欢A,且不会出现A和B相 ...
- 拓扑排序/DFS HDOJ 4324 Triangle LOVE
题目传送门 题意:判三角恋(三元环).如果A喜欢B,那么B一定不喜欢A,任意两人一定有关系连接 分析:正解应该是拓扑排序判环,如果有环,一定是三元环,证明. DFS:从任意一点开始搜索,搜索过的点标记 ...
随机推荐
- HTML+CSS(11)
n CSS背景属性 Background-color:背景色. Background-image:背景图片地址.如:background-image:url(images/bg.gif;) Back ...
- Leetcode0037--Sudoku Solver 数独游戏
[转载请注明]http://www.cnblogs.com/igoslly/p/8719622.html 来看一下题目: Write a program to solve a Sudoku puzzl ...
- windows下安装Python-Whl文件
原文链接:http://blog.sciencenet.cn/home.php?mod=space&uid=1181151&do=blog&id=865515 Note1. 整 ...
- mvc自定义控件
//自定义一个DatePicker.cshtml文件@helper Init() { <link href="~/Content/mobiscroll.custom-2.5.0.min ...
- POJ_2063_完全背包
Investment Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 10090 Accepted: 3540 Descr ...
- 关于DataGridViewComboBoxColumn的二三事
近日开发一个基于WinForm的工具,用到了DataGridViewComboBoxColumn. 关于数据: DataGridView的数据源是代码生成的DataTable DataGridView ...
- PAT_A1148#Werewolf - Simple Version
Source: PAT 1148 Werewolf - Simple Version (20 分) Description: Werewolf(狼人杀) is a game in which the ...
- Java 8 集合不完全一览
JDK 8 List 名称 线程安全 数据结构 允许 null 默认初始容量 扩容策略 备注 ArrayList 不安全 数组 允许 10 1.5 * old LinkedList 不安全 双链表 允 ...
- [luogu4026 SHOI2008]循环的债务 (DP)
传送门 吐槽洛谷难度标签qwq Solution 显然是一道神奇的DP,由于总钱数不变,我们只需要枚举前两个人的钱数就可知第三个人的钱数 DP的时候先枚举只用前k个币种,然后枚举前两个人的钱数,然后枚 ...
- Flask中的session操作
一.配置SECRET_KEY 因为flask的session是通过加密之后放到了cookie中.所以有加密就有密钥用于解密,所以,只要用到了flask的session模块就一定要配置“SECRET_K ...