链接:



Horror List

Time Limit: 1000ms
Memory Limit: 65536KB
 

64-bit integer IO format: 
%lld      Java class name: 
Main
Font Size: 
+  
-
Type:  
None
 
Graph Theory
 
    2-SAT
 
    Articulation/Bridge/Biconnected Component
 
    Cycles/Topological Sorting/Strongly Connected Component
 
    Shortest Path
 
        Bellman Ford
 
        Dijkstra/Floyd Warshall
 
    Euler Trail/Circuit
 
    Heavy-Light Decomposition
 
    Minimum Spanning Tree
 
    Stable Marriage Problem
 
    Trees
 
    Directed Minimum Spanning Tree
 
    Flow/Matching
 
        Graph Matching
 
            Bipartite Matching
 
            Hopcroft–Karp Bipartite Matching
 
            Weighted Bipartite Matching/Hungarian Algorithm
 
        Flow
 
            Max Flow/Min Cut
 
            Min Cost Max Flow
 
DFS-like
 
    Backtracking with Pruning/Branch and Bound
 
    Basic Recursion
 
    IDA* Search
 
    Parsing/Grammar
 
    Breadth First Search/Depth First Search
 
    Advanced Search Techniques
 
        Binary Search/Bisection
 
        Ternary Search
 
Geometry
 
    Basic Geometry
 
    Computational Geometry
 
    Convex Hull
 
    Pick's Theorem
 
Game Theory
 
    Green Hackenbush/Colon Principle/Fusion Principle
 
    Nim
 
    Sprague-Grundy Number
 
Matrix
 
    Gaussian Elimination
 
    Matrix Exponentiation
 
Data Structures
 
    Basic Data Structures
 
    Binary Indexed Tree
 
    Binary Search Tree
 
    Hashing
 
    Orthogonal Range Search
 
    Range Minimum Query/Lowest Common Ancestor
 
    Segment Tree/Interval Tree
 
    Trie Tree
 
    Sorting
 
    Disjoint Set
 
String
 
    Aho Corasick
 
    Knuth-Morris-Pratt
 
    Suffix Array/Suffix Tree
 
Math
 
    Basic Math
 
    Big Integer Arithmetic
 
    Number Theory
 
        Chinese Remainder Theorem
 
        Extended Euclid
 
        Inclusion/Exclusion
 
        Modular Arithmetic
 
    Combinatorics
 
        Group Theory/Burnside's lemma
 
        Counting
 
    Probability/Expected Value
 
Others
 
    Tricky
 
    Hardest
 
    Unusual
 
    Brute Force
 
    Implementation
 
    Constructive Algorithms
 
    Two Pointer
 
    Bitmask
 
    Beginner
 
    Discrete Logarithm/Shank's Baby-step Giant-step Algorithm
 
    Greedy
 
    Divide and Conquer
 
Dynamic Programming

Tag it!

It was time for the 7th Nordic Cinema Popcorn Convention, and this year the manager Ian had a brilliant idea. In addition to the traditional film program, there would be a surprise room where a small group of people could stream a random movie from a large collection, while enjoying popcorn and martinis.

However, it turned out that some people were extremely disappointed, because they got to see movies like Ghosts of Mars, which instead caused them to tear out their hair in despair and horror.

To avoid this problem for the next convention, Ian has come up with a solution, but he needs your help to implement it. When the group enters the surprise room, they will type in a list of movies in a computer. This is the so-called horror list, which consists of bad movies that no one in the group would ever like to see. Of course, this list varies from group to group.

You also have access to the database Awesome Comparison of Movieswhich tells you which movies are directly similar to which. You can assume that movies that are similar to bad movies will be almost as bad. More specificly, we define the Horror index as follows:

Input

The first line of input contains three positive integers

N
,

H
,

L
 (

1≤H<N≤1000,0≤L≤10000
), where

N
 is the number of movies (represented by IDs, ranging from

0
 to

N−1
),

H
 is the number of movies on the horror list and

L
 is the number of similarities in the database.

The second line contains

H
 unique space-separated integers

xi
 (

0≤xi

<
N
) denoting the ID of the movies on the horror list.

The following

L
 lines contains two space-separated integers

ai

,
b
i
 (

0≤ai

<
b
i
<
N
), denoting that movie with ID

ai
 is similar to movie with ID

bi
 (and vice verca).

 
 

Output

Output the ID of the best movie in the collection (highest Horror Index). In case of a tie, output the movie with the lowest ID.

 

Sample Input

  1. 6 3 5
  2. 0 5 2
  3. 0 1
  4. 1 2
  5. 4 5
  6. 3 5
  7. 0 2
 

