zoukankan      html  css  js  c++  java
  • 2015百度之星 放盘子

    放盘子

     
    Time Limit: 2000/1000 MS (Java/Others)
    Memory Limit: 65536/65536 K (Java/Others)
    Problem Description
    小度熊喜欢恶作剧。今天他向来访者们提出一个恶俗的游戏。他和来访者们轮流往一个正多边形内放盘子。最后放盘子的是获胜者,会赢得失败者的一个吻。玩了两次以后,小度熊发现来访者们都知道游戏的必胜策略。现在小度熊永远是先手,他想知道他是否能获胜。 注意盘子不能相交也不能和多边形相交也不能放在多边形外。就是说,盘子内的点不能在多边形外或者别的盘子内。
    Input
    第一行一个整数$T$,表示$T$组数据。每组数据包含$3$个数$n,a,r (4 leq n leq 100,0 < a < 1000,0 < r < 1000)$ $n$是偶数,代表多边形的边数,$a$代表正多边形的边长,$r$代表盘子的半径。
    Output
    对于每组数据,先输出一行 Case #i: 然后输出结果.如果小度熊获胜,输出”Give me a kiss!” 否则输出”I want to kiss you!”
    Sample Input
    2
    4 50 2.5
    4 5.5 3
    
    Sample Output
    Case #1:
    Give me a kiss!
    Case #2:
    I want to kiss you!
    Hint
    在第一组样例中,小度熊先在多边形中间放一个盘子,接下来无论来访者怎么放,小度熊都根据多边形中心与来访者的盘子对称着放就能获胜。 

    Problem's Link:   http://bestcoder.hdu.edu.cn/contests/contest_showproblem.php?cid=584&pid=1004


    analyse:

    SB题。

    策略是这样的:因为是百度熊先放,如果可以放第一个,百度熊就将这个盘子放在正多边形的中央(盘子圆心和正多边形的中心重合),剩下的就是别人怎么放,百度熊跟着放在对称的位置就行。因为:边数为偶数的正多边形一定是关于几何中心对称。

    问题就简化成了:如果能放下第一个盘子,百度熊就一定能赢。

    只需要求出正多边形对边的距离和2*r相比较即可。

                          

    Time complexity: O(n)

    Source code:  

    Java代码:
    import java.util.Scanner;
    
    public class Main
    {
        static Scanner in=new Scanner(System.in);
        double calcLen(int n,double a)
        {
            if(n==4) return a/2.0;
            double PI=3.1415926;
            return a/2.0/(Math.tan(PI*360.0/(double)n/2.0/180));
        }
        public static void main(String[] args)
        {
            int t=in.nextInt();
            for(int Cas=1;Cas<=t;++Cas)
            {
                int n;
                double a,r;
                n=in.nextInt();
                a=in.nextDouble();
                r=in.nextDouble();
                System.out.println("Case #"+Cas+":");
                double len=new Main().calcLen(n,a);
                if(len-r>=0.0)
                    System.out.println("Give me a kiss!");
                else
                    System.out.println("I want to kiss you!");
            }
        }
    }
    View Code

    C++代码:

    /*
    * this code is made by crazyacking
    * Verdict: Accepted
    * Submission Date: 2015-05-24-19.09
    * Time: 0MS
    * Memory: 137KB
    */
    #include <queue>
    #include <cstdio>
    #include <set>
    #include <string>
    #include <stack>
    #include <cmath>
    #include <climits>
    #include <map>
    #include <cstdlib>
    #include <iostream>
    #include <vector>
    #include <algorithm>
    #include <cstring>
    #define  LL long long
    #define  ULL unsigned long long
    using namespace std;
    
    int  i, t, n;
    double a, r, x, y;
    int main()
    {
        scanf( "%d", &t );
        for ( i = 1; i <= t; i++ )
        {
            scanf( "%d%lf%lf", &n, &a, &r );
            printf( "Case #%d:
    ", i );
            x = ( 90 * n - 180 ) / n;
            y = a / 2 * tan( x / 180 * 3.1415927 );
            if ( y < r ) {printf( "I want to kiss you!
    " ); continue;}
            printf( "Give me a kiss!
    " ); continue;
        }
        return 0;
    }
    View Code
  • 相关阅读:
    CentOS7最小化安装后要做的事
    Django 2.0 新特性
    Django2.+ path配置
    Django 安装
    Django基础
    http协议
    Centos7 下mysql大小写敏感问题
    CentOS 设置mysql的远程访问
    Linux下彻底卸载mysql详解
    静态库和动态库
  • 原文地址:https://www.cnblogs.com/crazyacking/p/4524687.html
Copyright © 2011-2022 走看看