poj 3141Distant Galaxy
来源:互联网 发布:苹果app录音软件 编辑:程序博客网 时间:2024/05/16 14:08
Description
You are observing a distant galaxy using a telescope above the Astronomy Tower, and you think that a rectangle drawn in that galaxy whose edges are parallel to coordinate axes and contain maximum star systems on its edges has a great deal to do with the mysteries of universe. However you do not have the laptop with you, thus you have written the coordinates of all star systems down on a piece of paper and decide to work out the result later. Can you finish this task?
Input
There are multiple test cases in the input file. Each test case starts with one integerN, (1 ≤ N ≤ 100), the number of star systems on the telescope. N lines follow, each line consists of two integers: the X and Y coordinates of theKth planet system. The absolute value of any coordinate is no more than 109, and you can assume that the planets are arbitrarily distributed in the universe.
N = 0 indicates the end of input file and should not be processed by your program.
Output
For each test case, output the maximum value you have found on a single line in the format as indicated in the sample output.
Sample Input
102 39 27 43 45 71 510 410 611 44 60
Sample Output
Case 1: 7
Source
#include <iostream>#include <algorithm>#include <stdio.h>#include <string.h>using namespace std;const int MAX = 100+5;struct P{ int x,y; bool operator <(const P& point) const { return x < point.x; }}points[MAX];int caculate(int n){ int ys[MAX]; sort(points, points + n); for(int i = 0; i < n; i++)ys[i] = points[i].y; //计算y行数 sort(ys, ys + n); int y_count = unique(ys, ys + n) - ys; // for(int i = 0; i < y_count; i++)cout <<" "<<ys[i]; if(y_count < 2)return n; int left[MAX],vertical[MAX]; // memset(vertical, n, 0); int ans = 0; for(int up = 0; up < y_count; up++) for(int dwn = up + 1; dwn < y_count; dwn++) { // int up_axis = y[up],dwn_axis = y[dwn]; int col = 0; left[0] = 0,vertical[0] = 0; for(int i = 0; i < n; i++) { if(i != 0 && points[i].x != points[i - 1].x) { vertical[++col] = 0; left[col] = left[col - 1]; } if(points[i].y == ys[up] || points[i].y == ys[dwn])left[col]++; if(points[i].y > ys[up] && points[i].y < ys[dwn])vertical[col]++; } if(!col)return n; int m = vertical[0]; //cout << ys[up]<<"---"<<ys[dwn]<<endl; // cout<<"left-"<<0<<"=>"<<left[0]<<" verti-"<<0<<"=>"<<vertical[0]<<endl; for(int i = 1; i <= col; i++) { // cout<<"left-"<<i<<"=>"<<left[i]<<" verti-"<<i<<"=>"<<vertical[i]<<endl; ans = max(ans, left[i] + vertical[i] + m); m = max(m, vertical[i] - left[i - 1]); } } return ans;}int main(){ int t,n,x,y,kase = 1; //scanf("%d",&t); while(1) { scanf("%d",&n); if(!n)break; for(int i = 0; i < n; i++) scanf("%d%d",&points[i].x, &points[i].y); int ans = caculate(n); cout <<"Case "<<kase++<<": "<< ans<<endl; } //system("pause"); return 0;}
- POJ-3141-Distant Galaxy
- POJ--3141--Distant Galaxy
- poj 3141Distant Galaxy
- poj 3141 Distant Galaxy
- POJ 3141 Distant Galaxy 笔记
- Distant Galaxy poj 3141
- Distant Galaxy
- Distant Galaxy
- uva 1382 - Distant Galaxy
- uva 1382 - Distant Galaxy
- UVA - 1382 Distant Galaxy
- UVa:1382 Distant Galaxy
- UVA 1382 - Distant Galaxy
- UVA 1382 Distant Galaxy
- LA3695 - Distant Galaxy
- UVA - 1382 Distant Galaxy
- Distant Galaxy(高效)
- 【poj3141】 Distant Galaxy
- 人工智能系统
- Xms Xmx PermSize MaxPermSize 区别
- ip netns相关命令
- JSONP+PHP,跨域回调
- hduoj1093(A+B for Input-Output Practice (V))
- poj 3141Distant Galaxy
- hdu 4324(拓扑排序)
- uC/OS-II 学习笔记:消息邮箱
- 用上Google才是正事 分享几个访问Google的IP和域名
- qq营销软件详情咨询
- 2015 偶数求和
- hduoj2008(数值统计)
- HDU 4861 Couple doubi(数论)
- android shape的使用详解以及常用效果(渐变色、分割线、边框、半透明阴影效果等)