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 ...
随机推荐
- Vmware的虚拟机示例进入BIOS方法
虚拟机(Vmware)怎么进入BIOS_百度经验 https://jingyan.baidu.com/article/7e440953e566472fc0e2eff7.html Vmware虚拟机进入 ...
- Python + selenium + pycharm 环境部署细节 和selenium、Jenkins简单介绍
一.测试体系:Python + selenium + pycharm + Jenkins/docker 环境搭建: 1.安装python 3.4/3.5 2/3.6/ 3.7 2.配置环境变量 3.p ...
- php trait使用
trait类似于基类 同样的方法优先级为 本类>trait>基类 <?php /** * Created by PhpStorm. * User: mac * Date: 2019 ...
- 6-2 Verbs and Adjectives with that clauses
1 Many sentences in English contain two clauses: a main clause and a "that" clause. The &q ...
- Linux 查找文件命令 find whereis locate
Linux 有三个查找文件的命令:find, whereis, locate 其中find 不常用,whereis与locate经常使用,因为find命令速度较慢,因为whereis与locate是利 ...
- IDEA将项目上传至码云/GitHub托管
怎么将本地的项目放到码云或者GitHub去托管了?(以码云为例) 一.创建远程项目 第一步:点击创建项目 第二步:填写项目相关信息 第三步:复制远程的项目地址,注意:此处码云官方已经给出上传项目方法, ...
- golang操作mysql使用总结
前言 Golang 提供了database/sql包用于对SQL数据库的访问, 作为操作数据库的入口对象sql.DB, 主要为我们提供了两个重要的功能: sql.DB 通过数据库驱动为我们提供管理底层 ...
- keyvalue对RDD s
scala> val input =sc.textFile("/home/simon/SparkWorkspace/test.txt")input: org.apache.s ...
- Python模拟wc命令(软件测试第二次作业)
Python实现字符,单词,行,代码行,空行及可视化 Gitee项目地址:https://gitee.com/biubiubiuLYQ/word_and_character_statistics 一. ...
- eclipse 基础快捷键。
批量修改:Alt+Shift+R 查看java源码:1.选中方法,比如System.out.println()的 println 2.F3 代码格式化:ctrl+shift+f (注意: 这个快捷键和 ...