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 ...
随机推荐
- java多线程下模拟抢票
我们设置三个对象分别同时抢20张票,利用多线程实现. public class Web123506 implements Runnable{ private int ticteksNums=20;// ...
- Golang 在 Linux CentOS 6.5 服务器上实现 博客后台程序开机启动
在linux下想实现开机启动的方法很多,这里我采用了在/etc/rc.local里写shell指令的方式. 以下就以我的实际操作为例子讲述,很多地方需要看官自己调整信息哦! 1.在/etc/rc.lo ...
- VECTOR中pair的排序
vector中pair的排序方法 首先定义一个vector vector<pair<int,char> >vec; 调用排序函数sort sort(vec.begin(),ve ...
- 16-6 WEB存储-通讯录实战
<!doctype html> <html> <head> <meta charset="utf-8"> <title> ...
- hdu 6011 Lotus and Characters 贪心
http://acm.hdu.edu.cn/showproblem.php?pid=6011 先把数字从小到大排好,比如是-6.3.4这样, 然后处理出后缀和,当后缀和 <= 0的时候马上停止就 ...
- Java操作pdf: JarsperReport的简单使用
在企业级应用开发中,报表生成.报表打印下载是其重要的一个环节.除了 Excel 报表之外,PDF 报表也有广泛的应用场景. 目前世面上比较流行的制作 PDF 报表的工具如下: iText PDF :i ...
- [BZOJ2002][Hnoi2010]Bounce弹飞绵羊 LCT
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2002 建图,每次往后面跳就往目标位置连边,将跳出界的点设为同一个点.对于修改操作发现可以用 ...
- shell编写的多服务器自动互信脚本(安装ceph)
相信大家都使用过分布式存储,而在分布式存储中较为出色的非ceph莫属了,但是这里就不深入聊ceph啦,我们只是聊聊安装ceph时遇到的问题. ceph需要多台主机进行ssh互信.三台还能忍受,但是当超 ...
- jmeter 连接 mysql 进行压力测试
- C# 移动开发 MasterDetailPage 侧滑
先上结果图: 虽然是跨平台的安卓和ios都可以运行,由于目前只配置了安卓的,ios的先不理. 我们先新建一个项目,跨平台应用: 可移植类库: 可移植项目右键添加新建项 选 Forms MasterDe ...