给出n个点,问你有没有可能存在一条直线,这n个点中存在百分号p以上点在这条直线上。

两个点确定一条直线,所以可以随机枚举两个点,然后用这条直线去判断其他的点是不是在这条直线上,如果在这个直线上的点超过%p,那么就说明找到了一种情况

#include<map>
#include<set>
#include<ctime>
#include<cmath>
#include<stack>
#include<queue>
#include<string>
#include<vector>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define lowbit(x) (x & (-x))
#define INOPEM freopen("in.txt", "r", stdin)
#define OUTOPEN freopen("out.txt", "w", stdout) typedef unsigned long long int ull;
typedef long long int ll;
const double pi = 4.0*atan(1.0);
const int inf = 0x3f3f3f3f;
const int maxn = 1e5+;
const int maxm = ;
const int mod = 1e9+;
using namespace std; int n, m;
int T, tol;
struct Node {
ll x, y;
};
Node node[maxn]; int check(int i, int j, int k) {
ll ans1 = (node[i].x - node[j].x) * (node[i].y - node[k].y);
ll ans2 = (node[i].x - node[k].x) * (node[i].y - node[j].y);
if(ans1 == ans2) return ;
else return ;
} //x1-x2 x1-x3
//y1-y2 y1-y3 int main() {
srand(time());
while(~scanf("%d%d", &n, &m)) {
memset(node, , sizeof node);
for(int i=; i<n; i++) scanf("%lld%lld", &node[i].x, &node[i].y);
if(n <= ) {
printf("possible\n");
continue;
}
int ans = n*m;
bool flag = false;
for(int T=; T<=; T++) {
int sum = ;
int x = rand() % n;
int y = rand() % n;
while(x == y) y = rand() % n;
for(int i=; i<n; i++) {
if(i == x || i == y) continue;
sum += check(x, y, i);
if(sum * >= ans) {
flag = true;
break;
}
}
if(flag) break;
}
printf("%s\n", flag ? "possible" : "impossible");
}
return ;
}

Finding Lines UVALive - 6955(随机)的更多相关文章

  1. 随机算法 - HNU 13348 Finding Lines

    Finding Lines Problem's Link: http://acm.hnu.cn/online/?action=problem&type=show&id=13348&am ...

  2. Finding Lines

    Finding Lines 题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8& ...

  3. UVALive - 6955 Finding Lines 随机算法

    题目链接: http://acm.hust.edu.cn/vjudge/contest/126968#problem/F 题意 给你n个点,问是否有>=p/100*n个点共线(p>=20& ...

  4. UVALive 6955 Finding Lines(随机化优化)题解

    题意:问你是否有一条直线满足这条直线上的点个数与总个数之比不小于p 思路:解法太暴力了,直接随机取两个数,如果能满足条件就输出可以,否则不行.证明一下为什么可以随机化,题目给出可能有P >=20 ...

  5. Educational Codeforces Round 41 (Rated for Div. 2) D. Pair Of Lines (几何,随机)

    D. Pair Of Lines time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...

  6. java随机生成验证码

    package com.yuyuchen.util; import java.awt.Color; import java.awt.Font; import java.awt.Graphics; im ...

  7. Gym101482 NWERC 2014(队内训练第4场)

    -----------------------前面的两场感觉质量不高,就没写题解----------------------------- A .Around the Track pro:给定内多边形 ...

  8. Gym 101482 题解

    B:Biking Duck 题意:现在有一个人要从(x1,y1)点走到(x2,y2)点, 现在走路的速度为v. 还有骑自行车的速度v2,自行车要从某个自行车站到另一个自行车站,现在我们可以视地图的边界 ...

  9. ImageUtil(验证码数据生成工具类)

    登录界面时,常常会使用到验证码图片生成,程序如下: package util; import java.awt.Color; import java.awt.Font; import java.awt ...

随机推荐

  1. react插件包

    react-scoped-style support ie8,ie8+,chrome,firefox,safari does not support css priority (just apply ...

  2. C#Note13:如何在C#中调用python

    前言 IronPython 是一种在 .NET 及 Mono上的 Python 实现,由微软的 Jim Hugunin(同时也是 Jython 创造者) 所发起,是一个开源的项目,基于微软的 DLR ...

  3. css3的clip-path方法剪裁实现

    本例讲解如何通过clip-path把一个div(元素,可以是图片等)裁切成不同的形状,这里以一个div为例宽高均为300px 注意:不支持IE和Firefox,支持webkit浏览器,在现代浏览器中需 ...

  4. echo "" > 和 echo "" >> 的区别

    在写shell脚本中,如果判断一个文件已经存在,但希望重写这个文件,一般用如下方式 echo "" > file.txt 这个表示清空文件的内容,如果使用 echo “” & ...

  5. comparable和comparator

    Comparable Comparable可以认为是一个内部比较器,实现了Comparable接口的类有一个特点,就是这些类是可以和自己比较的,在compareTo方法中指定具体的比较方法. comp ...

  6. css元素选择器

    css的元素选择器就是html的标签名:

  7. solr配置ik中文分词(二)

    上一篇文章主要介绍了solr的安装与配置,这篇文章主要记录如何使用ik分词器对中文进行分词. 步骤: 1.下载ik分词jar包:ik-analyzer-solr5-5.x.jar. 2.将下载的jar ...

  8. Lambda表达式Contains方法(等价于SQL语句中的like)使用注意事项

    貌似已经半年多没写一篇帖子了,充分的说明要么老总一天折腾的让人心齐疲惫,没心情去写:要么另外一种可能就是自己不思进取,说白了就是懒.好在这种状态在今天被打破了.MoNey加油. 众所周知,想在Enti ...

  9. hdu-5536(字典树)

    题意:给你n个数,让你在n个数中选三个,使得(a1+a2)^a3的值最大,a1!=a2!=a3(下标不等于): 解题思路:01字典树可以写,因为数据小,我们可以先把n个数建一颗字典树,然后两边for找 ...

  10. hdu-1238(kmp+枚举)

    题意:给你n个字符串,问你这里面最长的公共子串的长度是多少,一个公共子串的反串也算,比如样例二: 解题思路:随便找一个字符,枚举它的子串然后跑kmp就行了,很多人的博客都是用string类里面的函数来 ...