Ural 1289. One-Ticket

Source: Internet
Author: User

1289. One Tickettime limit:1.0 second
Memory limit:64 MBA crowed of volunteers dressed in the star striped overalls has filled the starport. There StarCraft leaves to the thorium mines of Haron. Their job would be the hard and dangerous. Would many of them return home? This question have an exact answer. Each of the volunteers have a ticket to the StarCraft. There signed a compartment number where he is to fly. The StarCraft isn't passenger, it departs to Haron once a month full of the volunteers and returns back loaded with Thori Um. This precious metal can is loaded not at all of the compartments. In such a compartments volunteers can return home. All the others is to stay at Haron ... Forever.the compartments is numbered. The numbers of the unfit compartments (and only their numbers) is so, the digit root of the first half of the number equals to the digit root of the second half. To calculate the digit root of a number one are to summarize the digits of the number; If the result is greater or equal than and then the DigiTS of the result is to be summarized again; And so on until one gets a number from 0 to 9.How many volunteers would return home? Inputeven integer number N≤200000–an amount of digits used to number the compartments. There is exactly 10n compartments numbered from 0 to 10n-1 with the leading zeros. Outputthe number of compartments free of thorium on the the-the-the-same. Sample
input Output
2
10
problem Author:Leonid Volkov
problem Source:USU Personal Contest 2004 Tags:None()difficulty:391 Test Instructions: Ask the first half of the number root and the number of the last half of the number root of the same n-digit number (can have the prefix 0) analysis: First, the number root is zero is obviously only 00 .... 000 This is all 0 then the other number root must be 1-9 M=N/2 (n must be even) the first m bits are set to k=10^m-1=99...999 (M 9), obviously, each number root 1111 ... 111 (M 1) =K/9 number of the same, after M-bit total K number, obviously, each number root K/9 number and then it is obvious ... The answer is ans = k * (K/9) + 1 write down the high precision is good but, 999...999 * 111..111 is a regular ... And it's easy to find. So the high precision does not have to write ...
1#include <cstdio>2#include <cstring>3#include <cstdlib>4#include <cmath>5#include <deque>6#include <vector>7#include <queue>8#include <iostream>9#include <algorithm>Ten#include <map> One#include <Set> A#include <ctime> - using namespacestd; -typedefLong LongLL; thetypedefDoubleDB; - #defineFor (I, S, T) for (int i = (s); I <= (t); i++) - #defineFord (I, S, T) for (int i = (s); I >= (t); i--) - #defineRep (i, T) for (int i = (0); i < (t); i++) + #defineREPN (i, T) for (int i = (t)-1); I >= (0); i--) - #defineRep (i, X, T) for (int i = (x); i < (t); i++) + #defineMIT (2147483647) A #defineINF (1000000001) at #defineMLL (1000000000000000001LL) - #defineSZ (x) ((int) (x). Size ()) - #defineCLR (x, y) memset (x, y, sizeof (x)) - #definePUF Push_front - #definePub push_back - #definePOF Pop_front in #definePOB pop_back - #defineFT first to #defineSD Second + #defineMk Make_pair -InlinevoidSetio (stringName) { the     stringInput = name+". in", *Output = name+". out"; $Freopen (Input.c_str (),"R", stdin),Panax NotoginsengFreopen (Output.c_str (),"W", stdout); - } the  +InlineintGetint () { A     intRet =0; the     CharCh =' '; +     BOOLFlag =0; -      while(! (Ch >='0'&& Ch <='9')) { $         if(Ch = ='-') Flag ^=1; $Ch =GetChar (); -     } -      while(Ch >='0'&& Ch <='9') { theRet = ret*Ten+ch-'0'; -Ch =GetChar ();Wuyi     } the     returnFlag? -Ret:ret; - } Wu  - intN; About  $InlinevoidInput () { -Cin>>N; - } -  AInlinevoidSolve () { +N/=2; the     if(n = =1) puts ("Ten"); -     Else { $for (I,1, N-1) printf ("1"); theprintf"0"); thefor (I,1, N-2) printf ("8"); theprintf" -"); the     } - } in  the intMain () { the #ifndef Online_judge AboutSetio ("G"); the     #endif  the Input (); the Solve (); +     return 0; -}
View Code

Ural 1289. One-Ticket

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.