第四届山东省赛 Thrall’s Dream(BFS+vector)

2218: Thrall’s Dream

Time Limit: 1 Sec  Memory Limit: 128 MB

Submit: 253  Solved: 72

[Submit][Status][Web
Board
]

Description

We never paid any heed to the ancient prophecies, like fools we clung to the old hatreds, and fought as we had for generations. Until one day the sky rained fire, and a new enemy came upon us. We stand now upon the brink of destruction, for the Reign of
Chaos has come at last.

Thrall, the warchief of the Orcish Horde, all along, he led his tribe live in the fringe of Lordaeron under the human control. In a downpour night, Thrall falls into sleep in a Orc hall at Arathi Highlands, at this moment he heard a voice:

“The sands of time have run out, son of Durotan. The cries of war echo upon the winds, the remnants of the past scar the land which is besieged once again by conflict. Heroes arise to challenge fate, and lead their brethren to battle. As mortal armies rush
blindly towards their doom, The Burning Shadow comes to consume us all. You must rally the Horde, and lead your people to their destiny.

I will answer all of your questions in time, young warchief. For now, rally your warriors and prepare to leave this land, cross the sea to the distant land of Kalimdor. We will speak again. ”

Thrall believes the prophesy of Blood Raven Medivh. Three days later, He and Grom Hellscream‘s Warsong Clan meet in the Lordaeron coast to the distant lands of Kalimdor. But the Goblin Zeppelins they take encountered storms in the middle. Thrall and Grom
falling to the islands, they want to find each other and then to Kalimdor.

For the sake of simplicity, we assume that Thrall and Grom may fall into any islands x and y, only by Thrall to find Grom or by Grom to find Thrall. Give you the map of this island, please judge that Thrall and Gtom can meet?

Input

There are multiple test case in the input file, first line is a case number T. Each test case will begin with two integers N (0 <= N < 2001) and M (0 <= M < 10001), where N is the number of islands and M is number of portal. Next M lines each line contains
two integers a and b, indicated there is a portal in island a that people can go from a to b by this portal. The island numbered from 1 to N.

Output

For each test case, your output should be in one line with “Kalimdor is just ahead” (without quotes, hereinafter the same) if Thrall and Grom can meet or “The Burning Shadow consume us all” otherwise as indicated in the sample output.

Sample Input

2
3 2
1 2
1 3

3 2
1 2
2 3

Sample Output

Case 1: The Burning Shadow consume us all
Case 2: Kalimdor is just ahead

HINT

Source

2013年山东省第四届ACM大学生程序设计竞赛

因为题目中的数据范围太大,可以选择不定长数组进行记录,这样省时间

#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<queue>
#include<vector>  

using namespace std;  

int n,m;
bool v[2015],mm[2015][2015];
vector<int>map[2015];  

void BFS(int x)
{
    queue<int>q;
    while(!q.empty())
    {
        q.pop();
    }
    for(int j=0; j<map[x].size(); j++)
    {
        q.push(map[x][j]);
        v[map[x][j]] = true;
    }
    v[x] = true;
    while(!q.empty())
    {
        int t = q.front();
        q.pop();
        for(int j=0; j<map[t].size(); j++)
        {
            if(v[map[t][j]] == 0)
            {
                v[map[t][j]] = true;
                q.push(map[t][j]);
                mm[x][map[t][j]] = true;
            }  

        }
    }
}  

int main()
{
    int T;
    int kk = 0;
    scanf("%d",&T);
    while(T--)
    {
        int x,y;
        scanf("%d%d",&n,&m);
        for(int i=0; i<=n; i++)
        {
            for(int j=0; j<=n; j++)
            {
                mm[i][j] = false;
            }
            mm[i][i] = true;
        }
        for(int i=1; i<=n; i++)
        {
            map[i].clear();
        }
        for(int i=0; i<m; i++)
        {
            scanf("%d%d",&x,&y);
            map[x].push_back(y);
            mm[x][y] = true;
        }
        int flag = 0;
        for(int i=1; i<=n; i++)
        {
            memset(v,0,sizeof(v));
            BFS(i);
        }
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=n;j++)
            {
                if(mm[i][j] == 0 && mm[j][i] == 0)
                {
                    flag = 1;
                    printf("Case %d: The Burning Shadow consume us all\n",++kk);
                    break;
                }
            }
            if(flag == 1)
            {
                break;
            }
        }
        if(flag == 0)
        {
            printf("Case %d: Kalimdor is just ahead\n",++kk);
        }  

    }
    return 0;
}  
时间: 2024-07-28 20:58:37

