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 ...
随机推荐
- webservice 项目中遇到的问题
redshift database 连接异常 解决方案 url 修改添加参数如下 jdbc:redshift://hostname:5439/dbname?ssl=true&sslfactor ...
- php中inset 和 和 empty 的区别
inset函数 用途:检测变量是否设置判断:检测变量是否设置,并且不是 NULL.如果已经使用 unset() 释放了一个变量之后,它将不再是 isset().若使用 isset() 测试一个被设置成 ...
- SpringBoot系列: Eclipse+Maven环境准备
这个链接比我写得更全面, http://tengj.top/2018/01/01/maven/ =============================20190115补充: maven 的一些插件 ...
- 让overflow:auto页面滚动条出现时不跳动
今天看到一篇张鑫旭的文章,转载过来.https://www.zhangxinxu.com/wordpress/2015/01/css-page-scrollbar-toggle-center-no-j ...
- 本地测试使用Tomcat,生产环境使用GlassFish。
总结:Tomcat8 = javaee7规范(servlet3.1 + jsp2.3 + el3.0 + websocket1.0) + java7 [配置初始化参数使用jdk8编译]conf/web ...
- MySQL api
今天看去年年中写的代码,留意到一个关键时刻能提高效率的api:on duplicate key update: 语法: INSERT INTO INSERT INTO g_iot_user_build ...
- cocos2dx 屏幕分辨率
http://cn.cocos2d-x.org/article/index?type=cocos2d-x&url=/doc/cocos-docs-master/manual/framework ...
- 使用Python的turtle库画圣诞树
代码如下: from turtle import * import random import time n = 80.0 speed("fastest") screensize( ...
- Linux下运行jmeter
• 我们在做测试的时候,有时候要运行很久,公司用的测试服务器一般都是linux,就可以运行在linux下面,linux下面不能像windows一样有图形化界面,那怎么运行脚本呢,就先在windows上 ...
- Python11 RabbitMQ Redis
本节内容 1.RabbitMQ 2.Redis RabbitMQ队列 安装 http://www.rabbitmq.com/install-standalone-mac.html 安装python r ...