文档章节

poj There's Treasure Everywhere!

locusxt
 locusxt
发布于 2013/05/19 23:13
字数 785
阅读 29
收藏 0
There's Treasure Everywhere!


描述
    Finding buried treasures is simple: all you need is a map! The pirates in the Caribbean were famous for
     their enormous buried treasures and their elaborate maps. The maps usually read like ``Start at the lone
      palm tree. Take three steps towards the forest, then seventeen step towards the small spring, . . . blahblah
       . . . , finally six steps toward the giant rock. Dig right here, and you will find my treasure!'' Most of
       these directions just boil down to taking the mentioned number of steps in one of the eight principal compass
       directions (depicted in the left of the figure).
    Obviously, following the paths given by these maps may lead to an interesting tour of the local scenery, but if
     one is in a hurry, there is usually a much faster way: just march directly from your starting point to the place
      where the treasure is buried. Instead of taking three steps north, one step east, one step north, three steps
      east, two steps south and one step west (see figure), following the direct route (dashed line in figure) will
       result in a path of about 3.6 steps.


    You are to write a program that computes the location of and distance to a buried treasure, given a 'traditional' map.
输入
    The input contains several strings, each one on a line by itself, and each one consisting of at most 200 characters.
    The last string will be END, signaling the end of the input. All other strings describe one treasure map each, according
     to the following format:


    The description is a comma-separated list of pairs of lengths (positive integers less than 1000) and directions
    (N (north), NE (northeast), E (east), SE (southeast), S (south), SW (southwest), W (west) or NW (northwest)).
    For example, 3W means 3 steps to the west, and 17NE means 17 steps to the northeast. A full stop (.) terminates
    the description, which contains no blanks.
输出
    For every map description in the input, first print the number of the map, as shown in the sample output. Then
    print the absolute coordinates of the treasure, in the format "The treasure is located at (x,y).". The coordinate
    system is oriented such that the x-axis points east, and the y-axis points north. The path always starts at the origin (0,0).


    On the next line print the distance to that position from the point (0,0), in the format "The distance to the
    treasure is d.". The fractional values x, y, d must be printed exact to three digits to the right of the decimal point.


    Print a blank line after each test case.
样例输入


    3N,1E,1N,3E,2S,1W.
    10NW.
    END


样例输出


    Map #1
    The treasure is located at (3.000,2.000).
    The distance to the treasure is 3.606.


    Map #2
    The treasure is located at (-7.071,7.071).
    The distance to the treasure is 10.000.


    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    using namespace std;


    int main()
    {
        int c = 0;
        while (true)
        {
            c++;
            double x = 0, y = 0;
            int times[8] = {0};
            char ord[205];
            int num[205];
            char dir[2];
            int numit = 0;
            int dirit = 0;
            scanf("%s", ord);
            if(ord[0] == 'E') break;
            for(int i = 0; i < strlen(ord); i++)
            {
                if('0' <= ord[i] && ord[i] <= '9') {num[numit] = ord[i] - '0'; numit++;}
                else if('A' <= ord[i] && ord[i] <= 'Z') {dir[dirit] = ord[i]; dirit++;}
                else
                {
                    int n = 0;
                    for(int j = numit - 1; j >= 0; j--)
                    n += num[j] * pow(10.0, numit - j - 1);
                    if(dirit == 1)
                    {
                        if(dir[0] == 'N') times[0] += n;
                        else if(dir[0] == 'E') times[2] += n;
                        else if(dir[0] == 'S') times[4] += n;
                        else if(dir[0] == 'W') times[6] += n;
                    }
                    else if(dirit == 2)
                    {
                        if(dir[0] == 'N' && dir[1] == 'E') times[1] += n;
                        else if(dir[0] == 'S' && dir[1] == 'E') times[3] += n;
                        else if(dir[0] == 'S' && dir[1] == 'W') times[5] += n;
                        else if(dir[0] == 'N' && dir[1] == 'W') times[7] += n;
                    }
                    numit = 0;
                    dirit = 0;
                }
            }
            //for(int i = 0; i < 8; i++)
            //printf("%d ", times[i]);
            for(int i = 0; i < 4; i++)
            times[i] -= times[i + 4];
            x = double(times[1]) * sqrt(2.0) / 2+ double(times[2]) + double(times[3]) * sqrt(2.0) / 2;
            y = double(times[0]) + double(times[1]) * sqrt(2.0) / 2 - double(times[3])  * sqrt(2.0) / 2;
            double dis = sqrt(x*x + y*y);
            if(x == -0.0) x = 0.0;
            if(y == -0.0) y = 0.0;
            if(dis == -0.0) dis = 0.0;


            printf("Map #%d\nThe treasure is located at (%.3f,%.3f).\n" ,c, x,y);
            printf("The distance to the treasure is %.3f.\n", dis);
            printf("\n");
        }
        return 0;
    }

