hdu 4948 Kingdom(推论)
hdu 4948 Kingdom(推论)
题意:
题目问从一个城市u到一个新的城市v的必要条件是存在
以下两种路径之一
u --> v
u --> w -->v
询问任意一种能够走完整个地图所有点的访问序列
题解:
首先这道题必然有解,因为题目的条件
其次存在一个推论,对于每个子图而言,当前图入度最大的点距离每个点的距离不超过2,例如
u-->w-->t-->v
如果v是入度最大的点,必然存在一条u/w-->v的路径,往更长的路径进行推论也一样,因为结合上一个重要的条件(任意两点有一条路径),同样可以得到这个推论
import java.io.*;
import java.util.*;
public class hdu_4948 {
static class MyInputStream extends InputStream {
public BufferedInputStream bis = new BufferedInputStream(System.in);
public int read() throws IOException {
int i;
while ((i = bis.read()) < 48)
if (i == -1)
return -1;
int temp = 0;
while (i > 47) {
temp = temp * 10 + i - 48;
i = bis.read();
}
return temp;
}
}
static final int N = 510;
static int in[] = new int[N];
static int vis[] = new int[N];
static int ans[] = new int[N];
public static void main(String[] args){
Scanner cin=new Scanner(new InputStreamReader(System.in));
while (true) {
int n = cin.nextInt();
if (n == 0)
break;
String st;
Arrays.fill(in, 0,n+1,0);
for (int i = 1; i <= n; i++) {
st=cin.next();
for (int j = 0; j < n; j++) {
if(st.charAt(j)=='1')
in[j+1]++;
}
}
Arrays.fill(vis, 0, n + 1, 0);
int mx, w, cnt = n;
for (int i = 1; i <= n; i++) {
mx = 0;
w = 0;
for (int j = 1; j <= n; j++) {
if (mx <= in[j] && vis[j] == 0) {
mx = in[j];
w = j;
}
}
ans[cnt--] = w;
vis[w] = 1;
}
StringBuilder str = new StringBuilder("");
for (int i = 1; i <= n; i++) {
if (i > 1)
str.append(" ");
str.append("" + ans[i]);
}
System.out.println(str);
}
cin.close();
}
}
hdu 4948 Kingdom(推论)的更多相关文章
- 拓扑排序 --- hdu 4948 : Kingdom
Kingdom Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Sub ...
- HDU 5583 Kingdom of Black and White 水题
Kingdom of Black and White Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showpr ...
- HDU 5943 Kingdom of Obsession 【二分图匹配 匈牙利算法】 (2016年中国大学生程序设计竞赛(杭州))
Kingdom of Obsession Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Oth ...
- hdu 5943 Kingdom of Obsession 二分图匹配+素数定理
Kingdom of Obsession Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Oth ...
- hdu 5583 Kingdom of Black and White(模拟,技巧)
Problem Description In the Kingdom of Black and White (KBW), there are two kinds of frogs: black fro ...
- hdu 5583 Kingdom of Black and White
Kingdom of Black and White Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Ja ...
- HDU 5583 Kingdom of Black and White(暴力)
http://acm.hdu.edu.cn/showproblem.php?pid=5583 题意: 给出一个01串,现在对这串进行分组,连续相同的就分为一组,如果该组内有x个数,那么就对答案贡献x* ...
- HDU 4948 (傻比图论)
Kingdom Problem Description Teacher Mai has a kingdom consisting of n cities. He has planned the tra ...
- HDU 5943 Kingdom of Obsession
题意:n个人编号为[s+1, s+n],有n个座位编号为[1,n],编号为 i 的人只能坐到编号为它的约数的座位,问每个人是否都有位置坐. 题解:由于质数只能坐到1或者它本身的位置上,所以如果[n+1 ...
随机推荐
- PhpStorm Xdebug远程调试环境搭建原理分析及问题排查
2017年05月26日 经验心得 目录 一. 环境介绍 二. 远程环境配置 2.2 Xdebug安装 2.3 配置 三. 本地phpstorm配置 3.1 下载远程代码 3.2 添加php解释器 ...
- iOS Debug心得 (持续更新)
最近在维护一个内部比较混乱的APP,Debug的时候遇到很多比较痛苦的地方, 因此做一个Debug记录,对以后的开发会有比较大的帮助: 这样,在开发新项目的时候就可以争取把一些BUG扼杀在襁褓中. & ...
- python中字典的陷阱
把字典与列表组合,如 i=20 s=[]#定义一个空列表 b={'d':i}#定义一个字典 while i>0: i=i-1 b['d']=i#更新字典的值 s.append(b) print( ...
- 数据结构 - 静态单链表的实行(C语言)
静态单链表的实现 1 静态链表定义 静态链表存储结构的定义如下: /* 线性表的静态链表存储结构 */ #define MAXSIZE 1000 /* 假设链表的最大长度是1000 */ typede ...
- 数据结构 - 静态顺序线性表的实行(C语言)
数据结构 - 静态顺序线性表的实行(C语言) 1 获取元素操作 对于线性表的顺序存储结构来说,如果我们要实现GetElem操作,即将线性表L中的第i个位置元素值返回,其实是非常简单的. 只要i的数值在 ...
- [转]Business Model Canvas(商业模式画布):创业公司做头脑风暴和可行性测试的一大利器
本文转自:http://www.36kr.com/p/214438.html 本文来自First Round Review,他们准备的文章既讲故事,还同时向创业者提供可操作的建议,以助力打造优秀的公司 ...
- 关于表单清空的细节(reset函数或者class="reset"属性)
在需要清空的表单的情况下, 如果是在页面中 那么就添加属性 class="reset" 也即是 <button class="reset" value= ...
- AJPFX关于throw、throws关键字的解析
throw.throws关键字 throw关键字: 是用于方法体内部,用来抛出一个Throwable类型的异常.如果抛出了检查异常, 则还应该在方法头部声明方法可能抛出的异常类型.该方法的调用者也必须 ...
- 微软2017年预科生计划在线编程笔试 A Legendary Items
思路: 获得第i(i = 0, 1, ..., n - 1)件物品的概率仅由公式p / (1 << i)决定,所以获得这i件物品之间是相互独立的.迭代计算获得所有i件物品的期望再求和即可. ...
- vim设置默认显示行号
vim /root/.vimrc 设置在当前登录用户根目录下,.vimrc文件本身不存在,创建后之间添加下面配置保存即可 set number
