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 ...
随机推荐
- ue4 动画相关方法杂记
加载资源文件中的 骨骼,动画,蒙太奇----------------------------------------- FName anis("/Game/FirstPerson/Anima ...
- 洛谷P2759 奇怪的函数
P2759 奇怪的函数 题目描述 使得 x^x 达到或超过 n 位数字的最小正整数 x 是多少? 输入输出格式 输入格式: 一个正整数 n 输出格式: 使得 x^x 达到 n 位数字的最小正整数 x ...
- visdom可视化pytorch训练过程
一.前言 在深度学习模型训练的过程中,常常需要实时监听并可视化一些数据,如损失值loss,正确率acc等.在Tensorflow中,最常使用的工具非Tensorboard莫属:在Pytorch中,也有 ...
- thinkphp5部署到LAMP服务器显示Access denied.
问题:thinkphp5部署到LAMP服务器,首页正常访问,其余页面访问显示Access denied 解决:1.先把文件夹权限改为777 2. 进入服务器,改文件.将php.ini的值改成1
- 黑马MyBatis入门day1
package com.itheima.domain; /* CREATE TABLE `user` ( `id` int(11) NOT NULL AUTO_INCREMENT, `username ...
- thinkphp 2.1代码执行及路由分析
Dispatcher.class.php这个文件中是url路由,由于第一次正式看路由那块,所以就从头开始一行一行看把. 首先是dispatch函数 是37行到140行 这个函数是做映射用,把url映射 ...
- angular2 基于webpack环境搭建
目录结构: angular-quickstart |_ ts |_ app.ts |_ index.ts |_ index.html |_ package.json |_ tsconfig.json ...
- GDI绘制图形的使用_验证码
//创建GDI对象 Graphics g = this.CreateGraphics();// new Graphics(); //创建画笔对象 Pen pen = new Pen(Brushes.R ...
- 剑指tomcat之应用管理
tomcat服务启动之后,有tomcat自身提供的应用管理(App Manage)页面,默认的地址就是服务的IP地址+端口号(IP:port):页面如下所示 点击上图的按钮便可进入应用管理页面,需要账 ...
- JAVA常量介绍
常量: 在程序执行过程中,其值不发生改变的量: 1.分类: 字面值常量和自定义常量: 1.字面值常量有以下几种: 字符串常量.小数常量.整数常量.字符常量.布尔常量(true.false).空 ...