HDU 4350-card

Source: Internet
Author: User

 

Question address: http://acm.hdu.edu.cn/showproblem.php? PID = 1, 4350

 

More than 12 years old, with 1001 questions.

 

Shuffling, N gives a lot.

 

So as long as we find the loop section, modulo n out, and then perform the brute force operation, the remaining time complexity will be very low ~~~

 

It seems that the cycle section they are looking for is the smallest public multiple of (R-l + 1) and r... But what I am looking for is the maximum common number GCD between them, and then the cyclic section is R/GCD...

 

# Include <iostream> # include <cstdio> # include <cstring> # include <cmath> # include <queue> # include <algorithm> using namespace STD; int gcd (int, int B) {return B = 0? A: gcd (B, A % B) ;}int main () {int T, TT; int s [53], TMP [53]; int n, l, R; scanf ("% d", & T); For (TT = 1; TT <= T; TT ++) {for (INT I = 1; I <= 52; I ++) scanf ("% d", & S [I]); scanf ("% d", & N, & L, & R ); int G = gcd (R, R-l + 1); N % = (R/g); While (n --) {for (INT I = 0; I <= R-l; I ++) TMP [I] = s [L + I]; for (INT I = 1; I <L; I ++) TMP [R-l + I] = s [I]; for (INT I = R + 1; I <= 52; I ++) TMP [I-1] = s [I]; for (INT I = 0; I <52; I ++) s [I + 1] = TMP [I];} printf ("case # % d:", TT); For (INT I = 1; I <= 52; I ++) printf ("% d ", s [I]); puts ("");} return 0 ;}

 

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.