最近两天出去玩休息了,没有做题,惭愧~明天中午就出发取深圳了,终于要开始实习了,不知道公司的人的python会不会很虐呢?如果老总有空给我们指导下就好了!毕竟我对麻省理工计算机学院博士生+微软+亚马逊的经历很感兴趣,应该会是一个很强悍的老总吧!
因为很疲倦,所以没有敢挑难题做,虽然最近作的题目都不难,但是今天做的相对更水啦!
第一题HDU1021是一题非常容易看得出规律的题目~╮(╯▽╰)╭
(n+1)%4==3就输出yes,否则就no
/***********************************************************
> OS : Linux 3.2.0-60-generic #91-Ubuntu
> Author : yaolong
> Mail : dengyaolong@yeah.net
> Time : 2014年06月08日 星期日 22:19:23
**********************************************************/
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
using namespace std;
int main(){
int n;
while(scanf("%d",&n)!=EOF){
if((n+1)%4==3){
puts("yes");
}else{
puts("no");
}
}
return 0;
}
第二题其实我看了题解才会做的!后几位就很号办,用取模就可以了,但是前几位我的存档不多,不过大神的解法的确有意思。具体可以参考一下 这里。
我的代码写得很挫呢,明天要继续努力了,哪怕在实习!
/***********************************************************
> OS : Linux 3.2.0-60-generic #91-Ubuntu
> Author : yaolong
> Mail : dengyaolong@yeah.net
> Time : 2014年06月08日 星期日 22:28:53
**********************************************************/
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<cmath>
using namespace std;
int fib[]={0,1,1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610,
987, 1597, 2584, 4181, 6765};
int main(){
int n;
double f=(sqrt(5.0)+1.0)*0.5;
while(scanf("%d",&n)!=EOF){
if(n<=20){
printf("%d\n",fib[n]);
continue;
}
double ans=-0.5*log(5.0)/log(10.0)+(n+0.0)*log(f)/log(10.0);
ans-=(int)ans;
ans=pow(10.0,ans);
while(ans<1000.0){
ans*=10;
}
printf("%d\n",(int)ans);
}
return 0;
}