码迷,mamicode.com
首页 > 其他好文 > 详细

2017-4-29-Train:Codeforces Round #315 (Div. 2)

时间:2017-04-29 13:45:00      阅读:326      评论:0      收藏:0      [点我收藏+]

标签:PFS   case   dash   log   call   each   type   eof   event   

A. Music(数学题)

Little Lesha loves listening to music via his smartphone. But the smartphone doesn‘t have much memory, so Lesha listens to his favorite songs in a well-known social network InTalk.

Unfortunately, internet is not that fast in the city of Ekaterinozavodsk and the song takes a lot of time to download. But Lesha is quite impatient. The song‘s duration is T seconds. Lesha downloads the first S seconds of the song and plays it. When the playback reaches the point that has not yet been downloaded, Lesha immediately plays the song from the start (the loaded part of the song stays in his phone, and the download is continued from the same place), and it happens until the song is downloaded completely and Lesha listens to it to the end. For q seconds of real time the Internet allows you to download q - 1 seconds of the track.

Tell Lesha, for how many times he will start the song, including the very first start.

Input

The single line contains three integers T, S, q (2 ≤ q ≤ 104, 1 ≤ S < T ≤ 105).

Output

Print a single integer — the number of times the song will be restarted.

Examples

input

5 2 2

output

2

input

5 4 7

output

1

input

6 2 3

output

1

Note

In the first test, the song is played twice faster than it is downloaded, which means that during four first seconds Lesha reaches the moment that has not been downloaded, and starts the song again. After another two seconds, the song is downloaded completely, and thus, Lesha starts the song twice.

In the second test, the song is almost downloaded, and Lesha will start it only once.

In the third sample test the download finishes and Lesha finishes listening at the same moment. Note that song isn‘t restarted in this case.

Means:

歌曲总长T,已经下了s,下载速度为每q秒的现实时间能下载下来(q-1)秒 的歌曲,现在开始听歌,如果听到还没下载的地方就从0秒的地方开始replay,求一首歌听完需要从0秒听几次(包括一开始那次),一开始是从0开始的

Solve:

 技术分享

Code:

技术分享
 1 #pragma comment(linker, "/STACK:36777216")
 2 
 3 #include <bits/stdc++.h>
 4 using namespace std;
 5 #define LSON            id << 1 , l , mid
 6 #define RSON            id << 1 | 1 , mid + 1 , r
 7 #define ROOT            1 , 1 , n
 8 #define CLR(x , y)      memset(x , y , sizeof(x))
 9 #define LOWBIT(x)       x & (-x)
10 #define FORN(i , a , n)  for(int i = (a) ; i <= (n) ; ++i)
11 #define FORP(i , n , a)  for(int i = (n) ; i >= (a) ; --i)
12 #define CASE(x)        printf("Case %d: ", x)
13 #define SFD(x)      scanf("%lf" , &x)
14 #define SFC(x)      scanf(" %c" , &x)
15 #define SFS(x)      scanf(" %s" , x)
16 #define SFI(x)      scanf("%d" , &x)
17 #define SFI64(x)    scanf("%I64d" , &x)
18 #define PFF(x)         printf("%f" , x)
19 #define PFD(x)         printf("%lf" , x)
20 #define PFI(x)         printf("%d" , x)
21 #define PFC(x)         printf("%c" , x)
22 #define PFS(x)         printf("%s" , x)
23 #define PFI64(x)       printf("%I64d" , x)
24 #define SPACE          printf(" ")
25 #define PUT            puts("")
26 #define LPUP(i , j , k) for(int i = j ; i <= k ; ++i)
27 #define LPDW(i , j , k) for(int i = j ; i >= k ; --i)
28 #define PB(x)          push_back(x)
29 #define ALL(A)         A.begin(), A.end()
30 #define SZ(A)          int((A).size())
31 #define LBD(A, x)      (lower_bound(ALL(A), x) - A.begin())
32 #define UBD(A, x)      (upper_bound(ALL(A), x) - A.begin())
33 #define LOCAL
34 static const double PI = acos(-1.0);
35 static const double EPS = 1e-8;
36 static const int INF = 0X3fffffff;
37 typedef __int64 LL;
38 typedef double DB;
39 template<class T> inline
40 T read(T &x)
41 {
42     x = 0;
43     int f = 1 ; char ch = getchar();
44     while (ch < 0 || ch > 9) {if (ch == -) f = -1; ch = getchar();}
45     while (ch >= 0 && ch <= 9) {x = x * 10 + ch - 0; ch = getchar();}
46     x *= f;
47 }
48 
49 /************************Little Pea****************************/
50 
51 int t , s , q;
52 int main()
53 {
54 #ifndef ONLINE_JUDGE
55     freopen("D:\\系统优化\\Desktop\\littlepea\\in.data" , "r" , stdin);
56 #endif
57     read(t);read(s);read(q);
58     int ans = 1;int x = q * s;
59     while(x < t)
60     {
61         ++ans;
62         x *= q;
63     }
64     PFI(ans);
65 #ifndef ONLINE_JUDGE
66     fclose(stdin), fclose(stdout);
67 #endif
68 }
View Code

