LA 3695 Distant Galaxy(扫描线)
2015-11-26 11:58
393 查看
Distant Galaxy
Time Limit: 3000msMemory Limit: 131072KB
This problem will be judged on UVALive. Original ID: 3695
64-bit integer IO format: %lld Java class name: Main
Prev Submit Status Statistics Discuss Next
Font Size:
+
-
Type:
None
Graph Theory
2-SAT
Articulation/Bridge/Biconnected Component
Cycles/Topological Sorting/Strongly Connected Component
Shortest Path
Bellman Ford
Dijkstra/Floyd Warshall
Euler Trail/Circuit
Heavy-Light Decomposition
Minimum Spanning Tree
Stable Marriage Problem
Trees
Directed Minimum Spanning Tree
Flow/Matching
Graph Matching
Bipartite Matching
Hopcroft–Karp Bipartite Matching
Weighted Bipartite Matching/Hungarian Algorithm
Flow
Max Flow/Min Cut
Min Cost Max Flow
DFS-like
Backtracking with Pruning/Branch and Bound
Basic Recursion
IDA* Search
Parsing/Grammar
Breadth First Search/Depth First Search
Advanced Search Techniques
Binary Search/Bisection
Ternary Search
Geometry
Basic Geometry
Computational Geometry
Convex Hull
Pick's Theorem
Game Theory
Green Hackenbush/Colon Principle/Fusion Principle
Nim
Sprague-Grundy Number
Matrix
Gaussian Elimination
Matrix Exponentiation
Data Structures
Basic Data Structures
Binary Indexed Tree
Binary Search Tree
Hashing
Orthogonal Range Search
Range Minimum Query/Lowest Common Ancestor
Segment Tree/Interval Tree
Trie Tree
Sorting
Disjoint Set
String
Aho Corasick
Knuth-Morris-Pratt
Suffix Array/Suffix Tree
Math
Basic Math
Big Integer Arithmetic
Number Theory
Chinese Remainder Theorem
Extended Euclid
Inclusion/Exclusion
Modular Arithmetic
Combinatorics
Group Theory/Burnside's lemma
Counting
Probability/Expected Value
Others
Tricky
Hardest
Unusual
Brute Force
Implementation
Constructive Algorithms
Two Pointer
Bitmask
Beginner
Discrete Logarithm/Shank's Baby-step Giant-step Algorithm
Greedy
Divide and Conquer
Dynamic Programming
Tag it!
[PDF Link]
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 integer N , (1N
100) ,
the number of star systems on the telescope. N lines follow,
each line consists of two integers: the X and Y coordinates
of the K -th 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
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
Source
Regionals 2006, Asia - ShanghaiPrev Submit Status Statistics Discuss Next
给出n个点坐标,找一个矩形,使边界上的点最多。思路枚举上下边界,然后用扫描线,大白P53
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e2 + 10;
struct Node {
int x,y;
bool operator < (const Node & rhs) const {
return x < rhs.x;
}
}p[maxn];
int y[maxn];
int L[maxn],on[maxn],on2[maxn];
int solve(int n)
{
sort(p,p+n);
sort(y,y+n);
int m = unique(y,y+n) - y;
if(m < 3) return n; ///不超过两个y坐标
int ans = 0;
for(int a = 0; a < m; ++a) {
for(int b = a+1; b < m; ++b) {
int k = 0,ymin = y[a],ymax = y[b];
for(int i = 0; i < n; ++i) {
if(i==0 || p[i].x != p[i-1].x) { ///新的竖线
++k;
on[k] = 0;
on2[k] = 0;
L[k] = L[k-1] + on2[k-1] - on[k-1];
}
if(p[i].y > ymin && p[i].y < ymax) ++on[k];
if(p[i].y >= ymin && p[i].y <= ymax) ++on2[k];
}
if(k < 3) return n; ///不超过两个x坐标
int M = 0;
for(int i = 1; i <= k; ++i) {
ans = max(ans,L[i]+on2[i]+M);
M = max(M,on[i]-L[i]);
}
}
}
return ans;
}
int main()
{
int n,cas = 0;
while(scanf("%d",&n)==1&& n) {
++cas;
for(int i = 0; i < n; ++i) {
scanf("%d%d",&p[i].x,&p[i].y);
y[i] = p[i].y;
}
int ans = solve(n);
printf("Case %d: %d\n",cas,ans);
}
return 0;
}
相关文章推荐
- python
- solr的or查询
- Mac下利用Cordova打包 iOS App以及出现的问题
- [知其然不知其所以然-11] turbo功能如果没有在所有的cpu上都使能会怎么样?
- Android屏幕适配全攻略(最权威的官方适配指导)
- sql server 中将由逗号“,”分割的一个字符串,转换为一个表,并应用与 in 条件
- SimpleAdapter真不简单!
- C语言中简单的循环
- springMVC 一些文章
- Oracle索引
- 实现带快速导航的ListView(自定义View和自定义ViewGroup的结合),可直接使用和修改使用
- Abp Application级别的生命周期
- REST API权限集成设计
- 错误处理try-catch,异常抛出throws、throw
- 不是为了你而演奏
- php7在 windows环境下部署
- 把PPT放入浏览器中——12款用于演示的JS库
- C++11中值得关注的几大变化
- WCF svcutil工具
- FileOutputStream