UVA 10927 Bright Lights

还是扫描线。Rank 15 耶~

给你一些柱子还有柱子的高度,问你从0 0 哪些看不到。

直接极角排序,然后相同角度按从近到远的距离排,然后保存共线最大高度,扫一遍即可。

第二次输出排序忘排 y 了,WA了几次 = =。。还以为是比较猥琐的错误呢,比如1个数的话不是“are” 是 “is” 什么的,不过这个题没有。。。 = =。。我想太多了。

#include <map>
#include <set>
#include <queue>
#include <stack>
#include <math.h>
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <limits.h>
#include <string.h>
#include <string>
#include <algorithm>
#define MID(x,y) ( ( x + y ) >> 1 )
#define L(x) ( x << 1 )
#define R(x) ( x << 1 | 1 )
#define BUG puts("here!!!")
#define STOP system("pause")

using namespace std;

const int MAX = 100010;
struct point {int x,y,h; double t;};
point p[MAX];
point out[MAX];
bool cmp(point a,point b)
{
	if( a.t == b.t )
		return a.x*1ll*a.x + a.y*1ll*a.y < b.x*1ll*b.x + b.y*1ll*b.y;
	return a.t < b.t;
}
bool cmp1(point a,point b)
{
	if( a.x == b.x ) return a.y < b.y;
	return a.x < b.x;
}
int main()
{
	int n, ind = 1;
	while( ~scanf("%d", &n) && n )
	{
		for(int i=0; i<n; i++)
		{
			scanf("%d%d%d", &p[i].x, &p[i].y, &p[i].h);
			p[i].t = atan2(p[i].y, p[i].x);
		}
		
		sort(p, p+n, cmp);

		int cnt = 0;
		int h = p[0].h;
		for(int i=1; i<n; i++)
		{
			if( p[i].t == p[i-1].t )
			{
				if( p[i].h <= h )
					out[cnt++] = p[i];
				h = max(h, p[i].h);
			}
			else
				h = p[i].h;
		}
		printf("Data set %d:\n", ind++);
		
		if( cnt == 0 )
		{
			printf("All the lights are visible.\n");
			continue;
		}
		sort(out, out+cnt, cmp1);
		
		printf("Some lights are not visible:\n");
		for(int i=0; i<cnt-1; i++)
			printf("x = %d, y = %d;\n", out[i].x, out[i].y);
		printf("x = %d, y = %d.\n", out[cnt-1].x, out[cnt-1].y);
		
	}

return 0;
}


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值