B. Inventory(贪心 + 模拟)

Companies always have a lot of equipment, furniture and other things. All of them should be tracked. To do this, there is an inventory number assigned with each item. It is much easier to create a database by using those numbers and keep the track of everything.

During an audit, you were surprised to find out that the items are not numbered sequentially, and some items even share the same inventory number! There is an urgent need to fix it. You have chosen to make the numbers of the items sequential, starting with 1. Changing a number is quite a time-consuming process, and you would like to make maximum use of the current numbering.

You have been given information on current inventory numbers for n items in the company. Renumber items so that their inventory numbers form a permutation of numbers from 1 to n by changing the number of as few items as possible. Let us remind you that a set of n numbers forms a permutation if all the numbers are in the range from 1 to n, and no two numbers are equal.

Input

The first line contains a single integer n — the number of items (1 ≤ n ≤ 105).

The second line contains n numbers a1, a2, ..., an (1 ≤ ai ≤ 105) — the initial inventory numbers of the items.

Output

Print n numbers — the final inventory numbers of the items in the order they occur in the input. If there are multiple possible answers, you may print any of them.

Examples

input

3
1 3 2

output

1 3 2

input

4
2 2 3 3

output

2 1 3 4

input

1
2

output

1

Note

In the first test the numeration is already a permutation, so there is no need to change anything.

In the second test there are two pairs of equal numbers, in each pair you need to replace one number.

In the third test you need to replace 2 by 1, as the numbering should start from one.

Means:

给你n个数,每次每个数可以变成另一个数,问你能否用最少的次数变成1~n的排列

Solve:

直接模拟,记录贪心的改变前面多次出现的数

Code:

技术分享
 1 #pragma comment(linker, "/STACK:36777216")
 2 
 3 #include <bits/stdc++.h>
 4 using namespace std;
 5 #define LSON            id << 1 , l , mid
 6 #define RSON            id << 1 | 1 , mid + 1 , r
 7 #define ROOT            1 , 1 , n
 8 #define CLR(x , y)      memset(x , y , sizeof(x))
 9 #define LOWBIT(x)       x & (-x)
