链接: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. 一个工程多个Target

    当我们同一个工程需要在不同情形下编译打包,比如打个人包.企业包的时候,其中可能有一些细小的差别,又不想每次都先修改再打包的时候,我们可以通过创建多个Target来实现. 1.copy原有Target ...

  2. C#中异步及winform中界面假死

    c#中可以用BeginInvoke去启动异步调用,但是有两个BeginInvoke一个是controller的BeginInvoke还有一个是委托的BeginInvoke. 主要区别是controll ...

  3. 51nod1117(简单huffman tree)

    题目链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1117 题意:中文题诶- 思路:简单huffman tree ...

  4. 洛谷P2854 [USACO06DEC]牛的过山车Cow Roller Coaster

    P2854 [USACO06DEC]牛的过山车Cow Roller Coaster 题目描述 The cows are building a roller coaster! They want you ...

  5. BZOJ 1069: [SCOI2007]最大土地面积(旋转卡壳)

    题目链接~ 1069: [SCOI2007]最大土地面积 思路很简单,极角排序求完凸包后,在凸包上枚举对角线,然后两边分别来两个点旋转卡壳一下,搞定! 不过计算几何的题目就是这样,程序中间的处理还是比 ...

  6. Java-GC-标记压缩算法

    标记压缩算法 其分为两个阶段标记阶段,和压缩阶段.其中标记阶段和标记清除算法的标记阶段是一样的. 对压缩算法来说,他的工作就是移动所有的可达对象到堆内存的同一区域中,使它们紧凑的排列在一起,从而将所有 ...

  7. phpstorm使用

    生成注释快捷键/**+enter 注释快捷键ctrl+/

  8. JS高级学习历程-3

    JS-作用域链及作用 [作用域链] 1 什么事作用域链 一个变量,在当前环境可以使用,当前环境的内部环境也可以使用,内部的深层环境...也可以使用,变量在不同环境都可以使用的现象想成了一个链条,称为“ ...

  9. Python-13-pass,del和exec

    1.pass就是什么都不做 >>> pass >>>   2. 对于你不再使用的对象, Python通常会将其删除(因为没有任何变量或数据结构成员指向它) . &g ...

  10. Leetcode:根据身高重建队列

    题目 假设有打乱顺序的一群人站成一个队列. 每个人由一个整数对(h, k)表示,其中h是这个人的身高,k是排在这个人前面且身高大于或等于h的人数. 编写一个算法来重建这个队列. 注意: 总人数少于11 ...