Gym 100112H Horror List—深搜—bfs

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 Movies which 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:
HI =



0 if movie is on horror list. This overrides the other definitions.
Q + 1 if the worst directly similar movie has HI = Q
+∞ if not similar at all to a horrible movie
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
, bi (0 ≤ ai < bi < 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 Sample Output 1
6 3 5
0 5 2
0 1
1 2
4 5
3 5
0 2
1
NCPC 2012 Problem H: Horror List 15
NCPC 2012
Sample Input 2 Sample Output 2
6 2 3
5 2
0 5
0 1
3 4
3

天天英语6级题,我擦,真的要死了
题意:
有n部电影,告诉你k部恐怖电影,有l个是相似的电影;
如果和恐怖相似它的价值就是直接相邻的电影中最小值+1;如果是恐怖电影值就是0 ,输出值最大电影的最小坐标
解:
直接bfs深搜

#include<bits/stdc++.h>
using namespace std;
const int inf=(int)1e9;
int main()
{

    int n,h,l,i,j;
    while(cin>>n>>h>>l)
    {
        int stu[10001]={0},val[10001];
        vector<int> mp[10001];
        queue<int>  q;
        while(!q.empty()){q.pop();}
        for(i=0;i<n;i++)
        {
            val[i]=inf;
            mp[i].clear();
        }
        for(i=0;i<h;i++)
        {
            int a;
            scanf("%d",&a);
            val[a]=0;
            q.push(a);
        }
        while(l--)
        {
            int a,b;
            scanf("%d%d",&a,&b);
            mp[a].push_back(b);
            mp[b].push_back(a);
        }
        while(!q.empty())
        {
            int tmp=q.front();
            q.pop();
            for(i=0;i<mp[tmp].size();i++)
            {
                if(val[mp[tmp][i]]==inf)
                {
                    val[mp[tmp][i]]=val[tmp]+1;
                    q.push(mp[tmp][i]);
                }
            }
        }
        int pos=0,ans=0;
        for(i=0;i<n;i++)
        {
            if(val[i]>ans)
            {
                ans=val[i];
                pos=i;
            }
        }
        cout<<pos<<endl;
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值