Sample Output

  1. 1
 

Source



算法:最短路 =_= !




题意+思路:


我等英语弱菜实在是伤不起Orz

有 N 场电影【编号从 0 到 N-1】 背景懒得写了,说出来都是泪。。。
大致意思就是给你一张表上面有 H 个恐怖电影的标号。
然后给你  L  对关系,a, b 表示 a 和 b 相似。。。。【注意关系是双向的,也就意味着是个无向图】

然后题目的关键来了


根据上图中的公式,求出每个电影的恐怖值。。。

PS:最终你会发现,最恐怖的电影的价值应该是 0, 最不恐怖的反而尽量大。。。这一点很容易搞反。

第一行 HI = 0 :表示在恐怖表中的电影,恐怖值均为 0 ,而且不会被其他的关系定义覆盖。【相当于以这些电影为起点】

第二行 HI = Q+1:如果和当前电影类似的最恐怖的电影的恐怖值是 Q ,那么当前电影的 HI = Q+1 

                            【相当于起点到当前电影的最小距离】

第三行 HI = INF :如果当前电影不和任何电影相似。【表示是孤立的点,最不恐怖的电影】

一般的大多是正常人,为了不把自己吓的抓狂,当然是选择不怎么恐怖的电影看了,这里为了尽量满足大多数人的需求,当然是选择最不恐怖的电影了。如果恐怖度一样,就选择编号最小的电影。

那么题目就转化成了求 HI 最大的,电影编号,如果有多个一样,则输出最小的。PS:如果有INF的,当然直接输出最小的编号就over了

相当于以恐怖名单上的电影编号为起点,d[index] = 0; 如果 index 出现在恐怖名单上【样例中的第二行】

然后每一个点【电影】为终点,求出起点集合到终点的最短距离。

最后输出最短距离中距离最大的那个。。。

不知道说清楚了没有,反正比赛的时候我是没有想明白的,完了听Orc 提别人说是最短路才反应过来。。。

code:

代码丑了点Orz。。。。
不熟悉邻接表的优先队列实现还是个硬伤!!!
  1. //PS:用邻接矩阵写的一个比较丑的代码,还是不习惯用邻接表写。。。等熟悉了再折腾吧
  2. #include<stdio.h>
  3. #include<string.h>
  4. #include<algorithm>
  5. #include<iostream>
  6. using namespace std;
  7.  
  8. const int maxnN = 1000+10;
  9. const int maxnL = 10000+10;
  10. const int INF = 9999999;
  11. int n,h,L;
  12.  
  13. int d[maxnN];
  14. int w[maxnN][maxnN];
  15. int vis[maxnN];
  16.  
  17. void Dijkstra()
  18. {
  19. memset(vis, 0, sizeof(vis));
  20. for(int i = 0; i < n; i++)
  21. {
  22. int x , m = INF;
  23. for(int y = 0; y < n; y++) if(!vis[y] && d[y] <= m) m = d[x=y];
  24. if(m == INF) return; //如果存在孤立的点,不用继续判断
  25. vis[x] = 1;
  26. for(int y = 0; y < n; y++)
  27. d[y] = min(d[y], d[x]+w[x][y]);
  28. }
  29. }
  30. int main()
  31. {
  32. while(scanf("%d%d%d", &n,&h,&L) != EOF)
  33. {
  34. for(int i = 0; i < n; i++) d[i] = INF; //初始化每一条边,都没有相邻的
  35.  
  36. for(int i = 0; i < n; i++)
  37. for(int j = 0; j < n; j++)
  38. w[i][j] = (i == j ? 0 : INF);
  39. int x;
  40. for(int i = 0; i < h; i++)
  41. {
  42. scanf("%d", &x);
  43. d[x] = 0; //在恐怖表中的电影
  44. }
  45.  
  46. int a,b;
  47. for(int i = 0; i < L; i++)
  48. {
  49. scanf("%d%d", &a,&b);
  50. w[a][b] = 1; //双向图
  51. w[b][a] = 1;
  52. }
  53. Dijkstra();
  54.  
  55. int Max = d[0]; //从第一个开始查找
  56. int index = 0;
  57. for(int i = 1; i < n; i++)
  58. {
  59. if(d[i] > Max)
  60. {
  61. Max = d[i];
  62. index = i;
  63. }
  64. }
  65. printf("%d\n", index);
  66. //for(int i = 0; i < n; i++) printf("%d ", d[i]); printf("\n");
  67. }
  68. return 0;
  69. }

