• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
HaibaraAi
博客园    首页    新随笔    联系   管理    订阅  订阅

LA 3695 Distant Galaxy

 

3695 - Distant Galaxy

Time limit: 3.000 seconds

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?

 <tex2html_verbatim_mark>

Input 

There are multiple test cases in the input file. Each test case starts with one integer N <tex2html_verbatim_mark>, (1$ \le$N$ \le$100) <tex2html_verbatim_mark>, the number of star systems on the telescope. N <tex2html_verbatim_mark>lines follow, each line consists of two integers: the X <tex2html_verbatim_mark>and Y <tex2html_verbatim_mark>coordinates of the K <tex2html_verbatim_mark>-th planet system. The absolute value of any coordinate is no more than 109 <tex2html_verbatim_mark>, and you can assume that the planets are arbitrarily distributed in the universe.

N = 0 <tex2html_verbatim_mark>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 

10 
2 3 
9 2 
7 4 
3 4 
5 7 
1 5 
10 4 
10 6 
11 4 
4 6 
0

Sample Output 

Case 1: 7
 1 #pragma comment(linker,"/STACK:102400000,102400000")
 2 #include <cstdio>
 3 #include <vector>
 4 #include <cmath>
 5 #include <queue>
 6 #include <cstring>
 7 #include <iostream>
 8 #include <algorithm>
 9 using namespace std;
10 #define INF 0x7fffffff
11 #define mod 1000000007
12 #define ll long long
13 #define maxn 105
14 #define pi acos(-1.0)
15 //const int maxk = 10 + 1, inf = ~0U >> 2;
16 int n, m, ans,s;
17 struct point{
18     int x, y;
19 }a[maxn];
20 bool cmp(point a, point b){ return a.x < b.x; }
21 int px[maxn], p[maxn],lf[maxn],on[maxn],on2[maxn];
22 int main(){
23     int cas = 1;
24     while (~scanf("%d",&n)&&n){
25         int t = 0, tt = 0;
26         for (int i = 0; i < n; i++){
27             scanf("%d%d", &a[i].x, &a[i].y);
28             px[tt++] = a[i].y;
29         }
30         sort(a, a + n, cmp);
31         sort(px, px + tt);
32         if(tt)p[t++] = px[0];
33         for (int i = 1; i < tt; i++)if(px[i]!=px[i-1])p[t++]=px[i];
34         printf("Case %d: ", cas++);
35         if (t <= 2){ printf("%d\n", n); continue; }    
36         ans = 0;
37         for (int i = 0; i < t;i++)
38         for (int j = i+1; j < t; j++){
39             //memset(lf, 0, sizeof lf);
40             int h = 0;
41             for (int k = 0; k < n; k++){
42                 if (k==0||a[k].x!=a[k-1].x){
43                     h++;
44                     on[h] = on2[h] = 0;
45                     lf[h] = lf[h - 1] + on2[h - 1] - on[h - 1];
46                 }
47                 if (a[k].y >p[i] && a[k].y < p[j])on[h]++;
48                 if (a[k].y >= p[i] && a[k].y <= p[j])on2[h]++;
49             }
50             if (h <= 2){ ans = n; i = t; break; }
51             int res = 0;
52             for (int k = 1; k <= h; k++){
53                 ans = max(ans, on2[k] + res + lf[k]);
54                 res = max(res, on[k] - lf[k]);
55             }
56         }
57         printf("%d\n", ans);
58     }
59     return 0;
60 }
View Code


 

posted @ 2013-12-28 19:10  HaibaraAi  阅读(136)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3