补题多校联合训练第一场
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了补题多校联合训练第一场相关的知识,希望对你有一定的参考价值。
1001 Add More Zero
Problem Description
There is a youngster known for amateur propositions concerning several mathematical hard problems.
Nowadays, he is preparing a thought-provoking problem on a specific type of supercomputer which has ability to support calculations of integers between 0 and (2m?1) (inclusive).
As a young man born with ten fingers, he loves the powers of 10 so much, which results in his eccentricity that he always ranges integers he would like to use from 1to 10k (inclusive).
For the sake of processing, all integers he would use possibly in this interesting problem ought to be as computable as this supercomputer could.
Given the positive integer m, your task is to determine maximum possible integer k that is suitable for the specific supercomputer.
Nowadays, he is preparing a thought-provoking problem on a specific type of supercomputer which has ability to support calculations of integers between 0 and (2m?1) (inclusive).
As a young man born with ten fingers, he loves the powers of 10 so much, which results in his eccentricity that he always ranges integers he would like to use from 1to 10k (inclusive).
For the sake of processing, all integers he would use possibly in this interesting problem ought to be as computable as this supercomputer could.
Given the positive integer m, your task is to determine maximum possible integer k that is suitable for the specific supercomputer.
Input
The input contains multiple test cases. Each test case in one line contains only one positive integer m, satisfying 1≤m≤105.
Output
For each test case, output "Case #x: y" in one line (without quotes), where x indicates the case number starting from 1 and y denotes the answer of corresponding case.
Sample Input
1
64
Sample Output
Case #1: 0
Case #2: 19
思路:注意到不存在 10^k = 2^m10?k??=2?m?? ,所以就是?log?10??2?m???=?mlog?10??2?,这样做的时间复杂度是 O(1) 。
1 #include<cstdio> 2 #include<cstring> 3 #include<iostream> 4 #include<algorithm> 5 #include<cmath> 6 #include<vector> 7 #include<set> 8 #include<string> 9 #include<sstream> 10 #include<cctype> 11 #include<map> 12 #include<stack> 13 #include<queue> 14 using namespace std; 15 #define INF 0x3f3f3f3f 16 typedef long long ll; 17 int gcd(int a, int b){return b==0?a:gcd(b,a%b);} 18 19 int m; 20 21 int main() 22 { 23 // freopen("input.txt", "r", stdin); 24 // freopen("output.txt", "w", stdout); 25 int t = 1; 26 while(scanf("%d", &m) != EOF) 27 { 28 cout << "Case #" << t++ << ": " << (int) (log10(2) * m) << endl; 29 } 30 return 0; 31 }
1011 KazaQ‘s Socks
Problem Description
KazaQ wears socks everyday.
At the beginning, he has n pairs of socks numbered from 1 to n in his closets.
Every morning, he puts on a pair of socks which has the smallest number in the closets.
Every evening, he puts this pair of socks in the basket. If there are n?1 pairs of socks in the basket now, lazy KazaQ has to wash them. These socks will be put in the closets again in tomorrow evening.
KazaQ would like to know which pair of socks he should wear on the k-th day.
At the beginning, he has n pairs of socks numbered from 1 to n in his closets.
Every morning, he puts on a pair of socks which has the smallest number in the closets.
Every evening, he puts this pair of socks in the basket. If there are n?1 pairs of socks in the basket now, lazy KazaQ has to wash them. These socks will be put in the closets again in tomorrow evening.
KazaQ would like to know which pair of socks he should wear on the k-th day.
Input
The input consists of multiple test cases. (about 2000)
For each case, there is a line contains two numbers n,k (2≤n≤109,1≤k≤1018).
For each case, there is a line contains two numbers n,k (2≤n≤109,1≤k≤1018).
Output
For each test case, output "Case #x: y" in one line (without quotes), where x indicates the case number starting from 1 and y denotes the answer of corresponding case.
Sample Input
3 7
3 6
4 9
Sample Output
Case #1: 3 Case #2: 1 Case #3: 2
思路:打表,找规律即可。
1 #include<cstdio> 2 #include<cstring> 3 #include<iostream> 4 #include<algorithm> 5 #include<vector> 6 #include<set> 7 #include<string> 8 #include<sstream> 9 #include<cctype> 10 #include<map> 11 using namespace std; 12 #define INF 0x3f3f3f3f 13 14 int main() 15 { 16 // freopen("input.txt", "r", stdin); 17 // freopen("output.txt", "w", stdout); 18 long long n, k; 19 int flag = 0, ans; 20 while(~scanf("%lld%lld", &n, &k)) 21 { 22 if(k <= n) ans = k; 23 else 24 { 25 int x = (k - n) % (2 * (n - 1)); 26 if(x < n && x > 0) ans = x; 27 else if (x == 0) ans = n; 28 else ans = x - n + 1; 29 } 30 printf("Case #%d: %d\n", ++flag, ans); 31 } 32 return 0; 33 }
以上是关于补题多校联合训练第一场的主要内容,如果未能解决你的问题,请参考以下文章
2015多校联合训练第一场Tricks Device(hdu5294)
多校联合训练第一场OO’s Sequence(hdu5288)
2018-2019赛季多校联合新生训练赛第三场(2018/12/8)补题题解