zoukankan      html  css  js  c++  java
  • Fruit Ninja

    Fruit Ninja

    时间限制: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 ≤ 10000) 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 xi and yi(-1000000000<=xi,yi<=1000000000),
    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

    题目:n个点,问是否至少有n*x个点在一条直线上。
    对于极限数据n=10000,x=0.1的情况,分析发现我们若是随机选取一个点,选到这条直线上的点的概率是1/10,反之选不到的概率就是9/10。
    那这样我们选取n次,选不到的概率就是(9/10)的n次方。当n较大时,这个概率就足够低,可以让我们通过这个题。
    #include <bits/stdc++.h>
    #define N 1000000007
    using namespace std;
    long double check[10050];
    int x[10050],y[10050];
    
    int main()
    {
        int t;
        scanf("%d",&t);
        while(t--)
        {
            int n,c1=0,up,ans=0;
            double xx;
            scanf("%d %lf",&n,&xx);
            up=ceil(xx*1.0*n);
    
            for(int i=1; i<=n; i++)scanf("%d %d",&x[i],&y[i]);
    
            for(int i=1; i<=min(20,n-up+1); i++)
            {
                c1=0;
                for(int j=1; j<=n; j++)
                    if(i!=j)
                    {
                        if(x[j]!=x[i])check[c1++]=(y[j]-y[i])*1.0/(x[j]-x[i]);
                        else
                            check[c1++]=N;
                    }
                sort(check,check+c1);
    
                int tot=1;
                check[c1]=N+1;
                for(int i=1; i<=c1; i++)
                {
                    if(check[i]!=check[i-1])
                    {
                        ans=max(ans,tot+1);
                        tot=1;
                    }
                    else
                        tot++;
                }
    
                if(ans>=up)
                {
                    break;
                }
    
            }
    
            if(ans>=up)
            {
                printf("Yes
    ");
    
            }
            else
            {
                printf("No
    ");
    
            }
    
        }
        return 0;
    }
    View Code
  • 相关阅读:
    Implicit conversion from enumeration type 'enum CGImageAlphaInfo' to different enumeration type 'CGB
    iOS谋职之OC面试题
    IOS_视图实现圆角效果的三种方法及比较
    Objective-C 中的方法回掉
    returnValue of Chrome
    获取最新ADT下载地址的方法
    Git 分支使用
    Windows下运行jekyll,编码已不再是问题
    Github Pages另一个选择:GitCafe-Pages
    还没更换RubyGems镜像?
  • 原文地址:https://www.cnblogs.com/tian-luo/p/9426389.html
Copyright © 2011-2022 走看看