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(推论)的更多相关文章

  1. 拓扑排序 --- hdu 4948 : Kingdom

    Kingdom Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Sub ...

  2. 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 ...

  3. HDU 5943 Kingdom of Obsession 【二分图匹配 匈牙利算法】 (2016年中国大学生程序设计竞赛(杭州))

    Kingdom of Obsession Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Oth ...

  4. hdu 5943 Kingdom of Obsession 二分图匹配+素数定理

    Kingdom of Obsession Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Oth ...

  5. 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 ...

  6. 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 ...

  7. HDU 5583 Kingdom of Black and White(暴力)

    http://acm.hdu.edu.cn/showproblem.php?pid=5583 题意: 给出一个01串,现在对这串进行分组,连续相同的就分为一组,如果该组内有x个数,那么就对答案贡献x* ...

  8. HDU 4948 (傻比图论)

    Kingdom Problem Description Teacher Mai has a kingdom consisting of n cities. He has planned the tra ...

  9. HDU 5943 Kingdom of Obsession

    题意:n个人编号为[s+1, s+n],有n个座位编号为[1,n],编号为 i 的人只能坐到编号为它的约数的座位,问每个人是否都有位置坐. 题解:由于质数只能坐到1或者它本身的位置上,所以如果[n+1 ...

随机推荐

  1. git提交报错SSL routines:SSL23_GET_SERVER_HELLO:tlsv1 alert protocol version

    git push报错 git push origin master Administrator@FREESKYC-92DB80 /e/git/ouyida3/ouyida3.github.io (ma ...

  2. 关于数学函数中的abs——————————————杭电2057——————————————————————————

    数学函数中的abs当你用abs之后括号之中的数字就转换成了int格式.可能会丢失一些数据造成误差而且还会有,    警告: #include<stdio.h> #include<ma ...

  3. (二)python高级特性

    一.切片 >>> L = ['Michael', 'Sarah', 'Tracy', 'Bob', 'Jack'] 对这种经常取指定索引范围的操作,用循环十分繁琐,因此,Python ...

  4. 找规律/贪心 Codeforces Round #310 (Div. 2) A. Case of the Zeros and Ones

    题目传送门 /* 找规律/贪心:ans = n - 01匹配的总数,水 */ #include <cstdio> #include <iostream> #include &l ...

  5. mac下 netbeans 8.02中文版设置代码自动补齐 + eclipse自动补齐

    netbeans自带的自动补齐快捷键是commad+\ 我想要的是在输入的时候,有自动提示,找了半天也没找到怎么搞. 因为我是用的mac系统 后来参考其他的设置,找到了设置的方法,把这个方法记录一下. ...

  6. jmeter(十六)Jmeter之Bean shell使用(一)

    一.什么是Bean Shell BeanShell是一种完全符合Java语法规范的脚本语言,并且又拥有自己的一些语法和方法; BeanShell是一种松散类型的脚本语言(这点和JS类似); BeanS ...

  7. [转]Php MySql Class

    本文转自:http://www.cnblogs.com/noevil/archive/2010/11/06/1870864.html <?php /**  * 数据库操作类  *  * @aut ...

  8. 可以装一把——c#中手动添加控件

    TextBox txt = new TextBox(); //文本框控件 //如果想在移动控件位置 point(x,y) txt.Location = new Point(50,50); this.C ...

  9. SQL SERVER 事务例子

    存储过程格式: CREATE PROCEDURE YourProcedure AS BEGIN SET NOCOUNT ON; BEGIN TRY---------------------开始捕捉异常 ...

  10. 关于.Net中Process的使用方法和各种用途汇总(二):用Process启动cmd.exe完成将cs编译成dll

    上一章博客我为大家介绍了Process类的所有基本使用方法,这一章博客我来为大家做一个小扩展,来熟悉一下Process类的实际使用,废话不多说我们开始演示. 先看看我们的软件要设计成的布局吧. 首先我 ...