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 ...
随机推荐
- centos 检测aufs 并安装
http://www.cnblogs.com/logo-fox/p/7366506.html 因为DeviceMapper不稳定,所以必须升级到3.10以上的内核,运行docker(2.6提示运行do ...
- 开发工具之Sublime编辑器
sublime是一款轻量级的编辑器,可以从官网上进行下载最新版本.它有很多使用并且强大的功能支持.例如:GOTO,package 等快捷操作.但有时候下载的版本不能进行安装package contro ...
- js数据放入缓存,需要再调用
再贴代码之前先描述下,这个技术应用的场景:一个页面的http请求次数能少点就少,这样大大提高用户体验.所以再一个页面发起一个请求,把所有数据都拿到后储存在缓存里面,你想用的时候再调用出来,这个是非常好 ...
- vue二次实战
vue爬坑之路 npm uninstall 模块名(删除指定模块) https://www.cnblogs.com/wisewrong/p/6255817.html vue快速入门 https://s ...
- Day 3-5 装饰器
开放-封闭原则: 封闭:已实现的功能代码块不应该被修改. 开放:对现有功能的扩展开放. 装饰器: 定义:在符合'开放-封闭'的原则下,给程序扩展其他的功能! 例:在不更改tokyo函数的情况下.给to ...
- Guava Cache源码详解
目录 一.引子 二.使用方法 2.1 CacheBuilder有3种失效重载模式 2.2 测试验证 三.源码剖析 3.1 简介 3.2 源码剖析 四.总结 优点: 缺点: 正文 回到顶部 一.引子 缓 ...
- 集合之HashSet(含JDK1.8源码分析)
一.前言 我们已经分析了List接口下的ArrayList和LinkedList,以及Map接口下的HashMap.LinkedHashMap.TreeMap,接下来看的是Set接口下HashSet和 ...
- Yii2总结
1. Web访问流程(即在浏览器中输入一个网址至浏览器展现页面结果的过程) a. 将输入的网址提取出域名,在本地hosts文件中查找对应的IP地址(windows为C:/windows/system3 ...
- JSP从入门到精通
1. jsp开发环境配置 在windows下配置jsp的开发环境: 假设已经安装好了jdk,下面来配置tomcat 去http://tomcat.apache.org 下载tomcat windows ...
- Armstrong公理
从已知的一些函数依赖,可以推导出另外一些函数依赖,这就需要一系列推理规则,这些规则常被称作“Armstrong 公理”. 设U 是关系模式R 的属性集,F 是R 上成立的只涉及U 中属性的函数依赖集. ...