题目链接:Fruit Ninja

比赛链接:2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛

题目描述

Fruit Ninja is a juicy action game enjoyed by millions of players around the world, with squishy,

splat and satisfying fruit carnage! Become the ultimate bringer of sweet, tasty destruction with every slash.

Fruit Ninja is a very popular game on cell phones where people can enjoy cutting the fruit by touching the screen.

In this problem, the screen is rectangular, and all the fruits can be considered as a point. A touch is a straight line cutting

thought the whole screen, all the fruits in the line will be cut.

A touch is EXCELLENT if \(\frac{M}{N} \ge x\), (\(N\) is total number of fruits in the screen, \(M\) is the number of fruits that cut by the touch, \(x\) is a real number.)

Now you are given \(N\) fruits position in the screen, you want to know if exist a EXCELLENT touch.

输入描述:

The first line of the input is \(T(1 \le T \le 100)\), which stands for the number of test cases you need to solve.

The first line of each case contains an integer \(N (1 \le N \le 10^4)\) and a real number \(x (0 < x < 1)\), as mentioned above.

The real number will have only 1 digit after the decimal point.

The next \(N\) lines, each lines contains two integers \(x_i\) and \(y_i (-10^9 ≤ x_i,y_i ≤ 10^9)\), denotes the coordinates of a fruit.

输出描述:

For each test case, output "Yes" if there are at least one EXCELLENT touch. Otherwise, output "No".

示例1

输入

  2
5 0.6
-1 -1
20 1
1 20
5 5
9 9
5 0.5
-1 -1
20 1
1 20
2 5
9 9

输出

  Yes
No

题意

给定 \(N\) 个点以及一个实数 \(x\),问是否存在一条直线,直线经过 \(N\) 个点中的 \(M\) 个点,且 \(\frac{M}{N} \ge x\)。

思路

随机化算法

随机取两个点构造直线,比较直线经过的点的个数(斜率相同)是否大于等于 \(N * x\)。

代码

#include <bits/stdc++.h>
using namespace std;
typedef double db;
const int maxn = 1e4 + 10; class Point {
public:
db x, y;
Point(db x = 0, db y = 0) : x(x), y(y) {}
void input() {
scanf("%lf%lf", &x, &y);
}
};
Point p[maxn]; int main() {
int T;
scanf("%d", &T);
while(T--) {
int n;
db x;
scanf("%d%lf", &n, &x);
x *= n;
for(int i = 0; i < n; ++i) {
p[i].input();
}
int flag = 0;
for(int i = 0; i < 1000; ++i) {
int a = rand() % n, b = rand() % n;
while(a == b) a = rand() % n;
db cnt = 2;
for(int j = 0; j < n; ++j) {
if(j == a || j == b) continue;
if((p[j].y - p[a].y) * (p[b].x - p[j].x) == (p[j].x - p[a].x) * (p[b].y - p[j].y)) {
++cnt;
}
}
if(cnt >= x) {
flag = 1;
break;
}
}
if(flag) printf("Yes\n");
else printf("No\n");
}
return 0;
}

