Find Lines
(Uva 6955可以直接随机,湖大OJ 13348 要优化)
题意:给出 n个点的坐标, 一个 百分数p, 求是否有一条直线上有 n * p /100个点…
随机化算法,但也要优化下……(TLE, WA到底…)
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<stack>
//#include<bits/std c++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const LL MOD = 1e7 + ;
const LL maxn = 1e5 + ;
int gcd(int a,int b) { return b == ? a : gcd(b, a % b); }
unsigned int Rand() { static unsigned seed = ; return seed = seed * + ;}
struct Line {
long long a,b,c;
Line() {}
Line(int a1,int b1,int a2,int b2) {
int g = gcd(abs(a1 - a2),abs(b1 - b2));
if(a1 - a2 < ) g = -g;
a = -(b1-b2)/g;
b = (a1-a2) / g;
c = a*a1 + b*b1;
}
bool operator < (Line s) const { return (a < s.a || (a == s.a && (b < s.b || (b == s.b && c < s.c))));}
};
map<Line,int> L;
map<Line,int>::iterator it;
int X[], Y[];
int main() {
int n,p;
scanf("%d%d",&n,&p);
L.clear();
if(n == ) {
printf("possible\n");
return ;}
int limit = n * p;
for(int i = ; i < n; ++i) scanf("%d%d",&X[i],&Y[i]);
for(int t = ; t < ; ++t) { //先随机处理去重 + 统计次数
int a = Rand() % n, b = Rand() % n;
while(a == b) b = Rand() % n;
L[Line(X[a],Y[a],X[b],Y[b])]++;
}
for(it = L.begin(); it != L.end(); ++it)
{
if(it->second < ) continue;//随机1000次,在线上的点应该要出现一定次数 1/25 * 1000, 20保险,然而30 40 WA了...
int num = ; //简直拼人品.......
long long a = it->first.a, b = it->first.b, c = it->first.c;
for(int i = ; i < n; ++i) {
if(a*X[i] + b*Y[i] == c) {
num++;
if(num * >= limit) {
printf("possible\n");
return ;
}
}
}
}
printf("impossible\n");
return ;
}
Find Lines的更多相关文章
- extracting lines bases a list using awk
extracting lines bases a list using awk awk 'NR==FNR{a[$1]=$0; next}($1 in a){print a[$1]"\n&qu ...
- Enum:Game of Lines(POJ 3668)
画直线 题目大意:给定一些点集,要你找两点之间的连线不平行的有多少条 数据量比较少,直接暴力枚举,然后放到set查找即可 #include <iostream> #include < ...
- 我的常用mixin 之 lines
/** * 最多显示 $lineCount 行 * lines * * example: * @include lines; * @include lines(3); */ @mixin lines( ...
- uva 1471 defence lines——yhx
After the last war devastated your country, you - as the king of the land of Ardenia - decided it wa ...
- POJ 1269 Intersecting Lines --计算几何
题意: 二维平面,给两条线段,判断形成的直线是否重合,或是相交于一点,或是不相交. 解法: 简单几何. 重合: 叉积为0,且一条线段的一个端点到另一条直线的距离为0 不相交: 不满足重合的情况下叉积为 ...
- POJ 1269 Intersecting Lines【判断直线相交】
题意:给两条直线,判断相交,重合或者平行 思路:判断重合可以用叉积,平行用斜率,其他情况即为相交. 求交点: 这里也用到叉积的原理.假设交点为p0(x0,y0).则有: (p1-p0)X(p2-p0) ...
- [CareerCup] 13.1 Print Last K Lines 打印最后K行
13.1 Write a method to print the last K lines of an input file using C++. 这道题让我们用C++来打印一个输入文本的最后K行,最 ...
- Codeforces 593B Anton and Lines
LINK time limit per test 1 second memory limit per test 256 megabytes input standard input output st ...
- 简单几何(直线位置) POJ 1269 Intersecting Lines
题目传送门 题意:判断两条直线的位置关系,共线或平行或相交 分析:先判断平行还是共线,最后就是相交.平行用叉积判断向量,共线的话也用叉积判断点,相交求交点 /********************* ...
- 【POJ】1269 Intersecting Lines(计算几何基础)
http://poj.org/problem?id=1269 我会说这种水题我手推公式+码代码用了1.5h? 还好新的一年里1A了---- #include <cstdio> #inclu ...
随机推荐
- row_number()over()使用
语法: ROW_NUMBER ( ) OVER ( [ PARTITION BY value_expression , ... [ n ] ] order_by_clause ) 通过语法可以看出 o ...
- ubuntu主题收集
ubuntu主题收集 一些cmd常用命令: 任务栏底部,进入Dash并打开终端,命令最后一个是参数可选 ( Left | Bottom ) gsettings set com.canonical.Un ...
- Silverlight网页打开后马上崩溃,“白屏”,而且毫无提示
如题,出现白屏的问题 在Application_UnhandledException函数内,跟踪异常e的提示信息,可以了解到如下信息: at System.ComponentModel.AsyncCo ...
- Web服务调试可用,发布之后访问出错
今天重装了系统,然后发现之前的Web服务DataService不能用了.将其设置为启动项,运行的结果是 跟踪发现,是mysql.data.dll的版本不对.所以要找到所有版本不对的该dll,将其替换成 ...
- Spark 整合ElasticSearch
Spark 整合ElasticSearch 因为做资料搜索用到了ElasticSearch,最近又了解一下 Spark ML,先来演示一个Spark 读取/写入 ElasticSearch 简单示例. ...
- 一个不错的Html5 DatePicker控件,主要支持手机端。
原地址不知道在哪了,下载地址 QQ群:616945527 Html5控件wen文件夹中DatePicker.rar
- 1、PHP入门二维数组与循环
<?php $two=array(array(2,3),1=>array(1,2,3),2=>array(4,5,6)); echo $two[1][0];//输出1 echo $t ...
- VS 在文件中查找替换界面死掉。
主要问题时一个CopyAndReplace的插件引起的.卸载掉就没问题了.
- 【LDAP】LDAP注入漏洞与防御
0x01 前言 前两天爆了一个LDAP漏洞,据说存在了8年现在才被发现,感概一下,不知这8年来有多少站被搞了... 想着复现这个漏洞,就先复习一下LDAP注入的相关知识吧,差了很多资料,记一下笔记. ...
- IDApython教程(一)
IDAPython是IDA的一个功能强大的扩展特性,对外提供了大量的IDA API调用.另外,还能在使用python 脚本语言的过程中获得能力提升,所以我强烈推荐所有的逆向工程师使用它. 然而不幸的是 ...