10 #define FORN(i , a , n)  for(int i = (a) ; i <= (n) ; ++i)
11 #define FORP(i , n , a)  for(int i = (n) ; i >= (a) ; --i)
12 #define CASE(x)        printf("Case %d: ", x)
13 #define SFD(x)      scanf("%lf" , &x)
14 #define SFC(x)      scanf(" %c" , &x)
15 #define SFS(x)      scanf(" %s" , x)
16 #define SFI(x)      scanf("%d" , &x)
17 #define SFI64(x)    scanf("%I64d" , &x)
18 #define PFF(x)         printf("%f" , x)
19 #define PFD(x)         printf("%lf" , x)
20 #define PFI(x)         printf("%d" , x)
21 #define PFC(x)         printf("%c" , x)
22 #define PFS(x)         printf("%s" , x)
23 #define PFI64(x)       printf("%I64d" , x)
24 #define SPACE          printf(" ")
25 #define PUT            puts("")
26 #define LPUP(i , j , k) for(int i = j ; i <= k ; ++i)
27 #define LPDW(i , j , k) for(int i = j ; i >= k ; --i)
28 #define PB(x)          push_back(x)
29 #define ALL(A)         A.begin(), A.end()
30 #define SZ(A)          int((A).size())
31 #define LBD(A, x)      (lower_bound(ALL(A), x) - A.begin())
32 #define UBD(A, x)      (upper_bound(ALL(A), x) - A.begin())
33 #define LOCAL
34 static const double PI = acos(-1.0);
35 static const double EPS = 1e-8;
36 static const int INF = 0X3fffffff;
37 typedef __int64 LL;
38 typedef double DB;
39 template<class T> inline
40 T read(T &x)
41 {
42     x = 0;
43     int f = 1 ; char ch = getchar();
44     while (ch < 0 || ch > 9) {if (ch == -) f = -1; ch = getchar();}
45     while (ch >= 0 && ch <= 9) {x = x * 10 + ch - 0; ch = getchar();}
46     x *= f;
47 }
48 
49 /************************Little Pea****************************/
50 
51 static const int MAXN = 1e5 + 10;
52 int vis[MAXN];
53 int n;
54 int x;
55 int data[MAXN];
56 int main()
57 {
58 #ifndef ONLINE_JUDGE
59     freopen("D:\\系统优化\\Desktop\\littlepea\\in.data" , "r" , stdin);
60 #endif
61     read(n);
62     vector<int> v;
63     LPUP(i , 1 , n)
64     {
65         read(x);
66         ++vis[x];
67         data[i] = x;
68     }
69     LPUP(i , 1 , n)
70     {
71         if(vis[i] < 1)
72             v.push_back(i);
73     }
74     int pos = 0;
75     LPUP(i , 1 , n)
76     {
77         if(vis[data[i]] >= 2 || data[i] > n)
78         {
79             --vis[data[i]];
80             data[i] = v[pos++];
81         }
82     }
83     LPUP(i , 1 , n)
84     {
85         PFI(data[i]);SPACE;
86     }
87 #ifndef ONLINE_JUDGE
88     fclose(stdin), fclose(stdout);
89 #endif
90 }
View Code

C. Primes or Palindromes?(数学)

Rikhail Mubinchik believes that the current definition of prime numbers is obsolete as they are too complex and unpredictable. A palindromic number is another matter. It is aesthetically pleasing, and it has a number of remarkable properties. Help Rikhail to convince the scientific community in this!

Let us remind you that a number is called prime if it is integer larger than one, and is not divisible by any positive integer other than itself and one.

Rikhail calls a number a palindromic if it is integer, positive, and its decimal representation without leading zeros is a palindrome, i.e. reads the same from left to right and right to left.

One problem with prime numbers is that there are too many of them. Let‘s introduce the following notation: π(n) — the number of primes no larger than nrub(n) — the number of palindromic numbers no larger than n. Rikhail wants to prove that there are a lot more primes than palindromic ones.

He asked you to solve the following problem: for a given value of the coefficient A find the maximum n, such that π(n) ≤ A·rub(n).

Input

The input consists of two positive integers pq, the numerator and denominator of the fraction that is the value of A (, ).

Output

If such maximum number exists, then print it. Otherwise, print "Palindromic tree is better than splay tree" (without the quotes).

Examples

input

1 1

output

40

input

1 42

output

1

input

6 4

output

172

Means:

π(n)代表n以内素数的个数,rub(n)代表n以内回文数的个数,现在给出p,q问你使得π(n)≤ (p/q)·rub(n)的最大n是多少

Solve:

暴力了一下最大使得π(n) > 42 * rub(n)n1178707左右,所以枚举n大小到1e7就可以了,预处理素数

Code:

