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. [Django 1.5] jQuery/Ajax 在Django使用 ,如何更新模板里里变量

    最近希望实现一个页面局部刷新的功能,于是开始查阅ajax资料.幸好现在ajax很多功能都封装在jQuery这个库里面,我们可以很方便去调用.通过学习几个简单的小例子,可以实现简单的前端代码更新,还有重 ...

  2. GPS功能:百度路书自定义【轨迹回放】

    如题所述:百度的编辑界面很直观,修改后就可以运行,地址:http://developer.baidu.com/map/jsdemo.htm#c2_8: 因为同事研究了一下午结果都没搞出来,他copy百 ...

  3. [Leetcode][Python]45: Jump Game II

    # -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 45: Jump Game IIhttps://oj.leetcode.com ...

  4. hdu 5623 KK's Number(dp)

    问题描述 我们可爱的KK有一个有趣的数学游戏:这个游戏需要两个人,有N\left(1\leq N\leq 5*{10}^{4} \right)N(1≤N≤5∗10​4​​)个数,每次KK都会先拿数.每 ...

  5. 小黑小波比.coding的使用

    1_Coding的演示 1_html的演示 1_先查看帮助 1.它支持的语言非常多.下面是链接地址 https://coding.net/u/bobo159357456/p/html/paas/hel ...

  6. Android开发中目前流行控件和知识点总结

    Android开发中目前流行控件和知识点总结   1.SlidingMenu 滑动菜单 应用案例:Facebook . Path 2.0 .人人.网易新闻 下载地址: https://github.c ...

  7. 自己动手写处理器之第四阶段(1)——第一条指令ori的实现

    将陆续上传本人写的新书<自己动手写处理器>(尚未出版),今天是第11篇,我尽量每周四篇 第4章 第一条指令ori的实现 前面几章介绍了非常多预备知识,也描绘了即将要实现的OpenMIPS处 ...

  8. ZCTF-ARM64-Re300

    Re300-arm64     是一个64位的ARM程序.使用IDA加载,蹦出来这个框框,就是说IDA6.6还没有对ARM64位的程序实现relocation的分析.     就是由于这个,所以连对l ...

  9. Apache Lens —— 统计数据分析查询接口

    Lens 提供了一个统一数据分析接口.通过提供一个跨多个数据存储的单一视图来实现数据分析任务切分,同时优化了执行的环境.无缝的集成 Hadoop 实现类似传统数据仓库的功能. 该项目主要特性: 简单元 ...

  10. 基本文件的I/O

    System.IO命名空间包含允许在数据流和文件上进行同步,异步及写入的类型.文件是一些永久存储及具有特定顺序的字节组成的一个有序的,具有名称的集合.与文件有关的概念是目录路径和磁盘存储等.流提供了一 ...