题目链接: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. 不是有效的win32应用程序

    问题描述: 用vs2012编写的程序在xp下运行提示"不是有效的win32应用程序", 改成静态编译还是会提示上面的错误 解决办法: 原来常规里面的平台工具集的设置如上,更改为下面 ...

  2. java并发编程笔记(一)——并发编程简介

    java并发编程笔记(一)--简介 线程不安全的类示例 public class CountExample1 { // 请求总数 public static int clientTotal = 500 ...

  3. python作业/练习/实战:2、注册、登录(文件读写操作)

    作业要求 1.实现注册功能输入:username.passowrd,cpassowrd最多可以输错3次3个都不能为空用户名长度最少6位, 最长20位,用户名不能重复密码长度最少8位,最长15位两次输入 ...

  4. jmeter压测、操作数据库、分布式、 linux下运行的简单介绍

    一.jmeter压测 1.如何压测 常规性能压测:10-15分钟 稳定性测试:一周.2天等 如果想要压测10分钟,勾选永远,勾选调度器,填写600秒.也可以使用固定启动时间. 2.tps.响应时间 ( ...

  5. mybatis之返回值总结

    mybatis框架让我们能在编程中只需要编写一个接口,然后再编写mapper映射文件,无需编写接口的实现类就可以实现从数据库检索数据.这是mybatis通过动态代理,把mapper映射文件的内容转化为 ...

  6. tushare下载安装教程与版本更新步骤

    使用前提 安装Python 安装pandas:pip install pandas 安装lxml:pip install lxml 下载安装 方式1:pip install tushare,如果安装网 ...

  7. iView的page 组件

    //html <div class="pageNation"> <Page :total= totalPages :page-size= pageSize siz ...

  8. android meta_data配置数据

  9. stdio - 标准输入输出库函数

    SYNOPSIS 总览 #include <stdio.h> FILE *stdin; FILE *stdout; FILE *stderr; DESCRIPTION 描述 标注 I/O ...

  10. linux - sftp, scp, rz, sz(文件传输命令)

    1. sftp Secure Ftp 是一个基于SSH安全协议的文件传输管理工具.由于它是基于SSH的,会在传输过程中对用户的密码.数据等敏感信息进行加密,因此可以有效的防止用户信息在传输的过程中被窃 ...