© 著作权归作者所有

locusxt
粉丝 27
博文 140
码字总数 90989
作品 0
海淀
程序员
私信 提问
寻宝风格导航地图 Treasure 诞生记 | Mapbox 地图设计思路

Designing the Treasure map style 不久前,我们为大家介绍了霓虹灯风格地图 80‘s 8-bit 的设计思路,这篇文章我们继续分享一个有趣的地图设计 —— 寻宝风格地图 Treasure。 这张地图来自 ...

Mapbox前台小姐姐
08/16
0
0
算法进阶路径

第一阶段:练经典常用算法,下面的每个算法给我打上十到二十遍,同时自己精简代码, 因为太常用,所以要练到写时不用想,10-15分钟内打完,甚至关掉显示器都可以把程序打 出来. 1.最短路(Fl...

暖冰
2016/04/02
163
1
一个搞ACM需要掌握的算法

ACM的竞赛性强,因此自己应该和自己的实际应用联系起来.适合自己的才是好的,有的人不适合搞算法,喜欢系统架构,因此不要看到别人什么就眼红,发挥自己的长处,这才是重要的. 第一阶段:练经典常用...

long0404
2015/06/24
0
0
POJ 1328: Radar Installation

题目在此 解题思路: 以岛屿坐标为圆心,输入值为半径画圆,此圆会与 X 轴相交于 S、E 两点(岛屿 Y 坐标等于圆半径时,交一点;Y 坐标大于圆半径的情况提前排除,不参与后面的计算)。然后对...

Alexander_zhou
2014/02/22
186
0
Borg Maze POJ - 3026

题目链接:https://vjudge.net/problem/POJ-3026 思路: 题目说建立一个通道网络,使得‘S’能到达其他所有'A',且所有通道长度相加最短,可以看出是一个最小生成树,就是建图比较麻烦。 用b...

SSummerZzz
11/08
0
0

没有更多内容

加载失败,请刷新页面

加载更多

数据仓库分层示意图

细肉云吞
25分钟前
6
0
android studio集成opencv的方法

注意:每个版本的方法可能是不一样的,我使用的版本是4.1.1,这个版本指的是opencv-android的版本 1.从opencv官网下载opencv-android的sdk包,地址:https://opencv.org/releases/ 2.解压下载...

shatian
38分钟前
8
0
CentOS 7上的NGINX 安装 Godaddy SSL证书

Step 1.创建一个目录来存储服务器密钥 & 证书 $ mkdir /usr/local/nginx/conf/vhost/sslkey Step 2.生成CSR 说明:会提示填:1.国家 2.省份 3.城市 4.公司名称....等,填完后会生成 sasha-la...

Linux_Anna
40分钟前
7
0
WKWebView简单使用-(KVO)加载进度条,标题,返回

- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation{//如果将cangoback写在此方法里面只能执行一次,如果当前网页跳转不是新的web就不能执行}//通过...

west_zll
46分钟前
5
0
CentOS 7设置静态IP配置

vim /etc/sysconfig/network-scripts/ifcfg-ens33 TYPE=EthernetPROXY_METHOD=noneBROWSER_ONLY=noBOOTPROTO=staticDEFROUTE=yesIPV4_FAILURE_FATAL=noIPV6INIT=yesIPV6_AUTOC......

Jugier
51分钟前
4
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部