uva-270-排序
题意:很多个点,问,最多有多少个点在同一条直线上
#include <algorithm>
#include <iostream>
#include <string>
#include <stdio.h>
#include <memory.h>
#include <sstream> namespace cc
{
using std::cin;
using std::cout;
using std::endl;
using std::move;
using std::sort;
using std::string;
using std::stringstream; class Point
{
public:
int x, y;
Point(int x, int y) : x(x), y(y) {}
Point() : x(), y() {}
}; const int N = ; double k(int x1, int y1, int x2, int y2)
{
int dy = y1 - y2;
int dx = x1 - x2;
if (dx == )
return ;
return dy * 1.0 / dx;
} void solve()
{
int n;
cin >> n;
getchar();
getchar();
int t = ;
while (n--)
{
if (t != )
cout << endl;
++t;
string str;
int total = ;
Point pp[N];
while (getline(cin, str))
{
if (str.empty())
break;
stringstream strIn;
strIn << str;
int x, y;
strIn >> x >> y;
Point poin(x, y);
pp[total++] = poin;
}
int max = 0x80000000;
for (int base = ; base < total; base++)
{
Point p = pp[base];
double ks[N];
int ki = ;
for (int i = ; i < total; i++)
{
if (i == base)
continue;
double kk = k(pp[base].x, pp[base].y, pp[i].x, pp[i].y);
ks[ki++] = kk;
}
//sort
sort(ks, ks + ki);
int curMax = ;
double s = ks[];
for (int j = ; j < ki; j++)
{
if (ks[j] == s)
++curMax;
else
{
max = max > curMax ? max : curMax;
s = ks[j];
curMax = ;
}
}
max = max > curMax ? max : curMax;
}
cout<<max<<endl;
}
}
} // namespace cc int main()
{
#ifndef ONLINE_JUDGE
freopen("/Users/caicai/in", "r", stdin);
#endif // !ONLINE_JUDGE cc::solve(); #ifndef ONLINE_JUDGE while (true)
;
#endif // !ONLINE_JUDGE
return ;
}
uva-270-排序的更多相关文章
- UVA 270 Lining Up 共线点 暴力
题意:给出几个点的位置,问一条直线最多能连过几个点. 只要枚举每两个点组成的直线,然后找直线上的点数,更新最大值即可. 我这样做过于暴力,2.7s让人心惊肉跳...应该还能继续剪枝的,同一直线找过之后 ...
- UVa 11039 (排序+贪心) Building designing
白书上的例题比较难,认真理解样例代码有助于提高自己 后面的练习题相对简单,独立思考解决问题,增强信心 题意:n个绝对值各不相同的非0整数,选出尽量多的数排成序列,使得该序列正负交错且绝对值递增. 解法 ...
- UVa 270 & POJ 1118 - Lining Up
题目大意:给一些点,找出一条直线使尽可能多的点在这条直线上,求这条直线上点的个数. 以每一个点为原点进行枚举,求其它点的斜率,斜率相同则说明在一条直线上.对斜率排序,找出斜率连续相等的最大长度. #i ...
- UVa 1611 (排序 模拟) Crane
假设数字1~i-1已经全部归位,则第i到第n个数为无序区间. 如果i在无序区间的前半段,那么直接将i换到第i个位置上. 否则先将i换到无序区间的前半段,再将i归位.这样每个数最多操作两次即可归位. # ...
- UVA 270 Lining Up (几何 判断共线点)
Lining Up ``How am I ever going to solve this problem?" said the pilot. Indeed, the pilot was ...
- 我对sobel算子的理解
转自:http://blog.csdn.net/yanmy2012/article/details/8110316 索贝尔算子(Sobeloperator)主要用作边缘检测,在技术上,它是一离散性差分 ...
- Uva 10305 给任务排序
题目链接:https://uva.onlinejudge.org/external/103/10305.pdf 紫书P167 拓扑排序. dfs——从一个点出发,dfs 与之相连的所有点,把本身放入到 ...
- uva 10905 Children's Game (排序)
题目连接:uva 10905 Children's Game 题目大意:给出n个数字, 找出一个序列,使得连续的数字组成的数值最大. 解题思路:排序,很容易想到将数值大的放在前面,数值小的放在后面.可 ...
- POJ 1002 UVA 755 487--3279 电话排序 简单但不容易的水题
题意:给你许多串字符串,从中提取电话号码,输出出现复数次的电话号码及次数. 以下是我艰难的AC历程:(这题估计是我刷的题目题解次数排前的了...) 题目不是很难理解,刚开始想到用map,但stl的ma ...
- UVA 11039-Building designing【贪心+绝对值排序】
UVA11039-Building designing Time limit: 3.000 seconds An architect wants to design a very high build ...
随机推荐
- 禁止ajax访问shiro管理的登录页面
在使用shiro的时候,对于用户权限的管理,相信很多人都已经很熟悉了.今天,我这里简单的记录一下我自己调试过程中遇到的问题.主要是登录的操作,禁止通过ajax的方式进行访问. shiro中,登录过程拒 ...
- MySQL 使用profile分析慢sql,group left join效率高于子查询
MySQL 使用profile分析慢sql,group left join效率高于子查询 http://blog.csdn.net/mchdba/article/details/54380221 -- ...
- python show slave status
#!/usr/bin/env python import MySQLdbimport contextlib @contextlib.contextmanagerdef mysql(Host,Port, ...
- windows服务命令 转载
OnCustomCommand executes when the Service Control Manager (SCM) passes a custom command to the servi ...
- python 类继承与子类实例初始化
From: https://blog.csdn.net/cs0301lm/article/details/6002504?utm_source=blogxgwz4 [ 先贴参考书籍原文(中文英文对照) ...
- python3学习笔记一(标识符、关键字)
查看Python版本 可以命令窗口,windows使用win+R调出cmd运行框,输入以下命令: python -V 进入python的交互编辑模式,也可查看 D:\Python3.6\Scripts ...
- Dubbo(4)消费Dubbo服务
消费就是一个远程调用服务的过程: 1.项目结构: 2.项目依赖pom.xml: <project xmlns="http://maven.apache.org/POM/4.0. ...
- SFINAE简单实例
SFINAE(Substitution failure is not an error),是C++11以来推出的一个重要概念,这里,只是简单举一个例子,可能会有人需要. // 添加 scalar nu ...
- Oracle 表空间的概念
表空间 在数据库系统中,存储空间是较为重要的资源,合理利用空间,不但能节省空间,还可以提高系统的效率和工作性能. Oracle 可以存放海量数据,所有数据都在数据文件中存储.而数据文件大小受操作系 ...
- postgresql小纪
本来是想在PaaS环境中定位PG数据库的问题,却发现给每个PG实例,就是每个库,分配的密码是加密的,还不能直接查看密码. 登录PG数据库对应的容器,发现使用默认的用户postgres没有密码也可以正常 ...