POJ 2737 Swamp Things (斜率判断多点共线)
来源:互联网 发布:织梦cms使用手册 编辑:程序博客网 时间:2024/06/04 19:36
Swamp Things
题意: 判断最多的共线的点数
思路: 把所有点对的斜率都存下来 然后排序 看有多少相同的 相同的说明共线 注意判断斜率不存在的情况
参考code:
map TLE了 慎用STL
//// Created by TaoSama on 2015-06-12// Copyright (c) 2015 TaoSama. All rights reserved.////#pragma comment(linker, "/STACK:1024000000,1024000000")#include <algorithm>#include <cctype>#include <cmath>#include <cstdio>#include <cstdlib>#include <cstring>#include <iomanip>#include <iostream>#include <map>#include <queue>#include <string>#include <set>#include <vector>using namespace std;const int INF = 0x3f3f3f3f;const int MOD = 1e9 + 7;const int N = 1e5 + 10;const double EPS = 1e-10;int n, x[1005], y[1005];double k[1005];int main() {#ifdef LOCAL freopen("in.txt", "r", stdin);// freopen("out.txt","w",stdout);#endif ios_base::sync_with_stdio(0); int kase = 0; while(scanf("%d", &n) == 1 && n) { for(int i = 1; i <= n; ++i) scanf("%d%d", x + i, y + i); int ans = 0; for(int i = 1; i <= n; ++i) { int cnt = 0; for(int j = i + 1; j <= n; ++j) { if(x[i] == x[j]) k[cnt++] = INF; else k[cnt++] = (y[i] - y[j]) * 1.0 / (x[i] - x[j]); } sort(k, k + cnt); for(int j = 0; j < cnt; ++j) { int ct = 1; while(j + 1 < cnt && abs(k[j] - k[j + 1]) < EPS) ++j, ++ct; ans = max(ct, ans); } } ans += 1; if(ans < 4) ans = 0; printf("Photo %d: %d points eliminated\n", ++kase, ans); } return 0;}/*int n, x[1005], y[1005];int main() {#ifdef LOCAL freopen("in.txt", "r", stdin);// freopen("out.txt","w",stdout);#endif ios_base::sync_with_stdio(0); int kase = 0; while(scanf("%d", &n) == 1 && n) { for(int i = 1; i <= n; ++i) scanf("%d%d", x + i, y + i); int ans = 0; for(int i = 1; i <= n; ++i) { int Max = 0; map<double, int> slope; for(int j = i + 1; j <= n; ++j) { double t; if(x[i] == x[j]) t = INF; else t = (y[i] - y[j]) * 1.0 / (x[i] - x[j]); //cout << t << endl; if(!slope.count(t)) { slope[t] = 2; Max = max(Max, 2); } else { slope[t]++; Max = max(Max, slope[t]); } } ans = max(ans, Max); } if(ans < 4) ans = 0; printf("Photo %d: %d points eliminated\n", ++kase, ans); } return 0;}*/
0 0
- POJ 2737 Swamp Things (斜率判断多点共线)
- POJ2737 Swamp Things
- hdoj 1432 && poj 2606 Lining Up (多点共线)
- POJ4072多点共线问题
- Lining Up-多点共线问题
- POJ 3174--(坐标)找共线
- POJ 1039 Pipe 判断直线与线段相交(规范相交, 非规范相交),没有共线情况
- hdu 5020 求三点共线的组合数(容器记录斜率出现次数)
- UVA 270 Lining Up(多点共线)
- UVA 270-Lining Up(多点共线)
- poj 1118 2606 共线
- [LightOJ 1292] Laser Shot (几何,判断共线)
- POJ 1696 Space Ant (叉积,三点共线)
- 如何判断三点共线
- HDU 4341 判断共线+背包
- lightoj1292Laser Shot【共线判断求共线的最多点数】
- timus 1052. Rabbit Hunt URAL 解题报告 多点共线问题
- POJ 求平面点阵中的最大共线点数系列 (POJ 1118 + 2606 + 2780)
- Codeforces #307 (div2)
- Maximal Rectangle
- Codeforces Round #306 (Div. 2), problem: (A) Two Substrings
- 计算机博弈教程 连载【一. 计算机博弈简史】
- ASCII码表_完整版
- POJ 2737 Swamp Things (斜率判断多点共线)
- 如何为你的Android应用缩放图片
- Implement strStr()
- 刚刚学编程,写一点自己的想法
- linux下LNMP环境搭建
- Android Libraries You Should Use in Every Project
- vmware克隆Centos6.4虚拟机网卡无法启动问题
- Mac OS X网络诊断命令
- ZOJ 1094 Matrix Chain Multiplication