牛客 Fruit Ninja 2018 ACM 上海大都会赛 (随机化算法)的更多相关文章

  1. 2018 ACMICPC上海大都会赛重现赛 H - A Simple Problem with Integers (线段树,循环节)

    2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 H - A Simple Problem with Integers (线段树,循环节) 链接:https://ac.nowcoder.co ...

  2. 2018 ICPC上海大都会赛重现赛 D Thinking-Bear magic (几何)

    2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 D Thinking-Bear magic (几何) 链接:https://ac.nowcoder.com/acm/contest/163/ ...

  3. The 2018 ACM-ICPC上海大都会赛 J Beautiful Numbers (数位DP)

    题意:求小于等于N且能被自己所有位上数之和整除的数的个数. 分析:裸的数位dp.用一个三位数组dp[i][j][k]记录:第i位,之前数位之和为j,对某个mod余数为k的状态下满足条件的个数.这里mo ...

  4. 2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 F Color it

    链接:https://www.nowcoder.com/acm/contest/163/F 来源:牛客网 2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 F Color it 时间限制:C ...

  5. 2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 F Color it (扫描线)

    2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 F Color it (扫描线) 链接:https://ac.nowcoder.com/acm/contest/163/F来源:牛客网 时间 ...

  6. 2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 J Beautiful Numbers (数位DP)

    2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 J Beautiful Numbers (数位DP) 链接:https://ac.nowcoder.com/acm/contest/163/ ...

  7. 2018 ACM 国际大学生程序设计竞赛上海大都会赛

    传送门:2018 ACM 国际大学生程序设计竞赛上海大都会赛 2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛2018-08-05 12:00:00 至 2018-08-05 17:00:0 ...

  8. 2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 A,D

    A链接:https://www.nowcoder.com/acm/contest/163/A Fruit Ninja is a juicy action game enjoyed by million ...

  9. 牛客网 湖南大学2018年第十四届程序设计竞赛重现赛 A game

    链接:https://www.nowcoder.com/acm/contest/125/A来源:牛客网 Tony and Macle are good friends. One day they jo ...

随机推荐

  1. scrapy入门实战-爬取代理网站

    入门scrapy. 学习了有这几点 1.如何使用scrapy框架对网站进行爬虫: 2.如何对网页源代码使用xpath进行解析: 3.如何书写spider爬虫文件,对源代码进行解析: 4.学会使用scr ...

  2. TI推出一款强大模拟设计与仿真工具TINA-TI 9.

    德州仪器 (TI) 宣布推出一款基于 SPICE 的强大模拟设计与仿真工具 TINA-TI 9.1.该免费软件程序的最新版本与 7.0 版相比速度平均提高 5 倍,可帮助工程师在无任何节点或器件数量限 ...

  3. 创建线程方法&守护线程

    创建线程方法1. class mythread extends Thread{ 重写run方法 } mythread m=new mythread () 启动:m.start() 创建线程方法2. c ...

  4. A + B Problem II HDU - 1002

    非常简单的大数加法,因为不会Java只能手写大数加法了;博客存一下以后回来看看 #include<bits/stdc++.h> using namespace std; +; char A ...

  5. Vue实现无痕刷新

    一.什么是无痕刷新 在不刷新浏览器的情况下,实现页面的刷新. 传统的刷新页面方式 window.location.reload()原生 js 提供的方法 this.$router.go(0)vue 路 ...

  6. 忘记root密码

    Ubuntu密码恢复的方法如下: 1.重新启动,按ESC键进入Boot Menu,选择recovery mode(一般是第二个选项).2.在#号提示符下用cat /etc/shadow,看看用户名.3 ...

  7. 【目录】mysql 基础篇系列

    随笔分类 - mysql 基础篇系列 mysql 开发基础系列22 SQL Model(带迁移事项) 摘要: 一.概述 与其它数据库不同,mysql 可以运行不同的sql model 下, sql m ...

  8. C# 进制转换(二进制、十六进制、十进制互转) 转载 https://www.cnblogs.com/icebutterfly/p/8884023.html

    C# 进制转换(二进制.十六进制.十进制互转)由于二进制数在C#中无法直接表示,所以所有二进制数都用一个字符串来表示例如: 二进制: 1010 表示为 字符串:"1010" int ...

  9. 喜讯!联诚发创始人龙平芳荣获2019LED行业优秀女企业家称号!联诚发横揽三项大奖!

           2019年12月20日,在深圳大梅沙京基喜来登度假酒店隆重举行“蝶变跨越”慧聪LED显示屏行业品牌盛会颁奖典礼!在来自全国各地的LED显示屏行业协会领导,企业领袖,精英代表以及来自全国各 ...

  10. React 表单元素实例

    代码实例: <!DOCTYPE html> <html lang="zh-cn"> <head> <meta charset=" ...