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 ...
随机推荐
- 细说shiro之七:缓存
官网:https://shiro.apache.org/ 一. 概述 Shiro作为一个开源的权限框架,其组件化的设计思想使得开发者可以根据具体业务场景灵活地实现权限管理方案,权限粒度的控制非常方便. ...
- IDApython教程(四)
前三部分已经验证了用IDAPython能够让工作变的更简单,这一部分让我们看看逆向工程师如何使用IDAPython的颜色和强大的脚本特性. 分析者经常需要面对越来越复杂的代码,而且有时候无法轻易看出动 ...
- list vector map set (转)
List封装了链表,Vector封装了数组, list和vector得最主要的区别在于vector使用连续内存存储的,他支持[]运算符,而list是以链表形式实现的,不支持[]. Vector对于随机 ...
- 广度优先遍历(BFS )(转)
宽度优先搜索(BFS, Breadth First Search)是一个针对图和树的遍历算法.发明于上世纪50年代末60年代初,最初用于解决迷宫最短路径和网络路由等问题. 对于下面的树而言,BFS方法 ...
- form表单post提交的数据格式
1.浏览器行为:Form表单提交 action:url 地址,服务器接收表单数据的地址 method:提交服务器的http方法,一般为post和get name:最好好吃name属性的唯一性 enct ...
- luogu P3250 [HNOI2016]网络
传送门 考虑只有一个询问,怎么使用暴力枚举最快的得到答案.因为要求最大的,所以可以把链按权值从大往小排序,然后往后扫,找到一个没有交的就是答案,直接退出 一堆询问,可以考虑整体二分,先二分一个值\(m ...
- java乱码解决方法
String name = request.getParameter("name"); 乱码解决:String name = new String(request.getParam ...
- IE9浏览器打开开发者工具代码正常执行,反之报错
1.can i use console IE9开发者工具打开时支持console对象,否则报错. 2.由于出现错误 80020101 而导致此项操作无法完成 测试代码 <!DOCTYPE ht ...
- F - Change FZU - 2277 (DFS序+线段树)
题目链接: F - Change FZU - 2277 题目大意: 题意: 给定一棵根为1, n个结点的树. 有q个操作,有两种不同的操作 (1) 1 v k x : a[v] += x, a[v ' ...
- python,关于这个里边的私有方法(private)、保护方法(protected)、公开方法(public)
__foo__: 定义的是特殊方法,一般是系统定义名字 ,类似 __init__() 之类的. _foo: 以单下划线开头的表示的是 protected 类型的变量,即保护类型只能允许其本身与子类进行 ...