hdu 4324 Triangle LOVE(拓扑判环)
Triangle LOVE
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 3603 Accepted Submission(s): 1416
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”.
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). Ai,j = 1 means i-th people loves j-th people, otherwise Ai,j = 0.
It is guaranteed that the given relationship is a tournament, that is, Ai,i= 0, Ai,j ≠ Aj,i(1<=i, j<=n,i≠j).
Take the sample output for more details.
2
5
00100
10000
01001
11101
11000
5
01111
00000
01000
01100
01110
Case #1: Yes Case #2: No 输入一个矩阵,假设a[i][j]==1,意思是i喜欢j。问存不存在一个三角恋关系,
既拓扑排序判环,,要深入理解拓扑排序的原理
2015,8,14#include<stdio.h>
#include<string.h>
#define M 2100
char mp[M][M];
int du[M];
int n,cas;
void topo(){
int ok=0,i,k;
for(int i=1;i<=n;i++){
for(k=1;k<=n;k++)
if(du[k]==0) //z找到入度为0的点
break;
if(k==n+1){//假设不存在入度为0的点。那么就是一定存在环 ,就有三角恋
ok=1;
break;
}else{
du[k]--;//删除这个点
for(int j=1;j<=n;j++){
if(mp[k][j]=='1'&&du[j]!=0)
du[j]--;
}
}
}
if(ok) printf("Case #%d: Yes\n",cas++);
else printf("Case #%d: No\n",cas++);
}
int main(){
int i,j,t;
cas=1;
scanf("%d",&t);
while(t--){
memset(du,0,sizeof(du));
scanf("%d",&n);
for(i=1;i<=n;i++){//依照凝视的输入会超时
//getchar();
scanf("%s",mp[i]+1);;
for(j=1;j<=n;j++){
// scanf("%c",&mp[i][j]);
if(mp[i][j]=='1')
du[j]++;
}
}
topo();
}
return 0;
}
hdu 4324 Triangle LOVE(拓扑判环)的更多相关文章
- HDU 4324 Triangle LOVE 拓扑排序
Problem Description Recently, scientists find that there is love between any of two people. For exam ...
- E. Andrew and Taxi(二分+拓扑判环)
题目链接:http://codeforces.com/contest/1100/problem/E 题目大意:给你n和m,n代表有n个城市,m代表有m条边,然后m行输入三个数,起点,终点,花费.,每一 ...
- HDU 4324 Triangle LOVE (拓扑排序)
Triangle LOVE Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Tot ...
- hdu 4324 Triangle LOVE
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4324 Triangle LOVE Description Recently, scientists f ...
- HDU - 4324 Triangle LOVE(拓扑排序)
https://vjudge.net/problem/HDU-4324 题意 每组数据一个n表示n个人,接下n*n的矩阵表示这些人之间的关系,输入一定满足若A不喜欢B则B一定喜欢A,且不会出现A和B相 ...
- HDU 4324 Triangle LOVE【拓扑排序】
题意:给出n个人,如果a喜欢b,那么b一定不喜欢a,如果b不喜欢a,那么a一定喜欢b 就是这n个点里面的任意两点都存在一条单向的边, 所以如果这n个点不能构成拓扑序列的话,就一定成环了,成环的话就一定 ...
- hdu 4324 Triangle LOVE(拓扑排序,基础)
题目 /***************************参考自****************************/ http://www.cnblogs.com/newpanderking ...
- Coloring Edges 【拓扑判环】
题目链接:https://vjudge.net/contest/330119#problem/A 题目大意: 1.给出一张有向图,给该图涂色,要求同一个环里的边不可以全部都为同一种颜色.问最少需要多少 ...
- 【建图+拓扑判环】BZOJ3953: [WF2013]Self-Assembly
Description 自动化学制造(Automatic Chemical Manufacturing,简称ACM)正在对一个叫自组装(self-assembly)的过程进行实验.在这个过程中,有着天 ...
随机推荐
- 路飞学城-Python开发-第三章
# 数据结构: # goods = [ # {"name": "电脑", "price": 1999}, # {"name&quo ...
- Python中编写精美图形界面(PyQt5)
纯代码,布局的讲解 见: https://cloud.tencent.com/developer/article/1345469 Qt designer设计文件 .ui转 .py文件,进阶使用 注:不 ...
- java 获取config 配置文件
static ResourceBundle PropertiesUtil = ResourceBundle.getBundle("config"); public static S ...
- 洛谷 P4147 玉蟾宫 (最大子矩形问题)
这道题用到了悬线法,非常牛逼,可以看这个论文. https://blog.csdn.net/twtsa/article/details/8120269 #include<cstdio> # ...
- Lock-less buffer management scheme for telecommunication network applications
A buffer management mechanism in a multi-core processor for use on a modem in a telecommunications n ...
- vjudge A - Beautiful numbers
A - Beautiful numbers Volodya is an odd boy and his taste is strange as well. It seems to him that a ...
- RPC架构
RPC架构 学习了: https://www.cnblogs.com/ChrisMurphy/p/6550184.html RPC架构简介,有一个Java例子: http://blog.csdn.ne ...
- 纯CSS实现小圆点和三角形图案
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...
- Java常用知识(长期更新)
1.0转义符 \n:换行 ,\n的作用和print后面的ln相同,可酌情使用 \t:一个制表位(一系列空格) 例: public class Schedule{ public static void ...
- Android项目实战(五十七):Glide 高斯模糊效果
核心需要高斯模糊的库 compile 'jp.wasabeef:glide-transformations:2.0.1' 针对于3.7的版本 使用方法为: //加载背景, Glide.with(Mus ...