UV 1567, lga1567

Source: Internet
Author: User

UV 1567, lga1567

Link to the Q & A 1567-A simple stone game

Given K and N, it indicates that a pile of stones have N. The first time you can get 1 ~ N-1 stone, get the last stone victory, word each operation, the number of stones can not exceed the opponent's last take the stone m K times. Ask if you can win the first hand and output the smallest first operation.

Solution: After thinking about this question for a day, I made a table to find the rule, and I pushed the formula. I couldn't help it. Then I found an answer on the Internet, which will be very clear, solution book

/******************* K times dynamic subtraction game * Reference: explain <cstdio> # include <cstring> # include <algorithm> using namespace std; const int maxn = 1e6 + 5; int N, K, a [maxn], B [maxn]; int main () {int cas; scanf ("% d", & cas); for (int I = 1; I <= cas; I ++) {scanf ("% d", & N, & K); int p = 0, q = 0; a [0] = B [0] = 0; while (a [p] <N) {a [p + 1] = B [p] + 1; p ++; while (a [q + 1] * K <a [p]) q ++; B [p] = B [q] + a [p];} printf ("Case % d:", I); if (N = a [p]) printf ("lose \ n"); else {int ans; while (N) {if (N> = a [p]) {N-= a [p]; ans = a [p];} p --;} printf ("% d \ n", ans) ;}} return 0 ;}

Coreldraw x5 activation code

The installation code you provided cannot be changed.
Installation code: X6FH-3J45-TT7X-J567-RAS8
Serial: DR15R22-DS48YWY-MUDYDGJ-WX7THLY
Activation code: 5876-0C27-1432-0F59-1567
Try it!
 

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.