牛客 Fruit Ninja 2018 ACM 上海大都会赛 (随机化算法)
题目链接: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 上海大都会赛 (随机化算法)的更多相关文章
- 2018 ACMICPC上海大都会赛重现赛 H - A Simple Problem with Integers (线段树,循环节)
2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 H - A Simple Problem with Integers (线段树,循环节) 链接:https://ac.nowcoder.co ...
- 2018 ICPC上海大都会赛重现赛 D Thinking-Bear magic (几何)
2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 D Thinking-Bear magic (几何) 链接:https://ac.nowcoder.com/acm/contest/163/ ...
- The 2018 ACM-ICPC上海大都会赛 J Beautiful Numbers (数位DP)
题意:求小于等于N且能被自己所有位上数之和整除的数的个数. 分析:裸的数位dp.用一个三位数组dp[i][j][k]记录:第i位,之前数位之和为j,对某个mod余数为k的状态下满足条件的个数.这里mo ...
- 2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 F Color it
链接:https://www.nowcoder.com/acm/contest/163/F 来源:牛客网 2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 F Color it 时间限制:C ...
- 2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 F Color it (扫描线)
2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 F Color it (扫描线) 链接:https://ac.nowcoder.com/acm/contest/163/F来源:牛客网 时间 ...
- 2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 J Beautiful Numbers (数位DP)
2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 J Beautiful Numbers (数位DP) 链接:https://ac.nowcoder.com/acm/contest/163/ ...
- 2018 ACM 国际大学生程序设计竞赛上海大都会赛
传送门:2018 ACM 国际大学生程序设计竞赛上海大都会赛 2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛2018-08-05 12:00:00 至 2018-08-05 17:00:0 ...
- 2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 A,D
A链接:https://www.nowcoder.com/acm/contest/163/A Fruit Ninja is a juicy action game enjoyed by million ...
- 牛客网 湖南大学2018年第十四届程序设计竞赛重现赛 A game
链接:https://www.nowcoder.com/acm/contest/125/A来源:牛客网 Tony and Macle are good friends. One day they jo ...
随机推荐
- 软件-平面设计-CorelDRAW:CorelDRAW
ylbtech-软件-平面设计-CorelDRAW:CorelDRAW CorelDRAW Graphics Suite是加拿大Corel公司的平面设计软件:该软件是Corel公司出品的矢量图形制作工 ...
- oracle 中和mysql的group_concat有同样作用的写法
所有版本的oracle都可以使用select wm_concat(name) as name from user;但如果是oracle11g,使用select listagg(name, ',') w ...
- 仿flask写的web框架
某大佬仿flask写的web框架 web_frame.py from werkzeug.local import LocalStack, LocalProxy def get_request_cont ...
- Openstack组件部署 — keystone(domain, projects, users, and roles)
目录 目录 前文列表 Create a domain projects users and roles domain projects users and roles的意义和作用 Create the ...
- <读书笔记>《高性能网站建设指南:前端工程师技能精髓》
只有10-20%的最终用户响应时间花在了下载HTML文档上.其余的80-90%时间花在了下载页面中的所有组件上. 规则1.减少HTTP请求 图片地图:将多个图片合并成一个,而后通过css定位显示不同的 ...
- zabbix添加对web页面url的状态监控
zabbix3.0.4添加对web页面url的状态监控 1.应用集配置 在配置—>主机中打开主机列表,选择需要添加监控主机的web,创建应用集 2.web监测配置 选择web场景,再单击右上角的 ...
- # Python第十节 传参
Python第十节 传参 一. 变量和变量名 首先说明变量名和变量的一点差异 例如: var = [1, 2, 3] `var = "Google" 调用变量var的时候, 既可以 ...
- element ui step组件在另一侧加时间轴显示
这是我开发的时候遇到的一个问题:项目需要在步骤条(竖直方向)的另一侧加时间显示,但是我在element ui 的step组件中一直没找着设置方法,所以就自己想了个办法加进来,效果如下: 代码如下,先上 ...
- 学习笔记-es5新增的一些数组的API(不全)-字符串-字符串API(不全)
### es5新增的数组的api + indexOf() 搜索数组中的元素,并返回它所在的位置. arr.indexOf(str,index) 参数: str为要查找的字符串 index为开始查找的下 ...
- navigator对象-了解
navigator 对象包含有关浏览器的信息,它有很多属性,我们最常用的是 userAgent ,该属性可以返回由客户机发送服务器的 user-agent 头部的值 下面前段代码可以判断用户使用哪个终 ...