20:球弹跳高度的计算
把心态做崩了,去看了看别人的看看自己哪里不对。。
using namespace std;
int main(){
double h;
cin >>h;
double a=h;
double b=h; //保存高度
for(int i=0;i<10;i++){
h = (double)h/2;
a+=h;
}
cout <<2*a-b-h-h<<endl << h ;
}
最后要减两个h确实脑子没转过来,只减了一个。
21:角谷猜想
#include <iostream>
#include <cmath>
using namespace std;
int main(){
long N;
cin >> N;
while(true){
if(N==1)if(N==1) goto E;
if(N%2==0){
cout << N << "/2=";
N =N/2;
cout << N <<endl;
if(N==1) goto E;
}if(N%2!=0){
cout << N << "*3+1=";
N = N*3+1;
cout << N <<endl;
if(N==1) goto E;
}
}
E:cout << "End";
}
嘛,抄个思路对不对。
while true这个骚点子我还是临时想到的,提交了三遍,第一遍是我信了官网的邪写的int,第二遍是我灵机一动会不会有直接输入1这种可能,我还真skr小天才。
22:(哦) 津津的储蓄计划
我觉得最好还是用数组吧
#include <iostream>
#include <cmath>
#include <cstdlib>
using namespace std;
int main(){
int moe[12];
int myMoe=300;
int give1,give2=0;
cin>>moe[0];
myMoe-=moe[0];
for(int i=1;i<12;i++){
cin >> moe[i];
myMoe+=300;
myMoe-=moe[i];
if(myMoe<0) {cout <<"-"<< i+1; exit(0);}
if(myMoe>=0) give1 =myMoe/100*100;
give2 +=give1;
myMoe-=give1;
}
double All =1.2*give2;
cout << All+myMoe;
}
一个小时,整整一个小时才做出来。。。。虽然是一遍过, 但看来noi的题真是没那么好做啊