HDU 2722 Here We Go(relians) Again

來源:互聯網
上載者:User

就是題目長...  只要構好圖就可以了。

1:each block is a square measuring 2520 rels per side 。

2:The speed limit between two adjacent intersections is always constant, and may range from 1 to 9 rels per blip

每條邊的邊長都是2520,速度1-9. 所以按time = 2520 / speed 構圖。

 

00447988 2010-07-05 21:03:02 Accepted 1012 15 MS 1180 KB Visual C++ Slave_wc

#include <iostream><br />#include <cstring><br />#include <queue><br />using namespace std;<br />#define MAXN 500<br />const int slave = 2520;<br />int map[MAXN][MAXN];<br />int dis[MAXN];<br />bool hash[MAXN];<br />struct Dij<br />{<br />    int id;<br />    int dis;<br />    bool friend operator < (const Dij a, const Dij b)<br />    {<br />        return a.dis > b.dis;<br />    }<br />};<br />Dij now, next;<br />int Bfs(int st, int ed, int n)<br />{<br />    memset(hash, false, sizeof(hash));<br />    memset(dis, 0x7f, sizeof(dis));<br />    priority_queue<Dij> Q;<br />    now.id = st;<br />    now.dis = 0;<br />    dis[st] = 0;<br />    Q.push(now);<br />    <br />    while (!Q.empty())<br />    {<br />        now = Q.top();<br />        Q.pop();<br />        <br />        if (hash[now.id])<br />        {<br />            continue;<br />        }<br />        if (now.id == ed)<br />        {<br />            return now.dis;<br />        }<br />        hash[now.id] = true;<br />        <br />        for (int j = 1; j <= n; j++)<br />        {<br />            if (!hash[j] && dis[j] > dis[now.id] + map[now.id][j])<br />            {<br />                dis[j] = dis[now.id] + map[now.id][j];<br />                next.id = j;<br />                next.dis = dis[j];<br />                 Q.push(next);<br />            }<br />        }<br />    }<br />    return -1;<br />}<br />int main()<br />{<br />    int n, m, i, j, a, r, t;<br />    char str[10];<br />    <br />    while (scanf("%d %d", &n, &m) != EOF)<br />    {<br />        if (n == 0 && m == 0)<br />        {<br />            break;<br />        }<br />        r = 1;<br />        memset(map, 0x7f, sizeof(map));<br />        for (i = 1; i <= 2 * n + 1; i++)<br />        {<br />            if (i & 1)<br />            {<br />                for (j = 1; j <= m; j++)<br />                {<br />                    scanf("%d %s", &a, str);<br />                    if (a == 0)<br />                    {<br />                        continue;<br />                    }<br />                    int left = (r - 1) * (m + 1) + j;<br />                    int right = left + 1;<br />                    if (str[0] == '*')<br />                    {<br />                        t = slave / a;<br />                        map[left][right] = t;<br />                        map[right][left] = t;<br />                    }<br />                    else if (str[0] == '>')<br />                    {<br />                        t = slave / a;<br />                        map[left][right] = t;     <br />                    }<br />                    else if (str[0] == '<')<br />                    {<br />                        t = slave / a;<br />                        map[right][left] = t;<br />                    }<br />                }<br />                r++;<br />            }<br />            else<br />            {<br />                for (j = 1; j <= m + 1; j++)<br />                {<br />                    scanf("%d %s", &a, str);<br />                    if (a == 0)<br />                    {<br />                        continue;<br />                    }<br />                    int down = (r - 1) * (m + 1) + j;<br />                    int up = down - (m + 1);<br />                    if (str[0] == '*')<br />                    {<br />                        t = slave / a;<br />                        map[up][down] = t;<br />                        map[down][up] = t;<br />                    }<br />                    else if (str[0] == '^')<br />                    {<br />                        t = slave / a;<br />                        map[down][up] = t;     <br />                    }<br />                    else if (str[0] == 'v')<br />                    {<br />                        t = slave / a;<br />                        map[up][down] = t;<br />                    }<br />                }<br />            }<br />        }<br />        int st = 1;<br />        int ed = (n + 1) * (m + 1);<br />        int ans = Bfs(st, ed, ed);<br />        if (ans != -1)<br />        {<br />            printf("%d blips/n", ans);<br />        }<br />        else<br />        {<br />            puts("Holiday");<br />        }<br />    }<br />    return 0;<br />}<br /> 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.