UVa 587 - There's treasure everywhere!

题目:你开始在坐标原点,想去目的地,给你一系列的指路信息,问目的地的位置和到原点的距离。

分析:模拟,计算几何。直接按照顺序计算即可,利用相对坐标求绝对坐标。

说明:注意输入格式。

#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cmath>

using namespace std;

int    temp;
char   buf[10];
double x,y;

int input(void)
{
	scanf("%d",&temp);
	int count = 0;
	while (buf[count] = getchar()) {
		if (buf[count] == '.' || buf[count] == ',') break;
		count ++;
	}
	int flag = 1;
	if (buf[count] == '.') flag = 0;
	buf[count] = 0;
	return flag;
}

void deal(void)
{
	if (buf[0] == 'W') { x -= temp;return; }
	if (buf[0] == 'E') { x += temp;return; }
	if (buf[0] == 'N') {
		if (buf[1] == 'W') { x -= temp*sqrt(0.5);y += temp*sqrt(0.5);return; }
		if (buf[1] == 'E') { x += temp*sqrt(0.5);y += temp*sqrt(0.5);return; }
		y += temp;return;
	}
	if (buf[0] == 'S') {
		if (buf[1] == 'W') { x -= temp*sqrt(0.5);y -= temp*sqrt(0.5);return; }
		if (buf[1] == 'E') { x += temp*sqrt(0.5);y -= temp*sqrt(0.5);return; }
		y -= temp;return;
	}
}

int main()
{
	int T = 1,B;
	while ((B = getchar()) != 'E') {
		ungetc(B, stdin);
		x = y = 0.0;
		while (input())
			deal();
		deal();getchar();
		printf("Map #%d\n",T ++);
		printf("The treasure is located at (%.3lf,%.3lf).\n",x,y);
		printf("The distance to the treasure is %.3lf.\n\n",sqrt(x*x+y*y));
	}
    return 0;
}

UVa 587 - There's treasure everywhere!

时间: 2024-10-09 10:30:36

UVa 587 - There's treasure everywhere!的相关文章

UVa 12325 Zombie&#39;s Treasure Chest【暴力】

题意:和上次的cf的ZeptoLab的C一样,是紫书的例题7-11 不过在uva上交的时候,用%I64d交的话是wa,直接cout就好了 1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include <cmath> 5 #include<stack> 6 #include<vector> 7 #include<map> 8 #include&l

UVa 12325 - Zombie&#39;s Treasure Chest-[分类枚举]

12325 Zombie’s Treasure Chest Some brave warriors come to a lost village. They are very lucky and find a lot of treasures and a big treasure chest, but with angry zombies. The warriors are so brave that they decide to defeat the zombies and then brin

【例题 7-11 UVA - 12325】Zombie&#39;s Treasure Chest

[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 1.N/s1 < 1e6 枚举1的个数 2.N/s2<1e6 枚举2的个数 3.s1和s2的值较小 假设买了s2个1和s1个2 那么这两种物品占的体积就一样大了. 即都为s1s2 而第一种物品价值为s2v1第二种物品价值为s1v2 那么 如果s2v1>s1v2的话. 可以想见,如果第二种物品的数量超过了s1的话,显然可以把它占的体积都用来买物品1,因为那样更优. 则我们第二种物品最多只要枚举到s1就可以了. 同理s2v1

UVA 562 Dividing coins --01背包的变形

01背包的变形. 先算出硬币面值的总和,然后此题变成求背包容量为V=sum/2时,能装的最多的硬币,然后将剩余的面值和它相减取一个绝对值就是最小的差值. 代码: #include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> using namespace std; #define N 50007 int c[102],d

UVA 10341 Solve It

Problem F Solve It Input: standard input Output: standard output Time Limit: 1 second Memory Limit: 32 MB Solve the equation: p*e-x + q*sin(x) + r*cos(x) + s*tan(x) + t*x2 + u = 0 where 0 <= x <= 1. Input Input consists of multiple test cases and te

UVA 11014 - Make a Crystal(容斥原理)

UVA 11014 - Make a Crystal 题目链接 题意:给定一个NxNxN的正方体,求出最多能选几个整数点.使得随意两点PQ不会使PQO共线. 思路:利用容斥原理,设f(k)为点(x, y, z)三点都为k的倍数的点的个数(要扣掉一个原点O).那么全部点就是f(1),之后要去除掉共线的,就是扣掉f(2), f(3), f(5)..f(n).n为素数.由于这些素数中包括了合数的情况,而且这些点必定与f(1)除去这些点以外的点共线,所以扣掉.可是扣掉后会扣掉一些反复的.比方f(6)在f

[UVa] Palindromes(401)

UVA - 401 Palindromes Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu Submit Status Description A regular palindrome is a string of numbers or letters that is the same forward as backward. For example, the string "ABCDED

uva 401.Palindromes

题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=342 题目意思:给出一段字符串(大写字母+数字组成).判断是否为回文串 or 镜像串 or 回文镜像串 or 什么都不是.每个字母的镜像表格如下 Character Reverse Character Reverse Character Reverse A A M M Y Y B

[2016-02-19][UVA][129][Krypton Factor]

UVA - 129 Krypton Factor Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & %llu Submit Status Description You have been employed by the organisers of a Super Krypton Factor Contest in which contestants have very high mental and physica