Finding Lines UVALive - 6955(随机)
给出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(随机)的更多相关文章
- 随机算法 - HNU 13348 Finding Lines
Finding Lines Problem's Link: http://acm.hnu.cn/online/?action=problem&type=show&id=13348&am ...
- Finding Lines
Finding Lines 题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8& ...
- UVALive - 6955 Finding Lines 随机算法
题目链接: http://acm.hust.edu.cn/vjudge/contest/126968#problem/F 题意 给你n个点,问是否有>=p/100*n个点共线(p>=20& ...
- UVALive 6955 Finding Lines(随机化优化)题解
题意:问你是否有一条直线满足这条直线上的点个数与总个数之比不小于p 思路:解法太暴力了,直接随机取两个数,如果能满足条件就输出可以,否则不行.证明一下为什么可以随机化,题目给出可能有P >=20 ...
- 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 ...
- java随机生成验证码
package com.yuyuchen.util; import java.awt.Color; import java.awt.Font; import java.awt.Graphics; im ...
- Gym101482 NWERC 2014(队内训练第4场)
-----------------------前面的两场感觉质量不高,就没写题解----------------------------- A .Around the Track pro:给定内多边形 ...
- Gym 101482 题解
B:Biking Duck 题意:现在有一个人要从(x1,y1)点走到(x2,y2)点, 现在走路的速度为v. 还有骑自行车的速度v2,自行车要从某个自行车站到另一个自行车站,现在我们可以视地图的边界 ...
- ImageUtil(验证码数据生成工具类)
登录界面时,常常会使用到验证码图片生成,程序如下: package util; import java.awt.Color; import java.awt.Font; import java.awt ...
随机推荐
- Redis教程(Linux)
这里汇总了从简单的安装到较为复杂的配置,由浅入深的学习redis... 一 , 安装 1) redis扩展安装 从官网上下载扩展压缩包 wget http://pecl.php.net/get/red ...
- springboot注解@SpringBootApplication分析
@SpringBootApplication注解用在Spring Boot的入口类上面,是Spring Boot提供的应用启动相关的注解. 直接上注解的源码: @Target(ElementType. ...
- [转帖]Centos7 yum安装Chrome浏览器
Centos7 yum安装Chrome浏览器 https://www.cnblogs.com/ianduin/p/8727333.html以及https://blog.csdn.net/libaine ...
- MySQL5.5 安装配置方法教程
MySQL下载地址:http://dev.mysql.com/downloads/installer/ 1.首先进入的是安装引导界面 2.然后进入的是类型选择界面,这里有3个类型:Typical(典型 ...
- NOIP2015提高组复赛B 子串
题目链接:https://ac.nowcoder.com/acm/contest/263/B 题目大意: 略 分析: 设preA(i)为字符串A中第1个字符到第i个字符构成的字符串. 设preB(i) ...
- mysql逻辑架构
逻辑架构图 MySQL有点与众不同,它的逻辑架构可以在多种不同的场景中应用并发挥良好的作用.主要体现在存储引擎的架构上,插件式的存储引擎架构将查询处理和其他的系统任务以及数据的存储提取相分离.这种架构 ...
- kprobe原理解析
参考 http://www.cnblogs.com/honpey/p/4575928.html kprobe是linux内核的一个重要特性,是一个轻量级的内核调试工具,同时它又是其他一些更高级的内核 ...
- $mount(“#app”)手动挂载
没有el属性时,证明vue还没绑定到特定的dom上,需要延迟加载,则使用.$mount("")进行手动挂载 https://blog.csdn.net/longzhoufeng/a ...
- Spring Boot 构建电商基础秒杀项目 (四) getotp 页面
SpringBoot构建电商基础秒杀项目 学习笔记 BaseController 添加 public static final String CONTENT_TYPE_FORMED = "a ...
- c提取文件路径、文件名和后缀名
/* MAKEPATH.C */ #include <stdlib.h> #include <stdio.h> void main( void ) { char path_bu ...