11175-From D to E and Back(思维)
Accept: 164 Submit: 607
Time Limit: 3000 mSec
Problem Description
Take any directed graph D with n vertices and m edges. You can make the Lying graph E of B in the following way. E will have m vertices, one for each edge of D. For example, if D has an edge uv, then E will have a vertex called uv. Now, whenever D has edges uv and vw, E will have an edge from vertex uv to vertex vw. There are no other edges in E. You will be given a graph E and will have to determine whether it is possible for E to be the Lying graph of some directed graph D.
Input
The first line of input gives the number of cases, N (N < 220). N test cases follow. Each one starts with two lines containing m (0 ≤ m ≤ 300) and k. The next k lines will each contain a pair of vertices, x and y, meaning that there is an edge from x to y in E. The vertices are numbered from 0 to m−1
Output
Sample Input
Sample Output
Case #1: Yes
Case #2: Yes
Case #3: No
Case #4: Yes
题解:这种结论题真的是做不来。首先第一感觉是这怎么会不存在呢,然后样例三强势打脸,但是感觉上不成立的情况应该很少,但是少到何种程度完全没有认识,最后思来想去还是看了题解,题解都是千篇一律的结论,并且没有人证明那是充要的,至多证明是必要的,做这个题就当涨见识了。
#include <bits/stdc++.h> using namespace std; const int maxn = + ;
int gra[maxn][maxn]; int m, t; int read() {
int q = ;
char ch = ' ';
while (ch<'' || ch>'') ch = getchar();
while ('' <= ch && ch <= '') {
q = q * + ch - '';
ch = getchar();
}
return q;
} bool solve() {
for (int i = ; i < m; i++) {
for (int j = ; j < m; j++) {
int f1 = , f2 = ;
for (int k = ; k < m; k++) {
if (gra[i][k] && gra[j][k]) f1 = ;
if (gra[i][k] ^ gra[j][k]) f2 = ;
if (f1 && f2) return false;
}
}
}
return true;
} int T = ; int main()
{
int iCase;
iCase = read();
while (iCase--) {
memset(gra, , sizeof(gra));
m = read(), t = read();
int u, v;
for (int i = ; i < t; i++) {
u = read(), v = read();
gra[u][v] = ;
} printf("Case #%d: ",T++);
if (solve()) printf("Yes\n");
else printf("No\n");
}
return ;
}
11175-From D to E and Back(思维)的更多相关文章
- [C#][算法] 用菜鸟的思维学习算法 -- 马桶排序、冒泡排序和快速排序
用菜鸟的思维学习算法 -- 马桶排序.冒泡排序和快速排序 [博主]反骨仔 [来源]http://www.cnblogs.com/liqingwen/p/4994261.html 目录 马桶排序(令人 ...
- Photoshop、Illustrator思维导图笔记
半年前学习Photoshop时记得的思维导图笔记,可能不是很全,常用的基本都记下了.
- CYQ.Data 从入门到放弃ORM系列:开篇:自动化框架编程思维
前言: 随着CYQ.Data 开始回归免费使用之后,发现用户的情绪越来越激动,为了保持这持续的激动性,让我有了开源的念头. 同时,由于框架经过这5-6年来的不断演进,以前发的早期教程已经太落后了,包括 ...
- 计算机程序的思维逻辑 (8) - char的真正含义
看似简单的char 通过前两节,我们应该对字符和文本的编码和乱码有了一个清晰的认识,但前两节都是与编程语言无关的,我们还是不知道怎么在程序中处理字符和文本. 本节讨论在Java中进行字符处理的基础 - ...
- 计算机程序的思维逻辑 (29) - 剖析String
上节介绍了单个字符的封装类Character,本节介绍字符串类.字符串操作大概是计算机程序中最常见的操作了,Java中表示字符串的类是String,本节就来详细介绍String. 字符串的基本使用是比 ...
- 计算机程序的思维逻辑 (31) - 剖析Arrays
数组是存储多个同类型元素的基本数据结构,数组中的元素在内存连续存放,可以通过数组下标直接定位任意元素,相比我们在后续章节介绍的其他容器,效率非常高. 数组操作是计算机程序中的常见基本操作,Java中有 ...
- 计算机程序的思维逻辑 (33) - Joda-Time
Joda-Time上节介绍了JDK API中的日期和时间类,我们提到了JDK API的一些不足,并提到,实践中有一个广泛使用的日期和时间类库,Joda-Time,本节我们就来介绍Joda-Time.俗 ...
- 计算机程序的思维逻辑 (53) - 剖析Collections - 算法
之前几节介绍了各种具体容器类和抽象容器类,上节我们提到,Java中有一个类Collections,提供了很多针对容器接口的通用功能,这些功能都是以静态方法的方式提供的. 都有哪些功能呢?大概可以分为两 ...
- 成吨提高开发效率:Intellij Shortcuts精简子集与思维模式
在线精简cheatsheet备查表:intellij.linesh.twGithub项目:intellij-mac-frequent-keymap Intellij的快捷键多而繁杂,从官方推荐的key ...
- "Becoming Functional" 阅读笔记+思维导图
<Becoming Functional>是O'Reilly公司今年(2014)7月发布的一本薄薄的小册子,151页,介绍了函数式编程的基本概念.全书使用代码范例都是基于JVM的编程语言, ...
随机推荐
- GitHub:我们是这样弃用jQuery的
摘要: 技术债清理流程指南. 原文:Removing jQuery from GitHub.com frontend 译文:GitHub:我们为什么会弃用jQuery? 作者:GitHub 前端工程团 ...
- canvas-7global.html
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- html/css的学习之路(2)
今天我跟大家说一下html,html里面其实什么东西都可以放进去的.首先创建一个文本,改变他的后缀名为html.这时有个最重要的一点不管是html还是css都不可以用中文和符号命名. 这是html中的 ...
- 从换脸到换姿势,AI 在图像处理的道路上越走越魔幻
从换脸到换姿势,AI 在图像处理的道路上越走越魔幻 https://mp.weixin.qq.com/s/VFq3BWLpzyKZ3sqVWf1HKA [导读]加州大学伯克利分校的研究人员,近日在著名 ...
- iOS ----------要学习的地方(链接整理)
1.http://www.cocoachina.com/special/xcode/ 2.http://blog.csdn.net/a416863220/article/details/4111387 ...
- Android调用系统图库返回路径
调用系统图库: Intent intent = new Intent(Intent.ACTION_PICK,MediaStore.Images.Media.EXTERNAL_CONTENT_URI); ...
- Implemented the “Importance Sampling of Reflections from Hair Fibers”
Just the indirect specular pass by importance sampling. With all layers. Manually traced by 3D Ham ...
- ReactNative调研结果
React Native相关调研总结 一.概要 React Native - 使用React开发世界一流的原生应用: 使用JavaScript和React(对JS有一定扩展)作为开发语言: React ...
- Android内存优化(一)Dalvik虚拟机和ART虚拟机对比
1.概述 Android4.4以上开始使用ART虚拟机,在此之前我们一直使用的Dalvik虚拟机,那么为什么Google突然换了Android运行的虚拟机呢?答案只有一个:ART虚拟机更优秀. 2.D ...
- DAY9(PYTHON)
li=[{'usename':'xiaowang'}, {'} ] board=['张三','李四','王大麻子'] while 1: usename = input('用户名:') if usena ...