技术分享
  1 #pragma comment(linker, "/STACK:36777216")
  2 
  3 #include <bits/stdc++.h>
  4 using namespace std;
  5 #define LSON            id << 1 , l , mid
  6 #define RSON            id << 1 | 1 , mid + 1 , r
  7 #define ROOT            1 , 1 , n
  8 #define CLR(x , y)      memset(x , y , sizeof(x))
  9 #define LOWBIT(x)       x & (-x)
 10 #define FORN(i , a , n)  for(int i = (a) ; i <= (n) ; ++i)
 11 #define FORP(i , n , a)  for(int i = (n) ; i >= (a) ; --i)
 12 #define CASE(x)        printf("Case %d: ", x)
 13 #define SFD(x)      scanf("%lf" , &x)
 14 #define SFC(x)      scanf(" %c" , &x)
 15 #define SFS(x)      scanf(" %s" , x)
 16 #define SFI(x)      scanf("%d" , &x)
 17 #define SFI64(x)    scanf("%I64d" , &x)
 18 #define PFF(x)         printf("%f" , x)
 19 #define PFD(x)         printf("%lf" , x)
 20 #define PFI(x)         printf("%d" , x)
 21 #define PFC(x)         printf("%c" , x)
 22 #define PFS(x)         printf("%s" , x)
 23 #define PFI64(x)       printf("%I64d" , x)
 24 #define SPACE          printf(" ")
 25 #define PUT            puts("")
 26 #define LPUP(i , j , k) for(int i = j ; i <= k ; ++i)
 27 #define LPDW(i , j , k) for(int i = j ; i >= k ; --i)
 28 #define PB(x)          push_back(x)
 29 #define ALL(A)         A.begin(), A.end()
 30 #define SZ(A)          int((A).size())
 31 #define LBD(A, x)      (lower_bound(ALL(A), x) - A.begin())
 32 #define UBD(A, x)      (upper_bound(ALL(A), x) - A.begin())
 33 #define LOCAL
 34 static const double PI = acos(-1.0);
 35 static const double EPS = 1e-8;
 36 static const int INF = 0X3fffffff;
 37 typedef __int64 LL;
 38 typedef double DB;
 39 template<class T> inline
 40 T read(T &x)
 41 {
 42     x = 0;
 43     int f = 1 ; char ch = getchar();
 44     while (ch < 0 || ch > 9) {if (ch == -) f = -1; ch = getchar();}
 45     while (ch >= 0 && ch <= 9) {x = x * 10 + ch - 0; ch = getchar();}
 46     x *= f;
 47 }
 48 
 49 /************************Little Pea****************************/
 50 
 51 static const LL MAXN = 1e7 + 10;
 52 bool is_prime[MAXN];
 53 int prime[MAXN];
 54 int n;
 55 int pos = 0;
 56 void Prime()
 57 {
 58     LPUP(i , 2 , MAXN - 5)
 59     {
 60         is_prime[i] = 1;
 61     }
 62     LPUP(i , 2 , MAXN - 10)
 63     {
 64         if(is_prime[i])
 65             prime[++pos] = i;
 66         LPUP(j , 1 , pos)
 67         {
 68             if(i * prime[j] > (MAXN - 10))
 69                 break;
 70             is_prime[i * prime[j]] = 0;
 71             if(i % prime[j] == 0)
 72                 break;
 73         }
 74     }
 75 }
 76 int Re(int x)
 77 {
 78     int ret = 0;
 79     while(x)
 80     {
 81         int tp = x % 10;
 82         ret = ret * 10 + tp;
 83         x /= 10;
 84     }
 85     return ret;
 86 }
 87 bool IsHui(int x)
 88 {
 89     return (Re(x) == x);
 90 }
 91 LL hui = 0;
 92 LL pp = 0;
 93 LL p , q;
 94 int ans;
 95 int main()
 96 {
 97 #ifndef ONLINE_JUDGE
 98     freopen("D:\\系统优化\\Desktop\\littlepea\\in.data" , "r" , stdin);
 99 #endif
100     read(p);read(q);
101     Prime();
102     /*LPUP(i , 1 , n)///判断什么时候pi(n) > 42 * rub(n),得到为n = 1178707
103     {
104         if(IsHui(i))
105             ++hui;
106         if(is_prime[i])
107             ++pp;
108         if(pp > 42 * hui)
109         {
110             PFI(i);
111             return 0;
112         }
113     }*/
114     bool flag = 0;
115     LPUP(i , 1 , 10000000)
116     {
117         if(is_prime[i])
118             ++pp;
119         if(IsHui(i))
120             ++hui;
121         if(pp * q <= p * hui)
122         {
123             ans = i;
124             flag = 1;
125         }
126     }
127     if(flag)
128         PFI(ans);
129     else
130         PFS("Palindromic tree is better than splay tree");
131 #ifndef ONLINE_JUDGE
132     fclose(stdin), fclose(stdout);
133 #endif
134 }
View Code

 

2017-4-29-Train:Codeforces Round #315 (Div. 2)

标签:PFS   case   dash   log   call   each   type   eof   event   

原文地址:http://www.cnblogs.com/jianglingxin/p/6784947.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!