第四届山东省赛 Thrall’s Dream(BFS+vector)的相关文章

sdut 2603:Rescue The Princess(第四届山东省省赛原题,计算几何,向量旋转 + 向量交点)

Rescue The Princess Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 Several days ago, a beast caught a beautiful princess and the princess was put in prison. To rescue the princess, a prince who wanted to marry the princess set out immedia

Sdut 2108 Alice and Bob(数学题)(山东省ACM第四届省赛D题)

题目地址:sdut 2608 Alice and Bob Alice and Bob Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 Alice and Bob like playing games very much.Today, they introduce a new game. There is a polynomial like this: (a0*x^(2^0)+1) * (a1 * x^(2^1)+1)*....

sdutoj Thrall’s Dream

http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2604 Thrall’s Dream Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 We never paid any heed to the ancient prophecies, like fools we clung to the old hatreds, and fought

[ACM] SDUT 2604 Thrall’s Dream

Thrall's Dream Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 We never paid any heed to the ancient prophecies, like fools we clung to the old hatreds, and fought as we had for generations. Until one day the sky rained fire, and a new ene

山东省赛题 NEU OJ 1444 线段树双标记

http://acm.neu.edu.cn/hustoj/problem.php?id=1444 OJ问题论坛发帖http://t.cn/zjBp4jd FAQ http://t.cn/zjHKbmN Linux问题看http://t.cn/aWnP1n 1444: Devour Magic 时间限制: 1 Sec  内存限制: 256 MB 提交: 129  解决: 21 [提交][状态][讨论版] 题目描述 In Warcraft III, Destroyer is a large flyi

第五届山东省赛总结

这次比赛在HITWH,10号我们早早的坐车来到了威海,然后随便逛了逛,吃了饭,就是热身赛. 热身赛题目比较坑爹,尤其是A题,要求区间素数个数,给的数据是10^7,我写了一个却WA了.后来得知有10^9的情况,感觉一下成了神题,我想了好久也没思路,结束后得知大于10^7的数全部当成10^7做,太坑.但这样都有人能AC,真是膜拜.B题是要交一个随机数,RP比较好,2A.C据说是概率DP,我不会也没仔细看. 之后是开幕式,完了以后我一个人回了宾馆,跟山大威海的同学吃了一顿,随后回去看了看电视就睡了.

hdu 4771 Stealing Harry Potter&#39;s Precious (2013亚洲区杭州现场赛)(搜索 bfs + dfs) 带权值的路径

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4771 题目意思:'@'  表示的是起点,'#' 表示的是障碍物不能通过,'.'  表示的是路能通过的: 目的:让你从 '@' 点出发,然后每个点只能走一次,求出最小的距离: 解题思路:先用 bfs 求解出任意两点之间的距离,用 ans[i][j],表示点 i 到点  j 的距离: 然后用 dfs 递归求出从起点经过所有点的距离中,比较出最小的: AC代码: 1 #include<iostream>

hdu1212 Big Number &amp;第六届山东省赛Single Round Math (同余定理,大数取模)

题目链接:Big Number 题目大意:每次输入两个数,第一个是高精度,第二个数小于100000:求 a mod b 根据同余定理: (a+b)% c = (a%c+ b%c)%c (a*b)%c =  ( a%c* b%c)%c 所以 对于大数,例如 :123 可以这样分解 123 =  (1*10+2)*10 + 3: 123 % c =   (  (  (  1%c *  10%c)%c + 2%c) %c  * 10%c) + 3 %c  ) %c; 因此,我们用字符串处理这个数,通过

sdut 2610:Boring Counting(第四届山东省省赛原题,划分树 + 二分)

Boring Counting Time Limit: 3000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 In this problem you are given a number sequence P consisting of N integer and Pi is the ith element in the sequence. Now you task is to answer a list of queries, for each quer