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 ...
随机推荐
- Python开发【第四篇】:运算符
1. 算术运算符 算术运算符包括+.-.*./.%.//.**,即加减乘除,取余,取商(地板除法)以及幂运算. >>> 5 + 2 7 >>> 5 - 2 ...
- vue路由守卫
路由守卫 //路由进来之时 beforeRouteEnter(to, from, next) { console.log(this, 'beforeRouteEnter'); // undefined ...
- Unity3D 自动添加Fbx Animation Event
http://blog.csdn.net/aa20274270/article/details/52528449 using UnityEngine; using System.Collections ...
- 数据库性能分析 慢查询 profile工具
- 利用Hough变换识别图像中的直线
引入 近期看到2015年数学建模A题太阳影子定位中的第四问,需要根据附件中视频里的直杆的太阳影子的变化确定拍摄地点.其实确定拍摄地点这个问题并不是十分困难,因为有前三问的铺垫,我们已经得出了太阳影子长 ...
- M-HJ浇花
题目描述: 链接:https://ac.nowcoder.com/acm/contest/322/M来源:牛客网 HJ养了很多花(99999999999999999999999999999999999 ...
- Java 数字数组随机数工具类 NumberUtils、ArrayUtils、RandomUtils用法
commons-lang3-3-3.8.1 //----------------------------------------------------------------------- /** ...
- 在Unity3d中解析Lua脚本的方法
由于近期项目中提出了热更新的需求,因此本周末在Lua的陪伴下度过.对Lua与Unity3d的搭配使用,仅仅达到了一个初窥门径的程度,记录一二于此.水平有限,欢迎批评指正. 网络上关于Lua脚本和Uni ...
- vuejs vue-resource post方式提交参数PHP $_POST获取不到
- Js中的字符串/数组中常用的操作
JS为每种数据类型都内置很多方法,真的不好记忆,而且有些还容易记混,现整理如下,以便以后查看: 一.String ①charAt()方法用于返回指定索引处的字符.返回的字符是长度为 1 的字符串. 语 ...