Hdu4861 (couple doubi)

Source: Internet
Author: User

Address: couple doubi

 

Question:

There are K balls on the table, with the formula every ball has a value and the value of ith (I = ,..., k) Ball is 1 ^ I + 2 ^ I +... + (p-1) ^ I (mod P ). P is a prime number (3.5.7 ....). Doubinan and doubixp, each person takes one ball in turn to calculate the sum of the values of the ball to compare who wins. Nan first gets if win output yes otherwise no.

 

Solution:

Find the rule and list the winning and losing situations where p is 3 and K is 1-10, and P is 5, K is 1-10, and P is 7, and K is 1-10.

The result of P = 3 is found to be (0202020202) P = 5 (00040004) P = 7 (five zeros and a number ). Therefore, it is easy to find the rules by writing yes and no.

Assume that the winning and losing situations of P = 7, k <= 6 are all no, and K> = 7 is a loop of 7 groups.

 

Code:

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 long19 # define in T64 _ int6420 # define PI 3.141592721 /******************************* * ******/22 const int INF = 0x7f7f7f7f; 23 const double EPS = 1e-8; 24 const double PIE = ACOs (-1.0); 25 const int d1x [] = {0,-, 1 }; 26 const int d1y [] = {-,}; 27 const int d2x [] = {0,-, 1}; 28 const int d2y [] =, -}; 29 const int FX [] = {-1,-1,-,}; 30 const int FY [] = {-, 1, -,-, 1}; 31 const int dirx [] = {-,-2, 2,-,-}; 32 const int diry [] = {-2,-2,-1,-, 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/*********************** Lili split line, the above is the template section **************** */43 44 int main () 45 {46 int K, P; 47 While (scanf ("% d", & K, & P )! = EOF) 48 {49 int sum1 = P-2, sum2; 50 if (k <= sum1) 51 {52 printf ("NO \ n "); 53} 54 else55 {56 sum2 = K/(sum1 + 1); 57 if (sum2% 2) 58 printf ("Yes \ n "); 59 else60 printf ("NO \ n"); 61} 62} 63 return 0; 64}
View code

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.