补题: 1001. Add More Zero 1011KazaQ's Socks

来源:互联网 发布:微信朋友圈数据采集 编辑:程序博客网 时间:2024/06/03 02:56

先补比较简单的1001 和1011,最后再来看1002


1001

                         Add More Zero

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 2245    Accepted Submission(s): 1053


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 between0 and (2m1) (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 from1 to 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 integerm, satisfying 1m105.
 
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
164
 

Sample Output
Case #1: 0Case #2: 19
题目分析:

答案就是:⌊log10(2m−1),注意到不存在10k=2m10^k = 2^m ,所以⌊log10(2m−1)⌋=⌊log102m⌋=⌊mlog102

AC代码

#include<iostream>#include<cstdio>using namespace std;int main(){    double a=0.301029995663;    int m;    int l=0;    while(scanf("%d",&m)!=EOF)    {        l++;        cout<<"Case #"<<l<<": "<<(int)(m*a)<<endl;    }    return 0;}

              KazaQ's Socks

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 2375    Accepted Submission(s): 1074


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 n1 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 thek-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 #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 73 64 9
 

Sample Output
Case #1: 3Case #2: 1Case #3: 2

题意:KazaQ 有n双袜子,按1到n编号放在柜子里,他早上选一双穿,号码小的优先,晚上把穿的袜子放篮子里,当篮子里的袜子达到n-1双时,他会洗袜子,第二天晚上会把洗过的袜子放到柜子里,问第k天他穿的是哪双袜子?

题目分析:

n=3时

n k ans

3 1 1

3 2 2

3 3 3

3 4 1

3 5 2

3 6 1

3 7 3

3 8 1

3 9 2

3 10 1

3 11 3

。。。。。。


n=4时

n k ans

4 1 1

4 2 2

4 3 3

3 4 4

4 5 1

4 6 2

4 7 3

4 8 1

4 9 2

4 10 4

4 11 1

4 12 2

4 13 3

4 14 1

4 15 2

4 16 4


观察规律:前n天,第i天袜子是i,之后,天数-n,即i-n, n-1为周期,第i天, (i-n)%(n-1) 不为0, 袜子为(i-n)%(n-1),否则 (i-n)/(n-1)为奇数 袜子n-1 ;

(i-n)/(n-1)为偶数,袜子为n。

AC代码

#include<cstdio>#include<iostream>using namespace std;int main(){    long long n,k;    int t=0;    while(scanf("%lld%lld",&n,&k)!=EOF)    {        t++;        cout<<"Case #"<<t<<": ";        if(k<=n)        {            cout<<k<<endl;            continue;        }        else        {            long long m=(k-n)%(n-1);            if(m==0)                m=n;            long long rare=(k-n)/(n-1);            if(m<n-1)            {                cout<<m<<endl;            }            else            {                if(rare%2)                    cout<<n-1<<endl;                else                    cout<<n<<endl;            }        }    }    return 0;}



\left \lfloor \log_{10}(2^m - 1) \right \rfloor = \left \lfloor \log_{10}{2^m} \right \rfloor = \left \lfloor m \log_{10}{2} \right \rfloor