1
九阴白骨爪是射雕英雄传里的邪门武功,该武功用人类的头盖骨进行修炼,然后将骷髅头整齐的排在地上或草丛中,3层的排列方案是品字形,既第1行1个,第2行3个,第3行5个;已经有一天梅超风已经修改完成了该门武功,且骷髅头的堆也变得很高,排列规律从未改变。现在她想用计算机来统计一下这堆骷髅头上共有多少个手指洞(请10岁以下同学切莫模仿)Input
输入数据有多组,没组1个数N (1 <= N < 100 ),代表骷髅头的层数;Output
对于每组数据,在1行内输出这堆骷髅头的手指洞总数。Sample Input
12Sample Output
520出题本意是用递归写
#include<cstdio>#include<iostream>using namespace std;long long lhy(int t){ if(t-1>=1) return 2*t-1+lhy(t-1); else return 1;}int main(){ long int i,j,k,p,t; while(cin>>t) { cout<<lhy(t)*5<<endl; } return 0;}2凤舞九天
Problem:B
Time Limit:1000ms
Memory Limit:65536K
Description
“凤舞九天”是陆小凤的一门武功招式,每次出招的攻击次数不同,第1次攻击1次,第2次攻击1次;然后n次的攻击满足下面的公式:f[n]=(6*f[n-1]+8*f[n-2])%9; (n >=3)为啥对9取余呢?因为是凤舞九天啊!要是凤舞七天的话,就对7取余了!Input
输入数据有多组,每组1个数n (1 <= n <=100);Output
对于每组数据,在一行内输出第n次出招时,攻击的次数是多少?Sample Input
13100Sample Output
152这个题告诉我们,算数字的时候可以预处理加速
#include <stdio.h>#include <stdlib.h>#include <math.h>int a[205];int f(int n){ int i; a[1]=1; a[2]=1; for(i=3;i<=100;i++) {a[i]=(6*a[i-1]+8*a[i-2])%9;} return a[i];}int main(){ int n;f(150); while(scanf("%d",&n)!=-1) { printf("%d/n",a[n]); } return 0;}3求导
Problem:C
Time Limit:1000ms
Memory Limit:65536K
Description
大一的同学必须要注意,刚来林大的第一次考试是不及格最多的,因为大家都放松了警惕,最容易挂科的是高等数学,现在我们一起把数学复习一下。已知函数f(x)=3x2+2x+4,则它的导函数可以写成(f(x+h)-f(x))/(x+h-x),即f(x)的导可以表示为:(f(x+h)-f(x))/h,现在给你x和h值,你会计算它的导数吗?Input
输入数据有多组,每组1行,每行2个数x和h,这2个数是实数.Output
按照题中的描述,输出f(x)的导数值,结果保留2位小数,记得用双精度(double)和换行啊!Sample Input
2 0.14 0.1Sample Output
14.3026.30Hint
输入数据多组用while(scanf("%lf%lf",&x,&h)!=EOF),x和h定义成double求导……题目咋说你咋写就行了
#include <stdio.h>#include <stdlib.h>float f(float a){ return 3*a*a+2*a+4;}int main(){ float x,h; while (scanf("%f%f",&x,&h)!=EOF) printf("%.2f/n",(f(x+h)-f(x))/h); return 0;}4大表哥的黑客技术
Problem:D
Time Limit:1000ms
Memory Limit:65536K
Description
大表哥最近在图书馆借了一本黑客入门,学会了如何用360查杀病毒和修复漏洞。现在他无论什么问题都想运用黑客技术来解决,但是由于大表哥太菜了。所以虽然今天这道题很简单。能麻烦你运用函数帮助大表哥解决一下吗?Input
输入一个n,接下来输入n个数a1~an。(n<1000,保证ai<2^32)Output
输出a1~an的平方和。是不是很简单,但是要求用函数哦Sample Input
21 231 2 3Sample Output
514我看好多人把题意想复杂了,没说让你递归读入数据啊
而且啊 怎么都用unsigned long int……用long long 多省事
#include <iostream>#include <cstdio>#include <string.h>#include <algorithm>using namespace std;long long fun(int x,int a[]){ int i; long long sum=0,k; for(i=0;i<x;i++) { k=a[i]; sum+=k*k; } return sum;}int main(){ int n,j; int b[1010]; long long sum1; while(cin>>n) { for(j=0;j<n;j++) scanf("%d",&b[j]); sum1=fun(n,b); cout<<sum1<<endl; }}5字符集合
Problem:E
Time Limit:1000ms
Memory Limit:65535K
Description
编写函数向给定一个字符集合中,插入一个新字符到指定位置:已知一个字符集,给定一个插入位置k,向该位置插入一个新字符。本题10分Input
输入数据有多组,每组的第1行为n(<5),表示一组测试数据中字符集的个数,接下来原始字符串集(字符个数<100),插入的字符及位置;Output
输出插入后的新字符集,每组数据单独一行。Sample Input
3the c testD5Now,you can commit.Y8the game over.N6Sample Output
the cD testNow,you Ycan commit.the gaNme over.Hint
注意原始数据输入时,回车的处理。 输出正常输完一行加个换行。差不多就是下面这个意思吧,
#include<stdio.h>void insert(char str[],char ins,int pos){ int i; for(i=0;i<pos;i++) printf("%c",str[i]); printf("%c",ins); printf("%s/n",str+pos);//后面的字符直接这样输出就好啦~~}int main(){ // freopen("data.in","r",stdin); char str[200]; int T,pos; char ins[2]; scanf("%d",&T); while(T--) { getchar();//读入多余回车换行符号 gets(str); scanf("%s",ins); scanf("%d",&pos); insert(str,ins[0],pos); } return 0;}
新闻热点
疑难解答