UVA 10927 Bright Lights

来源:互联网 发布:pyqt5 windows 安装 编辑:程序博客网 时间:2024/05/16 02:04

还是扫描线。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);}elseh = 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;}


原创粉丝点击