先补比较简单的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
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 1 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.
1 64
Case #1: 0 Case #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
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.
For each case, there is a line contains two numbers n,k (2≤n≤109,1≤k≤1018) .
3 7 3 6 4 9
Case #1: 3 Case #2: 1 Case #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