Fruit Ninja(取随机数)
链接:https://www.nowcoder.com/acm/contest/163/A
来源:牛客网
空间限制:C/C++ 262144K,其他语言524288K
64bit IO Format: %lld
题目描述
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
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≤ T ≤ 100), which stands for the number of test cases you need to solve.
The first line of each case contains an integer N (1 ≤ N ≤ 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".
输入例子:
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
-->
输出
Yes
No
思路:暴力必定超时,所以以取随机数的方式确定两个端点,然后从1到n枚举,看有多少个点在这条直线上,将此过程重复120次即可!
AC代码:
#include <bits/stdc++.h>
using namespace std;
int t,n,m,sum,x,y;
double k;
bool flag;
struct record
{
int x,y;
};
record stu[];
int main()
{
scanf("%d",&t);
while(t--)
{
scanf("%d %lf",&n,&k);
for(int i=; i<=n-; i++)
{
scanf("%d %d",&stu[i].x,&stu[i].y);
}
if(n<=)
{
printf("Yes\n");
continue;
}
m=;
flag=false;
while(m--)
{
y=rand()%n;
x=rand()%n;
if(x==y) continue;
sum=;
for(int i=; i<=n-; i++)
{
if(i==y || i==x)
{
continue;
}
if((stu[i].y-stu[y].y)*(stu[i].x-stu[x].x)==(stu[i].y-stu[x].y)*(stu[i].x-stu[y].x))
{
sum++;
}
}
if((double)(sum)/n>=k)
{
flag=true;
break;
}
}
if(flag==true) printf("Yes\n");
else printf("No\n");
}
return ;
}
Fruit Ninja(取随机数)的更多相关文章
- sdut 2416:Fruit Ninja II(第三届山东省省赛原题,数学题)
Fruit Ninja II Time Limit: 5000MS Memory limit: 65536K 题目描述 Have you ever played a popular game name ...
- SDUT 2416:Fruit Ninja II
Fruit Ninja II Time Limit: 5000MS Memory limit: 65536K 题目描述 Have you ever played a popular game name ...
- hdu 4000 Fruit Ninja 树状数组
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4000 Recently, dobby is addicted in the Fruit Ninja. ...
- Sdut 2416 Fruit Ninja II(山东省第三届ACM省赛 J 题)(解析几何)
Time Limit: 5000MS Memory limit: 65536K 题目描述 Haveyou ever played a popular game named "Fruit Ni ...
- hdu 4620 Fruit Ninja Extreme
Fruit Ninja Extreme Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Othe ...
- Fruit Ninja(树状数组+思维)
Fruit Ninja Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- hdu4620 Fruit Ninja Extreme
Fruit Ninja Extreme Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- Fruit Ninja(随机数rand())
链接:https://www.nowcoder.com/acm/contest/163/A来源:牛客网 题目描述 Fruit Ninja is a juicy action game enjoyed ...
- Fruit Ninja
Fruit Ninja 时间限制:C/C++ 5秒,其他语言10秒 空间限制:C/C++ 262144K,其他语言524288K 64bit IO Format: %lld 题目描述 Fruit Ni ...
随机推荐
- Django 之验证码实现
1. django-simple-captcha 模块 安装 django-simple-captcha pip install django-simple-captcha pip install P ...
- jQuery 操作select 下拉列表
jQuery这个框架方便了我们对于HTML元素的操作,本来以为自己对于Select操作也算是熟悉了,但上午在测试的时候才发现自己了解的还真不多. 看了一下jQuery的一些方法后,理出了一些常用的方法 ...
- 2017-9-14 NOIP模拟赛
送分题 (songfen)e Time Limit: 10 00ms y Memory Limit:128MB题目描述LYK 喜欢干一些有挑战的事, 比如说求区间最大子段和. 它知道这个题目有 O(n ...
- 洛谷P3003 [USACO10DEC]苹果交货Apple Delivery
P3003 [USACO10DEC]苹果交货Apple Delivery 题目描述 Bessie has two crisp red apples to deliver to two of her f ...
- poj2241 The Tower of Babylon
The Tower of Babylon 题意:给你n种石头,长x,宽y,高z,每种石头数目无限,一块石头能放到另一块上的条件是:长和宽严格小于下面的石头.问叠起来的最大高度. /* 有些类似“叠箱子 ...
- oralce9i部署安装
为什么还学习oracle9i,因为目前大多数企业的数据依然存储在oracle9i上面,对于数据升级存在很大风险,因此在学习oralce之前,首先熟悉oracle9i也是很有必要的.现在我们先来学习or ...
- python之is 和 == 的区别//编码和解码
一.is 和 == 的区别: 1 .id() 内存地址 2. == 比较 #比较两边的值 3. is 比较 #比较的是内存地址 数字,字符串,有小数据池 #数字小 ...
- 事务&数据库连接池&DBUtils
事务的特性 原子性 指的是 事务中包含的逻辑,不可分割. 一致性 指的是 事务执行前后.数据完整性 隔离性 指的是 事务在执行期间不应该受到其他事务的影响 持久性 指的是 事务执行成功,那么数据应该持 ...
- Hive_Hive的数据模型_汇总
体系结构: 元数据 /HQL的执行安装: 嵌入 /远程 /本地管理: CLI /web界面 /远程服务数据类型: 基本 /复杂 /时间数据模型: 数据存储 /内部表 /分区表 /外部表 /桶表 /视图 ...
- angular4和asp.net core 2 web api
angular4和asp.net core 2 web api 这是一篇学习笔记. angular 5 正式版都快出了, 不过主要是性能升级. 我认为angular 4还是很适合企业的, 就像.net ...