BNU 26480 Horror List【最短路】的更多相关文章

  1. BNUOJ-26480 Horror List 最短路

    题目链接:http://www.bnuoj.com/bnuoj/problem_show.php?pid=26480 题意:简单来说,就是给一个图,然后从每个honor list中的点求最短路.. 边 ...

  2. BNU 20950 ——沉重的货物 —————— · 最短路、最短边最大化」

    沉重的货物 Time Limit: 1000ms Memory Limit: 65536KB 64-bit integer IO format: %lld      Java class name: ...

  3. bzoj1001--最大流转最短路

    http://www.lydsy.com/JudgeOnline/problem.php?id=1001 思路:这应该算是经典的最大流求最小割吧.不过题目中n,m<=1000,用最大流会TLE, ...

  4. 【USACO 3.2】Sweet Butter(最短路)

    题意 一个联通图里给定若干个点,求他们到某点距离之和的最小值. 题解 枚举到的某点,然后优先队列优化的dijkstra求最短路,把给定的点到其的最短路加起来,更新最小值.复杂度是\(O(NElogE) ...

  5. Sicily 1031: Campus (最短路)

    这是一道典型的最短路问题,直接用Dijkstra算法便可求解,主要是需要考虑输入的点是不是在已给出的地图中,具体看代码 #include<bits/stdc++.h> #define MA ...

  6. 最短路(Floyd)

    关于最短的先记下了 Floyd算法: 1.比较精简准确的关于Floyd思想的表达:从任意节点A到任意节点B的最短路径不外乎2种可能,1是直接从A到B,2是从A经过若干个节点X到B.所以,我们假设maz ...

  7. bzoj1266最短路+最小割

    本来写了spfa wa了 看到网上有人写Floyd过了 表示不开心 ̄へ ̄ 改成Floyd试试... 还是wa ヾ(。`Д´。)原来是建图错了(样例怎么过的) 结果T了 于是把Floyd改回spfa 还 ...

  8. HDU2433 BFS最短路

    Travel Time Limit: 10000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Sub ...

  9. 最短路(代码来源于kuangbin和百度)

    最短路 最短路有多种算法,常见的有一下几种:Dijstra.Floyd.Bellman-Ford,其中Dijstra和Bellman-Ford还有优化:Dijstra可以用优先队列(或者堆)优化,Be ...

随机推荐

  1. MySQL笔记(三)之数据插入更新与删除

    INSERT INTO INSERT INTO 语句用于向表格中插入新的行. 语法: INSERT INTO 表 VALUES (值1, 值2,....) # 列数必须和值的个数匹配 INSERT I ...

  2. asp.net绝对与相对路径

    对于asp.net 路径的问题,闲心有很多人和我一样,只是知道一点,理解并不深刻.下面我就来整理一下相路径和绝对路径的知识. 绝对路径: 每个网页都有一个唯一的地址,它就是该网页的绝对路径.绝对路径提 ...

  3. 【UOJ #206】【APIO 2016】Gap

    http://uoj.ac/problem/206 对于T=1,直接从两端往中间跳可以遍历所有的点. 对于T=2,先求出最小值a和最大值b,由鸽巢原理,答案一定不小于\(\frac{b-a}{N-1} ...

  4. luogu P4115 Qtree4

    题目链接 luogu P4115 Qtree4 题解 动态点分治,和上一题一样.同样三个堆.就是带权,用边权替换深度就好 为什么要单独写这个题解呢,因为我卡常卡了一天....据说树剖比rmq快? 在第 ...

  5. [CC-SEABUB]Sereja and Bubble Sort

    [CC-SEABUB]Sereja and Bubble Sort 题目大意: 一个\(n(n\le100)\)个数的排列\(A\),有两种操作: 交换两个相邻元素: 等概率随机打乱整个序列. 最多执 ...

  6. Xcode常用插件推荐

    1.Xcode插件管理工具–Alcatraz的安装 Alcatraz是针对Xcode的一款插件管理器,通过Alcatraz可以非常方便的管理插件,包括安装.删除.升级等操作. 官方网站 安装方法一(推 ...

  7. Kafka 0.7.2 单机环境搭建

    Kafka 0.7.2 单机环境搭建当下载完Kafka后,进行解压,其目录结构如下: bin config contrib core DISCLAIMER examples lib lib_manag ...

  8. CentOS 6.9通过RPM安装EPEL源(http://dl.fedoraproject.org)

    另类的装法,通过RPM包直接安装 wget http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm & ...

  9. POJ 3384 Feng Shui (半平面交)

    Feng Shui Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 3743   Accepted: 1150   Speci ...

  10. 数论E - Biorhythms(中国剩余定理,一水)

    E - Biorhythms Time Limit:1000MS     Memory Limit:10000KB     64bit IO Format:%I64d & %I64u Subm ...