hdu 4948 Kingdom(推论)

传送门

题意:

题目问从一个城市u到一个新的城市v的必要条件是存在

以下两种路径之一

u --> v

u --> w -->v

询问任意一种能够走完整个地图所有点的访问序列

题解:

首先这道题必然有解,因为题目的条件

其次存在一个推论,对于每个子图而言,当前图入度最大的点距离每个点的距离不超过2,例如

u-->w-->t-->v

如果v是入度最大的点,必然存在一条u/w-->v的路径,往更长的路径进行推论也一样,因为结合上一个重要的条件(任意两点有一条路径),同样可以得到这个推论

  1. import java.io.*;
  2. import java.util.*;
  3. public class hdu_4948 {
  4. static class MyInputStream extends InputStream {
  5. public BufferedInputStream bis = new BufferedInputStream(System.in);
  6. public int read() throws IOException {
  7. int i;
  8. while ((i = bis.read()) < 48)
  9. if (i == -1)
  10. return -1;
  11. int temp = 0;
  12. while (i > 47) {
  13. temp = temp * 10 + i - 48;
  14. i = bis.read();
  15. }
  16. return temp;
  17. }
  18. }
  19. static final int N = 510;
  20. static int in[] = new int[N];
  21. static int vis[] = new int[N];
  22. static int ans[] = new int[N];
  23. public static void main(String[] args){
  24. Scanner cin=new Scanner(new InputStreamReader(System.in));
  25. while (true) {
  26. int n = cin.nextInt();
  27. if (n == 0)
  28. break;
  29. String st;
  30. Arrays.fill(in, 0,n+1,0);
  31. for (int i = 1; i <= n; i++) {
  32. st=cin.next();
  33. for (int j = 0; j < n; j++) {
  34. if(st.charAt(j)=='1')
  35. in[j+1]++;
  36. }
  37. }
  38. Arrays.fill(vis, 0, n + 1, 0);
  39. int mx, w, cnt = n;
  40. for (int i = 1; i <= n; i++) {
  41. mx = 0;
  42. w = 0;
  43. for (int j = 1; j <= n; j++) {
  44. if (mx <= in[j] && vis[j] == 0) {
  45. mx = in[j];
  46. w = j;
  47. }
  48. }
  49. ans[cnt--] = w;
  50. vis[w] = 1;
  51. }
  52. StringBuilder str = new StringBuilder("");
  53. for (int i = 1; i <= n; i++) {
  54. if (i > 1)
  55. str.append(" ");
  56. str.append("" + ans[i]);
  57. }
  58. System.out.println(str);
  59. }
  60. cin.close();
  61. }
  62. }

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. apicloud运行机制

    1 首先在官网apicloud中,创建项目生成config.xml文件,预设风格. 2 将config.xml文件放在项目跟目录中,Vue项目,必须先打包生产dist文件, 3 本地或者云编译(官方工 ...

  2. poj 3253 Fence Repair (水哈夫曼树)

    题目链接: http://poj.org/problem?id=3253 题目大意: 有一根木棍,需要截成n节,每节都有固定的长度,一根长度为x的木棒结成两段,需要花费为x,问截成需要的状态需要最小的 ...

  3. Word排版技巧

    点击打开链接 # 整体布局 ## 页面布局 如果是新建一个Word文件,这里「页面布局」一般不用设置了: 文字方向:从左到右: 页边距:普通(日常使用建议用适中或窄,节约用纸,提交的论文报告什么才用普 ...

  4. Service官方教程(1)Started与Bound的区别、要实现的函数、声明service

    Services 简介和分类 A Service is an application component that can perform long-running operations in the ...

  5. ubuntu14.04 + GTX980ti + cuda 8.0 ---Opencv3.1.0(基础+opecv_contrib)配置

    如果喜欢视频的话:YouTube 上有视频教程 https://www.youtube.com/watch?v=1YIAp3Lh5hI 后来我在mac上安装最新版的OpenCV 找到了一片非常详细的教 ...

  6. AJPFX关于throw、throws关键字的解析

    throw.throws关键字 throw关键字: 是用于方法体内部,用来抛出一个Throwable类型的异常.如果抛出了检查异常, 则还应该在方法头部声明方法可能抛出的异常类型.该方法的调用者也必须 ...

  7. 使用Jenkins进行android项目的自动构建(2)

    Maven and POM 1. 什么是Maven? 官方的解释是: http://maven.apache.org/guides/getting-started/index.html#What_is ...

  8. angular2快速开始

    简介 5 分钟从0搭建一个ng2项目demohttps://angular.io/docs/js/latest/quickstart.html 你运气真好,竟然看到了这篇文章,你省事了,一分钟让你完成 ...

  9. (转)淘淘商城系列——maven工程debug调试

    http://blog.csdn.net/yerenyuan_pku/article/details/72784074 上文我们已经实现了商品列表展示的功能,在实际开发中我们肯定是要经常对maven工 ...

  10. Swift protocol extension method is called instead of method implemented in subclass

    Swift protocol extension method is called instead of method implemented in subclass protocol MyProto ...