zoukankan      html  css  js  c++  java
  • HDU4861(Couple doubi)

    题目地址:Couple doubi

    题目大意:

        桌上有K个球,有一公式Every ball has a value and the value of ith (i=1,2,...,k) ball is 1^i+2^i+...+(p-1)^i (mod p)  。p是一个素数(3.5.7....)。doubinan和doubixp,每人依次取一个球计算其球的value的总和sum比较谁赢。nan先取如果赢输出YES否则NO。

    解题思路:

        找规律,把p为3,k为1-10的胜负情况罗列出来和p为5,k为1-10,和p为7,k为1-10。

    会发现p=3的结果(0202020202)p=5(00040004)p=7(五个0和一个数)。所以把yes和no写出来,规律很容易发现

    假设p=7,K<=6的胜负情况都是NO,K>=7的胜负情况是7个一组的循环。

    代码:

     1 #include <algorithm>
     2 #include <iostream>
     3 #include <sstream>
     4 #include <cstdlib>
     5 #include <cstring>
     6 #include <cstdio>
     7 #include <string>
     8 #include <bitset>
     9 #include <vector>
    10 #include <queue>
    11 #include <stack>
    12 #include <cmath>
    13 #include <list>
    14 //#include <map>
    15 #include <set>
    16 using namespace std;
    17 /***************************************/
    18 #define ll long long
    19 #define int64 __int64
    20 #define PI 3.1415927
    21 /***************************************/
    22 const int INF = 0x7f7f7f7f;
    23 const double eps = 1e-8;
    24 const double PIE=acos(-1.0);
    25 const int d1x[]= {0,-1,0,1};
    26 const int d1y[]= {-1,0,1,0};
    27 const int d2x[]= {0,-1,0,1};
    28 const int d2y[]= {1,0,-1,0};
    29 const int fx[]= {-1,-1,-1,0,0,1,1,1};
    30 const int fy[]= {-1,0,1,-1,1,-1,0,1};
    31 const int dirx[]= {-1,1,-2,2,-2,2,-1,1};
    32 const int diry[]= {-2,-2,-1,-1,1,1,2,2};
    33 /*vector <int>map[N];map[a].push_back(b);int len=map[v].size();*/
    34 /***************************************/
    35 void openfile()
    36 {
    37     freopen("data.in","rb",stdin);
    38     freopen("data.out","wb",stdout);
    39 }
    40 priority_queue<int> qi1;
    41 priority_queue<int, vector<int>, greater<int> >qi2;
    42 /**********************华丽丽的分割线,以上为模板部分*****************/
    43 
    44 int main()
    45 {
    46     int k,p;
    47     while(scanf("%d%d",&k,&p)!=EOF)
    48     {
    49         int sum1=p-2,sum2;
    50         if(k<=sum1)
    51         {
    52             printf("NO
    ");
    53         }
    54         else
    55         {
    56             sum2=k/(sum1+1);
    57             if (sum2%2)
    58                 printf("YES
    ");
    59             else
    60                 printf("NO
    ");
    61         }
    62     }
    63     return 0;
    64 }
    View Code
  • 相关阅读:
    git push时提示"fatal: The current branch master has no..."
    git push时提示"Everything up-to-date"
    图解vim常用命令
    总结下git中一些常用命令
    SVN服务端的版本对比及创建仓库时的注意事项
    bootstrap字体图标不正常显示的原因
    bigdata_Hadoop jps出现process information unavailable提示解决办法
    bigdata_批量机器执行通用脚本
    bigdata_ambari修改hiveserver_metastore链接库(从0.14 升级到1.2.1 )
    bigdata_一篇文看懂Hadoop
  • 原文地址:https://www.cnblogs.com/ZhaoPengkinghold/p/3902922.html
Copyright © 2011-2022 走看看