版权声明:置顶文章如需转载请联系作者 https://blog.csdn.net/Bonstoppo/article/details/83902377
网址:蓝桥杯练习系统
蓝桥的题目比PAT的更加诡异,时间要求更加苛刻,很多题目不能一遍通关,所以更是需要耐心。
一、入门训练
001:Fibonacci数列 (AC:简单模拟)
注意要点:这个题目不能使用递归函数,会超时,所以直接简单算即可。
#include<iostream>
using namespace std;
int main(){
int n , n1 = 1 , n2 = 1 , n3;
scanf("%d" , &n);
if(n == 1 || n == 2){ //特殊情况分开写//
printf("1");
}
else{
for(int i = 0 ; i < n - 2; i ++){
n3 = (n1 + n2) % 10007;// 随时取余,防止溢出//
n1 = n2 % 10007;
n2 = n3 % 10007;
}
printf("%d" , n3);
}
return 0;
}
002:圆的面积 (AC:水题 , 精度输出)
注意要点:注意这个π的输出问题。
#include<iostream>
#include<math.h>
using namespace std;
int main(){
int n;
scanf("%d" , &n);
printf("%.7f" , n * n * atan(1.0) * 4 * 1.0);
return 0;
}
003:序列求和 (AC:水题)
注意要点:不要循环求和。
#include<iostream>
using namespace std;
int main(){
long long n;
scanf("%lld" , &n);
printf("%lld" , (1 + n) * n / 2);//等差数列求和公式//
return 0;
}
004:A+B问题 (AC:水题)
注意要点:注意int的范围::-2147483648 ~ 2147483647 2的32次方, 4个字节。
#include<iostream>
using namespace std;
int main(){
int a , b;
scanf("%d %d" , &a , &b);
printf("%d" , a + b);
return 0;
}