UVa 920 - Sunny Mountains

题目:有一些山,在一个平面山,给你每个山峰的坐标,太阳从右边照过来,被照到的线段的长度和。

分析:计算几何、贪心。首先,按很坐标排序;然后,每次找到左边第一个比它高的山峰,

求出对应的照射长度,求和即可。

说明:while(scanf("%d",&t))导致TLE,╮(╯▽╰)╭。

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

using namespace std;

typedef struct pnode
{
	double x,y;
}point;
point P[100];

bool cmp( point a, point b )
{
	return a.x > b.x;
}

double dist( point a, point b )
{
	return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}

int main()
{
	int T,N;
	while ( ~scanf("%d",&T) )
	while ( T -- ) {
		scanf("%d",&N);
		for ( int i = 0 ; i < N ; ++ i )
			scanf("%lf%lf",&P[i].x,&P[i].y);
		sort(P, P+N, cmp);

		double sums = 0.0;
		int    last = 0;
		for ( int i = 1 ; i < N ; ++ i )
			if ( P[i].y > P[last].y ) {
				sums += dist(P[i], P[i-1])*(P[i].y-P[last].y)/(P[i].y-P[i-1].y);
				last = i;
			}

		printf("%.2lf\n",sums);
	}
	return 0;
}

UVa 920 - Sunny Mountains

时间: 2024-10-04 13:54:41

UVa 920 - Sunny Mountains的相关文章

UVA - 10596 - Morning Walk (欧拉回路!并查集判断回路)

UVA - 10596 Morning Walk Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & %llu Submit Status Description Problem H Morning Walk Time Limit 3 Seconds Kamal is a Motashota guy. He has got a new job in Chittagong . So, he has moved to Ch

uva 10596 Morning Walk (欧拉回路)

uva 10596 Morning Walk Kamal is a Motashota guy. He has got a new job in Chittagong . So, he has moved to Chittagong from Dinajpur. He was getting fatter in Dinajpur as he had no work in his hand there. So, moving to Chittagong has turned to be a ble

UVA 10196 Morning Walk

Problem H Morning Walk Time Limit 3 Seconds Kamalis a Motashotaguy. He has got a new job in Chittagong. So, he has moved to Chittagong fromDinajpur. He was getting fatter in Dinajpur as he had no work in his hand there. So, moving toChittagong has tu

uva 10596 - Morning Walk

Problem H Morning Walk Time Limit 3 Seconds Kamal is a Motashota guy. He has got a new job in Chittagong. So, he has moved to Chittagong from Dinajpur. He was getting fatter in Dinajpur as he had no work in his hand there. So, moving to Chittagong ha

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