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 ...
随机推荐
- jQuery自定义扩展写法
jQuery自定义扩展有两种写法: $.extend({}) ; 调用方法: $.方法 $.fn.extend({}); 调用方法: ...
- xe5 android 手机上使用sqlite [转]
在android手机上怎样使用sqlite数据库,这里用Navigator实现 增删改查. 1.新建firemonkey mobile application 2.选择blank applicatio ...
- Mysql 性能优化5【重要】数据库结构优化
数据库设计的步骤 我们大多使用mysql 设计三范式 设置时区
- linux svn客户端通过 https访问windows VisualSVN Server Manager
1)需求: 已经在阿里云windwos系统 下面安装了VisualSVN Server Manager 做为svn服务器: 现在要在腾讯云源码安装新版本客户端 2)开始源码编译安装TortoiseSV ...
- vlan交换机的端口模式有哪几种
一 端口类型1 ,Access用户模式2 ,Trunk链路模式3 ,Hybrid模式(跟Trunk很类似但比trunk高级)二 端口介绍2.1 ,Access类型端口:只允许默认vlan的以太网帧,也 ...
- 基于单片机的Wifi温度湿度测量仪
这次的制作背景是由于单片机课程实训课程要求 刚好手上有块ESP8266-12F的WiFi模块 于是就选择了制作一个基于单片机,使用WiFi传输数据的温湿度采集测量仪 制作过程: 由于有使用过WiFi模 ...
- 【nosql】之ehcache.xml文件属性描述
<ehcache updateCheck="false" name="shiroCache"> <defaultCache <!--最大 ...
- [转][CentOS]修改IP后立即生效
来自:http://bbs.51cto.com/thread-789908-1.html Linux系统里修改IP地址后该如何使之即刻生效,有两种方法可以解决: (1) sudo ifdown eth ...
- web前端开发浅析
原文地址:http://www.cnblogs.com/babyzone2004/articles/1807381.html 摘 要:前端开发作为一项新的领域,经历的时间随然较短,却显示了强大的生命里 ...
- 在Ubuntu16.04下面安装asterisk网络电话交换机服务器
在Ubuntu下面需要安装 apt install libncurses5-dev uuid-dev libjansson-dev libxml2-dev libsqlite3-dev 去官网下载包h ...