zoukankan      html  css  js  c++  java
  • Fruit Ninja(取随机数)

    链接: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".
    示例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[10050];
    int main()
    {
        scanf("%d",&t);
        while(t--)
        {
            scanf("%d %lf",&n,&k);
            for(int i=0; i<=n-1; i++)
            {
                scanf("%d %d",&stu[i].x,&stu[i].y);
            }
            if(n<=2)
            {
                printf("Yes
    ");
                continue;
            }
            m=120;
            flag=false;
            while(m--)
            {
                y=rand()%n;
                x=rand()%n;
                if(x==y) continue;
                sum=2;
                for(int i=0; i<=n-1; 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
    ");
            else printf("No
    ");
        }
        return 0;
    }
    View Code
  • 相关阅读:
    关于oc中自动引用计数 小结
    xcode6中导航栏 控制view用程序编写
    oc中深拷贝与浅拷贝
    关于c语言 指针课堂随笔
    oc中设置手动引用和自动引用图解
    利用xcode6做出牛的一逼的计算器
    利用xcode6 使用代码写出英格兰国旗
    oc中字典的应用详解
    c和oc排序程序与见解
    关于Xcode6beta2 新学者使用 工程的建立
  • 原文地址:https://www.cnblogs.com/lglh/p/9429061.html
Copyright © 2011-2022 走看看