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

【补题】多校联合训练第一场

时间:2017-08-02 16:01:00      阅读:309      评论:0      收藏:0      [点我收藏+]

标签:play   for   beginning   iostream   soft   osi   case   lag   contains   

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.
 
Input
The input contains multiple test cases. Each test case in one line contains only one positive integer m, satisfying 1m105.
 
Output
For each test case, output "Case #xy" 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 }
View Code

 

 
 
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.
 
Input
The input consists of multiple test cases. (about 2000)
For each case, there is a line contains two numbers n,k (2n109,1k1018).
 
Output
For each test case, output "Case #xy" 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 }
View Code

 

【补题】多校联合训练第一场

标签:play   for   beginning   iostream   soft   osi   case   lag   contains   

原文地址:http://www.cnblogs.com/roMxx/p/7274312.html

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