zoukankan      html  css  js  c++  java
  • HDU 5512 Pagodas(等差数列)

    题目戳这

    题意:给你三个数:n,a,b,一开始一个集合里面有两个数:a和b,然后两个人轮流往这个集合里面增加数字,增加的这个数字的原则是,这个集合里面任选两个数的和或差,集合里面的数字不能重复,同时这个数字不能大于 n 。(本来说的造塔,这样说方便一点)

    思路:本来还以为是博弈,但是后来把数字的加减都模拟一遍之后发现,无论怎样,最后得到的这个集合里面的数列,其实是一个等差数列,所以这就简单了,由一开得到的 a 和 b 来相减,然后不断地取最小的两个数相减,然后等到等差数列的差,这个差同时也是等差数列一开始的那个数字,然后拿 n 除以这个差就是在 n 的范围内可以得到的数字的个数了,然后因为分先手和后手,所以最后只要判断一下个数的奇偶数就可以得到答案了。

    P.S.这道题又犯傻了,明明都已经找到规律了,结果还想着二分,明明拿个 n 除以那个差就好了······

     1 #include<stdio.h>
     2 #include<iostream>
     3 #include<string.h>
     4 #include<math.h>
     5 #include<algorithm>
     6 #include<vector>
     7 #include<string>
     8 #include<queue>
     9 #include<map>
    10 #include<stack>
    11 #include<set>
    12 #define ll long long
    13 #define PI acos(-1.0)    //圆周率
    14 const int mod=1e9+7;
    15 const int maxn=1e6+10;
    16 using namespace std;
    17 int T,n,a,b;
    18 int max(int l,int r)
    19 {
    20     if(l>r)  return l;
    21     else  return r;
    22 }
    23 int min(int l,int r)
    24 {
    25     if(l>r)  return r;
    26     else  return l;
    27 }
    28 int main()
    29 {
    30     int cas=0;
    31     scanf("%d",&T);
    32     while(T--)
    33     {
    34         scanf("%d %d %d",&n,&a,&b);
    35 
    36         if(a<b)  swap(a,b);
    37         int cnt=0;
    38         while(1)
    39         {
    40             cnt=a-b;
    41 
    42             if(b==cnt)  break;
    43 
    44             a=max(b,cnt);
    45             b=min(b,cnt);
    46         }
    47 
    48         int ans=n/cnt;
    49 
    50         printf("Case #%d: ",++cas);
    51         if(ans%2==0)  printf("Iaka
    ");
    52         else  printf("Yuwgna
    ");
    53     }
    54 
    55     return 0;
    56 }
    View Code
  • 相关阅读:
    How to function call using 'this' inside forEach loop
    jquery.validate.unobtrusive not working with dynamic injected elements
    Difference between jQuery.extend and jQuery.fn.extend?
    Methods, Computed, and Watchers in Vue.js
    Caution using watchers for objects in Vue
    How to Watch Deep Data Structures in Vue (Arrays and Objects)
    Page: DOMContentLoaded, load, beforeunload, unload
    linux bridge
    linux bridge
    EVE-NG网卡桥接
  • 原文地址:https://www.cnblogs.com/2cm-miao/p/5897898.html
Copyright © 2011-2022 走看看