第一次就写出两道水题。
1001. Add More Zero
http://acm.hdu.edu.cn/showproblem.php?pid=6033
答案就是 log10(2^m-1),注意到不存在 10^k = 2^m,所以log10(2^m-1)=log10(2^m)=mlog10(2),这样做的时间复杂度是 O(1) 。
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
int main()
{
int m,t=1;
while(scanf("%d",&m)!=EOF)
{
int k;
k=m*log10(2);
printf("Case #%d: %d\n",t++,k);
}
return 0;
}
刚开始想到了,但忘记了log这个简单函数咋写了。。。。上网查了一下原来这么简单
队友还写了个打表的,都觉得会超时,没想到A了。
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
int num[100010]={};
int j,k;
int m;
double i;
num[0]=0;
for (i=1,j=1;j<=100000;j++)
{
i*=2;
if(i>10)
{
num[j]=num[j-1]+1;
i/=10;
}
else
num[j]=num[j-1];
}
k=0;
while (scanf("%d",&m)!=EOF)
{
k++;
printf("Case #%d: %d\n",k,num[m]);
}
return 0;
}
1006.KazaQ’s Socks
http://acm.hdu.edu.cn/showproblem.php?pid=6043
找规律。
三只袜子:123 12 13 12 13。。。。
四只袜子:1234 123 124 123。。。
最后两个数循环
#include <iostream>
#include <cstdio>
#define ll long long int
using namespace std;
int main()
{
ll n,k,t=1;
while(cin>>n>>k)
{
if(k<=n)
{
cout<<"Case #"<<t++<<": "<<k<<endl;
}
else
{
int m;
k=k-n;
m=(k/(n-1))%2;
if(m==1)
{
if(k%(n-1))
{
cout<<"Case #"<<t++<<": "<<k%(n-1)<<endl;
}
else
{
cout<<"Case #"<<t++<<": "<<n-1<<endl;
}
}
else
{
if(k%(n-1))
{
cout<<"Case #"<<t++<<": "<<k%(n-1)<<endl;
}
else
{
cout<<"Case #"<<t++<<": "<<n<<endl;
}
}
}
}
return 0;
}