UVa 1382 Distant Galaxy 解题报告(枚举 + 前缀和)
来源:互联网 发布:新农合软件 编辑:程序博客网 时间:2024/04/30 09:15
1382 - 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?
Input
There are multiple test cases in the input file. Each test case starts with one integerN , (1N100), the number of star systems on the telescope. N lines follow, each line consists of two integers: theX and Y coordinates of theK-th planet system. The absolute value of any coordinate is no more than109, 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
解题报告: 绝对的好题目。
《训练指南》上说的很清楚了,不说啥了。总之,仔细体会,必有收获。代码如下:
#include <iostream>#include <cstdio>#include <algorithm>#include <cstring>#include <cmath>#include <vector>#include <queue>#include <map>#include <string>using namespace std;#define ff(i, n) for(int i=0;i<(n);i++)#define fff(i, n, m) for(int i=(n);i<=(m);i++)#define dff(i, n, m) for(int i=(n);i>=(m);i--)#define mem(a) memset((a), 0, sizeof(a))typedef long long LL;typedef unsigned long long ULL;void work();int main(){#ifdef ACM freopen("in.txt", "r", stdin);// freopen("in.txt", "w", stdout);#endif // ACM work();}/*****************************************/struct Point{ int x, y; bool operator<(const Point & cmp) const { return x < cmp.x; }} p[111];int n, m, y[111], l[111], on[111], on2[111];int solve(){ sort(p, p+n); sort(y, y+n); m = unique(y, y+n)-y; if(m <= 2) return n; int ans = 0; ff(a, m) fff(b, a+1, m) { int miny = y[a], maxy = y[b]; int k = 0; ff(i, n) { if(i==0 || p[i].x != p[i-1].x) { k++; on[k] = on2[k] = 0; l[k] = l[k-1]+on2[k-1]-on[k-1]; } if(p[i].y > miny && p[i].y < maxy) on[k]++; if(p[i].y >= miny && p[i].y <= maxy) on2[k]++; } int M = 0; fff(j, 1, k) { ans = max(ans, l[j]+on2[j]+M); M = max(M, on[j]-l[j]); } } return ans;}void work(){ int cas = 1; while(~scanf("%d", &n) && n) { ff(i, n) { scanf("%d%d", &p[i].x, &p[i].y); y[i] = p[i].y; } printf("Case %d: %d\n", cas++, solve()); }}
- UVa 1382 Distant Galaxy 解题报告(枚举 + 前缀和)
- uva 1382 - Distant Galaxy(枚举)
- uva 1382 Distant Galaxy (枚举)
- uva 1382 Distant Galaxy (枚举&&扫描&&贪心dp)
- UVA 1382 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
- UVA - 1382 Distant Galaxy
- Shanghai 2006 / UVa 1382 Distant Galaxy (枚举&扫描&动态维护)
- uva 1382 Distant Galaxy(离散化+枚举技巧)
- 【Jason's_ACM_解题报告】Distant Galaxy
- uva1382- Distant Galaxy (枚举)
- 1382 - Distant Galaxy(技巧枚举+离散化)
- LuoguP1311[NOIP2011] 选择客栈 解题报告【前缀和+枚举(?)】
- 整合struts1时web.xml里的配置
- SOLR中实现自定义评分函数FunctionQuery
- vim的一些实用技巧
- UVA 10090 Marbles(扩展欧几里得)
- C/C++/Qt 统计运行时间
- UVa 1382 Distant Galaxy 解题报告(枚举 + 前缀和)
- U-Boot操作Flash (NOR, NAND & SPI)
- 工资两三千,你的未来在哪里,马云——写给在工厂上班的同学们
- STL 源码剖析 算法 stl_algo.h -- search
- 经纬财富:鹤岗亏损是因为不懂资金管理
- codeforces 111C Petya and Spiders 状态压缩
- 的感觉还是大哥空间上看了个
- 13 反射
- 时间过得好快结束的更何况廉洁奉公看来大家分开