ural 1289. One Way Ticket

1289. One Way Ticket

Time limit: 1.0 second
Memory limit: 64 MB

A crowed of volunteers dressed in the star striped overalls have filled the starport. There starcraft leaves to the thorium mines of Haron. Their job will be hard and dangerous. Will many of them return home?

This question has an exact answer. Each of the volunteers has a ticket to the starcraft. There signed a compartment number where he is to fly. The starcraft is not passenger, it departs to Haron once a month full of the volunteers and returns back loaded with thorium. This precious metal can be loaded not in all of the compartments. In such a compartments volunteers can return home. All the others are to stay at Haron... Forever.

The compartments are numbered. The numbers of the unfit compartments (and only their numbers) are so that 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 is to summarize the digits of the number; if the result is greater or equal than 10, then the digits of the result are to be summarized again; and so on until one gets a number from 0 to 9.

How many volunteers will return home?

Input

Even integer number N ≤ 200000 – an amount of digits used to number the compartments. There are exactly 10N compartments numbered from 0 to 10N-1 with the leading zeros.

Output

The number of compartments free of thorium on the way home.

Sample

input output
2
10

Problem Author: Leonid Volkov
Problem Source: USU Personal Contest 2004

Tags: none  (hide tags for unsolved problems)

Difficulty: 391

题意:问前一半的数字根和后一半数字的数字根相同的n位数有多少(可以有前缀零)

分析:首先,数字根为零的话显然只能是00....000这样全部是零

然后其他数字根肯定是1-9

令m=n/2(n必为偶数)

前m位共有设为k=10^m-1=99...999(m个9)个数,显然,每个数字根1111...111(m个1)=k/9个数

同样的,后m位共有k个数,显然,每个数字根k/9个数

然后就很显然了。。。

答案就是Ans = k * (k / 9) + 1

写下高精度就好

但是,999...999 * 111..111是有规律的。。。而且很容易找。。

所以高精度都不用写了。。。

 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>
10 #include <map>
11 #include <set>
12 #include <ctime>
13 using namespace std;
14 typedef long long LL;
15 typedef double DB;
16 #define For(i, s, t) for(int i = (s); i <= (t); i++)
17 #define Ford(i, s, t) for(int i = (s); i >= (t); i--)
18 #define Rep(i, t) for(int i = (0); i < (t); i++)
19 #define Repn(i, t) for(int i = ((t)-1); i >= (0); i--)
20 #define rep(i, x, t) for(int i = (x); i < (t); i++)
21 #define MIT (2147483647)
22 #define INF (1000000001)
23 #define MLL (1000000000000000001LL)
24 #define sz(x) ((int) (x).size())
25 #define clr(x, y) memset(x, y, sizeof(x))
26 #define puf push_front
27 #define pub push_back
28 #define pof pop_front
29 #define pob pop_back
30 #define ft first
31 #define sd second
32 #define mk make_pair
33 inline void SetIO(string Name) {
34     string Input = Name+".in",
35     Output = Name+".out";
36     freopen(Input.c_str(), "r", stdin),
37     freopen(Output.c_str(), "w", stdout);
38 }
39
40 inline int Getint() {
41     int Ret = 0;
42     char Ch = ‘ ‘;
43     bool Flag = 0;
44     while(!(Ch >= ‘0‘ && Ch <= ‘9‘)) {
45         if(Ch == ‘-‘) Flag ^= 1;
46         Ch = getchar();
47     }
48     while(Ch >= ‘0‘ && Ch <= ‘9‘) {
49         Ret = Ret*10+Ch-‘0‘;
50         Ch = getchar();
51     }
52     return Flag ? -Ret : Ret;
53 }
54
55 int n;
56
57 inline void Input() {
58     cin>>n;
59 }
60
61 inline void Solve() {
62     n /= 2;
63     if(n == 1) puts("10");
64     else {
65         For(i, 1, n-1) printf("1");
66         printf("0");
67         For(i, 1, n-2) printf("8");
68         printf("90");
69     }
70 }
71
72 int main() {
73     #ifndef ONLINE_JUDGE
74     SetIO("G");
75     #endif
76     Input();
77     Solve();
78     return 0;
79 }

时间: 2024-08-05 02:45:34

ural 1289. One Way Ticket的相关文章

ural 1217. Unlucky Tickets

1217. Unlucky Tickets Time limit: 1.0 secondMemory limit: 64 MB Strange people live in Moscow! Each time in the bus, getting a ticket with a 6-digit number, they try to sum up the first half of digits and the last half of digits. If these two sums ar

Ural 1036 Lucky Tickets

Lucky Tickets Time Limit: 2000ms Memory Limit: 16384KB This problem will be judged on Ural. Original ID: 103664-bit integer IO format: %lld      Java class name: (Any) You are given a number 1 ≤ N ≤ 50. Every ticket has its 2N-digit number. We call a

URAL 2092 Bolero 贪心

C - Bolero Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status Practice URAL 2092 Description Winter in Yekaterinburg is the longest time of the year. And everyone spends long winter evenings in his own way. Den

URAL 1036(dp+高精度)

Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status Practice URAL 1036 Description You are given a number 1 ≤ N ≤ 50. Every ticket has its 2 N-digit number. We call a ticket lucky, if the sum of its first N digi

URAL 1796. Amusement Park (math)

1796. Amusement Park Time limit: 1.0 second Memory limit: 64 MB On a sunny Sunday, a group of children headed by their teacher came to an amusement park. Aunt Frosya,who was a very kind and quiet person, worked at the ticket window on that day. The t

Ural 1081 Binary Lexicographic Sequence(DP)

题目地址:Ural 1081 先用dp求出每个长度下的合法序列(开头为1)的个数.然后求前缀和.会发现正好是一个斐波那契数列.然后每次判断是否大于此时长度下的最少个数,若大于,说明这一位肯定是1,若小于,则肯定是0.就这样不断输出出来即可. 代码如下: #include <iostream> #include <cstdio> #include <string> #include <cstring> #include <stdlib.h> #in

URAL 1684. Jack&#39;s Last Word KMP

题目来源:URAL 1684. Jack's Last Word 题意:输入a b 把b分成若干段 每一段都是a的前缀 思路:b为主串 然后用a匹配b 记录到b的i位置最大匹配的长度 然后分割 分割的时候要从后往前 如果a = abac b = abab 那么如果从前往后 首先覆盖了aba 然后b就不能覆盖了 从后往前就可以了 首先覆盖ab 下一次还是ab 因为已经记录了到i位置的最大匹配长度 根据长度从末尾倒退 每次倒退的时候只要是最大的匹配的长度 因为如果在某一次的递推 记录的最大匹配的前缀

ural 1272. Non-Yekaterinburg Subway

1272. Non-Yekaterinburg Subway Time limit: 1.0 secondMemory limit: 64 MB A little town started to construct a subway. The peculiarity of the town is that it is located on small islands, some of them are connected with tunnels or bridges. The mayor is

ural 1273. Tie

1273. Tie Time limit: 1.0 secondMemory limit: 64 MB The subway constructors are not angels. The work under the ground and… Well, they are not angels. And where have you seen angels? It is all in a lifetime! Show me first somebody who has never… and t