zoukankan      html  css  js  c++  java
  • The Meaningless Game 思维题

    题目描述

    Slastyona and her loyal dog Pushok are playing a meaningless game that is indeed very interesting.

    The game consists of multiple rounds. Its rules are very simple: in each round, a natural number k is chosen. Then, the one who says (or barks) it faster than the other wins the round. After that, the winner's score is multiplied by k2, and the loser's score is multiplied by k. In the beginning of the game, both Slastyona and Pushok have scores equal to one.

    Unfortunately, Slastyona had lost her notepad where the history of all n games was recorded. She managed to recall the final results for each games, though, but all of her memories of them are vague. Help Slastyona verify their correctness, or, to put it another way, for each given pair of scores determine whether it was possible for a game to finish with such result or not.

    输入

    In the first string, the number of games n (1 ≤ n ≤ 350000) is given.

    Each game is represented by a pair of scores ab (1 ≤ a, b ≤ 109) – the results of Slastyona and Pushok, correspondingly.

    输出

    For each pair of scores, answer "Yes" if it's possible for a game to finish with given score, and "No" otherwise.

    You can output each letter in arbitrary case (upper or lower).

    样例

    样例输入

    6
    2 4
    75 45
    8 8
    16 16
    247 994
    1000000000 1000000
    View Code

    样例输出

    Yes
    Yes
    Yes
    No
    No
    Yes
    View Code

    提示

    First game might have been consisted of one round, in which the number 2 would have been chosen and Pushok would have won.

    The second game needs exactly two rounds to finish with such result: in the first one, Slastyona would have said the number 5, and in the second one, Pushok would have barked the number 3.

    分析

    一句话题意:现在两个人做游戏,每个人刚开始都是数字1,谁赢了就能乘以k^2,输的乘以k,现在给你最终这两个人的得分,让你判断是否有这个可能,有可能的话Yes,否则No。

    我们假设游戏进行了 i 轮,每次选择的数分别是n1、n2、n3……ni

    那么第一次,必定有一个人乘n12,另一个人乘n1,同样地,第二次,必定有一个人乘n22,另一个人乘n2

    我们设A为第一个人最终的得分,B为第二个人最终的得分,那么很显然,如果结果正确的话,必定有A*B=n13*n23*n33*……*ni3

    所以我们要判断对A*B开三次根号后的数是不是整数

    同时,一个人的最小得分必定为n1*n2*n3*……*ni,最大得分必定为n12*n22*n32*……*ni2

    所以我们还要判断A和B能否被它们的乘积开三次根号的结果整除

    如果上述条件都满足,就输出Yes,否则输出No

    代码

     1 #include<cstdio>
     2 #include<cstring>
     3 #include<algorithm>
     4 #include<iostream>
     5 #include<queue>
     6 #include<cmath>
     7 using namespace std;
     8 typedef long long ll;
     9 int main(){
    10     ll t;
    11     scanf("%lld",&t);
    12     while(t--){
    13         ll a,b;
    14         scanf("%lld%lld",&a,&b);
    15         ll tot=a*b;
    16         ll js=round(pow(1.0*tot,1.0/3));
    17         //对A*B开三次根号取整  
    18         if(js*js*js==tot && a%js==0 && b%js==0) printf("Yes
    ");
    19         else printf("No
    ");
    20     }
    21     return 0;
    22 }
    View Code
  • 相关阅读:
    游戏开发设计模式之子类沙盒模式(unity3d 示例实现)
    Unity3d 屏幕空间人体皮肤知觉渲染&次表面散射Screen-Space Perceptual Rendering & Subsurface Scattering of Human Skin
    Unity5 Screen-Space Subsurface Scattering屏幕空间次表面散射SSSSS
    游戏开发Camera之Cinematic Camera-深度
    这次GDC China 2015的总结与关卡设计教程的梳理
    游戏开发设计模式之状态模式 & 有限状态机 & c#委托事件(unity3d 示例实现)
    游戏开发设计模式之原型模式 & unity3d JSON的使用(unity3d 示例实现)
    MyBatis结果集一对多映射
    Builder模式实例 MyBatis的ResultMapping和ResultMap
    MyBatis PropertyTokenizer
  • 原文地址:https://www.cnblogs.com/liuchanglc/p/12748173.html
Copyright © 2011-2022 走看看