链接:https://www.nowcoder.com/acm/contest/163/A
来源:牛客网

时间限制:C/C++ 5秒,其他语言10秒
空间限制:C/C++ 262144K,其他语言524288K
64bit IO Format: %lld

题目描述

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 ≥ 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≤ 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

-->

示例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
思路:暴力必定超时,所以以取随机数的方式确定两个端点,然后从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(取随机数)的更多相关文章

  1. sdut 2416:Fruit Ninja II(第三届山东省省赛原题,数学题)

    Fruit Ninja II Time Limit: 5000MS Memory limit: 65536K 题目描述 Have you ever played a popular game name ...

  2. SDUT 2416:Fruit Ninja II

    Fruit Ninja II Time Limit: 5000MS Memory limit: 65536K 题目描述 Have you ever played a popular game name ...

  3. hdu 4000 Fruit Ninja 树状数组

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4000 Recently, dobby is addicted in the Fruit Ninja. ...

  4. Sdut 2416 Fruit Ninja II(山东省第三届ACM省赛 J 题)(解析几何)

    Time Limit: 5000MS Memory limit: 65536K 题目描述 Haveyou ever played a popular game named "Fruit Ni ...

  5. hdu 4620 Fruit Ninja Extreme

    Fruit Ninja Extreme Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Othe ...

  6. Fruit Ninja(树状数组+思维)

    Fruit Ninja Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  7. hdu4620 Fruit Ninja Extreme

    Fruit Ninja Extreme Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...

  8. Fruit Ninja(随机数rand())

    链接:https://www.nowcoder.com/acm/contest/163/A来源:牛客网 题目描述 Fruit Ninja is a juicy action game enjoyed ...

  9. Fruit Ninja

    Fruit Ninja 时间限制:C/C++ 5秒,其他语言10秒 空间限制:C/C++ 262144K,其他语言524288K 64bit IO Format: %lld 题目描述 Fruit Ni ...

随机推荐

  1. LeetCode: 598 Range Addition II(easy)

    题目: Given an m * n matrix M initialized with all 0's and several update operations. Operations are r ...

  2. SCUT - 205 - 饲养牛 - 最大流

    https://scut.online/p/205 连着做所以一开始就觉得是网络流. 这种至多分配几次的很有网络流的特征. 一开始想从食物和饮料流向牛,但是怎么搞都不对. 其实可以从s流向食物,食物流 ...

  3. offsetLeft在各浏览器的值

    上网找了好久没有找到一个offsetLeft在各浏览器的值,自己用了一晚上的时间在各浏览器测试出来的offsetLeft的值. <!DOCTYPE html> <html lang= ...

  4. IT兄弟连 JavaWeb教程 过滤器2

    3  多个过滤器的执行顺序 如果一个Web应用中使用一个过滤器不能解决实际中的业务需要,那么可以部署多个过滤器对业务请求进行多次处理,这样做就组成了一个过滤器链.Web服务器在处理过滤器链时,将按过滤 ...

  5. Ruby: Case表达式

    Ruby的case表达式有两种形式: 第一种形式接近于一组连续的if语句:它让你列出一组条件,并执行第一个为真的条件表达式所对应的语句. 第二种形式,在case语句的顶部指定一个目标,而每个when从 ...

  6. React中方法的this绑定

    第一种 在组件(类)的constructor中绑定this class Demo extends Component { constructor(this) { super(this) this.st ...

  7. JS高级学习历程-15

    昨天内容回顾 面向对象的私有成员.静态成员 私有成员:在构造函数里边定义局部变量,就是私有成员. 静态成员:在js里边,函数就是对象,可以通过给函数对象声明成员方式声明静态成员. 原型继承 关键字:p ...

  8. linux 03 命令 续

    linux 03 命令 续 一.vim 两种操作方式:新文件 pyvip@Vip:~/demo/2_3$ vim demo.txt #操作一个新文件 一开始进入的是命令模式,按i进入插入模式,开始编辑 ...

  9. Codeforces 163C(实数环上的差分计数)

    要点 都在注释里了 #include <cstdio> #include <cstring> #include <iostream> #include <al ...

  10. tomcat7 fail to start inside Ubuntu Docker container

    The tomcat startup script needs some special privileges. Concrete it needs to check all running proc ...