Nbut 1225 NEW RDSP MODE I (law + fast Power)

Source: Internet
Author: User

  • [1225] NEW RDSP MODE I
  • Time limit: Ms Memory limit: 131072 K
  • Problem description
  • Little A has became fascinated and the game Dota recently, but he's not A good player. In all the modes, the RDSP mode was popular on online, in this mode, little A always loses games if he gets strange heroes, Because, the heroes is distributed randomly.

    Little A wants to win the game, so he cracks the code of the RDSP mode with his talent on programming. The following description is about the RDSP mode:

    There is N heroes in the game, and they all has a unique number between 1 and N. At the beginning of the game, all heroes'll be is sorted by the number in ascending order. So, all heroes form a sequence one.

    These heroes'll be operated by the following stages M times:

    1.Get out the heroes in odd position of sequence one to form a new sequence;

    2.Let The remaining heroes in even position to form a new sequence three;

    3.ADD the sequence from the back of sequence three to form a new sequence one.

    After M Times ' operation, the X heroes in the front of new sequence one would be chosen to be Little A ' s heroes. The problem for little A, the numbers of his heroes.

  • Input
  • There is several test cases.
    Each case contains three integers N (1<=n<1,000,000), M (1<=m<100,000,000), X (1<=x<=20).
    Proceed to the end of file.
  • Output
  • For each test case, output X integers indicate the number of heroes. There is a space between the numbers. The output of one test case occupied exactly one line.
  • Sample input
  • 5 1 25) 2 2
  • Sample output
  • 2 44 3
  • Tips
  • In case two:n=5,m=2,x=2,the initial sequence one is 1,2,3,4,5.after the first operation, the sequence Oneis 2,4,1,3,5. After the second operation, the sequence one is 4,3,2,1,5.so,output 4 3.
  • Source
  • Liaoning Province Race 2010

Test instructions: 1~n number of arrays A, an array of odd bits into an array B, an even number of bits to form an array c, and then connect B to C, to execute m times, the output of the last number of the first X-digits.

Analysis: This problem can be understood as a number in the final position after M-transformation, then the first from the two-time transformation of the relationship began to deduce

Suppose the position of this time is X, divided into even and odd two cases:

If x is an even number, then x's next coordinate will be X ' =X/2, which can be understood as half of the odd number in front is taken away, change the x=2*x '

If x is an odd number, then x's next coordinate will be X ' =N/2+X/2, which can be interpreted as having N/2 in front, and then x/2 an odd number in front of X, transforming X=2*x '-N

Can be found, whether it is odd or even, is x=2*x after the n modulo, then the M transformation can be regarded as 2 m power, here write a fast power on the line.

Also note that when N is an even number to +1, because N is even, the subscript may be 0, when n is an odd number, the nth position is unchanged in the transformation, so the situation and N-1.

#pragmaComment (linker, "/stack:1024000000,1024000000")#include<cstdio>#include<string>#include<iostream>#include<cstring>#include<cmath>#include<stack>#include<queue>#include<vector>#include<map>#include<stdlib.h>#include<algorithm>#defineLL __int64#defineFIN freopen ("In.txt", "R", stdin)using namespacestd; LL n,m,x; LL ans,tmp; ll Pow (ll x,ll n,ll MOD) {ll res=1;  while(n) {if(n&1) res= (x*res)%MOD; X= (x*x)%MOD; N>>=1; }    returnRes;}intMain () { while(SCANF ("%i64d%i64d%i64d", &n,&m,&x)! =EOF) {        if(N%2==0) n++; TMP=pow (2, M,n); Ans=tmp; printf ("%i64d", TMP);  for(intI=2; i<=x;i++) {ans+=tmp; Ans%=N; printf ("%i64d", ans); } printf ("\ n"); }    return 0;}
View Code

Nbut 1225 NEW RDSP MODE I (law + fast Power)

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.