当前位置: 代码迷 >> 综合 >> NOI题库1.3答案
  详细解决方案

NOI题库1.3答案

热度:17   发布时间:2024-02-05 08:33:58.0

第一题 A+B问题

#include<iostream>
using namespace std;
int main()
{
int a,b,c;
cin>>a>>b;
c=a+b;
cout<+<c<<endl;
system("pause");
return 0;
}//之前使用电脑版本的原因,多了一个pause,可用可不用


第二题 计算(a+b)*c的值

#include<iostream>
using namespace std;
int main()
{
int a,b,c,d;
cin>>a>>b>>c;
d=(a+b)*c;
cout<<d<<endl;
system("pause");
return 0;
}//pause在新版本的DEV-C++一样能用,只不过结束时要多按一次任意键


第三题 计算(a+b)/c的值

#include<iostream>
using namespace std;
int main()
{
int a,b,c,d;
cin>>a>>b>>c;
d=(a+b)/c;
cout<<d<<endl;
system("pause");
return 0;
}


第四题 带余除法

#include<iostream>
using namespace std;
int main()
{
int a,b,c,d;
cin>>a>>b;
c=a/b;
d=a%b;
cout<<c<<' '<<d<<endl;
system("pause");
return 0;
}


第五题 计算分数的浮点数值

#include<iostream>
#include<cstdio> //调用printf指令
using namespace std;
int main()
{
double a,b,c;
cin>>a>>b;
c=a/b;
printf("%.9lf",c);//也可以改成printf("%.9lf\n",c);
cout<<endl; //注意\n别写成了/n
system("pause");
return 0;
}


第六题 甲流疫情死亡率

#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
int a,b; 
cin>>a>>b;
float d,e,c; d=a; e=b; c=b/d*100;
printf("%.3f%%",c); 
system("pause");

  return 0;  
}


第七题 计算多项式的值

#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
double a,b,c,d,x,p;
cin>>x>>a>>b>>c>>d;
p=x*x*x*a+x*x*b+x*c+d;
printf("%.7lf",p);
return 0;
}


第八题?温度表达转化

#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
double f,c;
cin>>f;
c=5*(f-32)/9;
printf("%.5lf",c);
return 0;
}


第九题 与圆相关的计算

#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
double r,d,s,c,pi=3.14159;
cin>>r;
d=2*r;//直径=半径*2
s=pi*r*r;//面积=π*半径2
c=d*pi;//周长=π*直径
printf("%.4lf ",d);
printf("%.4lf ",c);
printf("%.4lf",s);
return 0;
}

 

第十题 计算并联电阻的阻值

#include <iostream>
#include <cstdio>
using namespace std;
int main()
{float a,b,r;cin>>a>>b;r=1/(1/a+1/b);printf("%.2lf",r);return 0;
}

 

第十一题 计算浮点数相除的余数

#include <iostream>
using namespace std;
int main()
{double a,b,r;int k;cin>>a>>b;k=a/b;r=a-k*b;cout<<r;return 0;
}

 

第十二题 计算球的体积

#include <iostream>
#include <cstdio>
using namespace std;
int main()
{double r,v,pi=3.14,a;cin>>r;a=4.0/3;v=a*pi*r*r*r;printf("%.2lf",v);return 0;
}

 

第十三题 反向输出一个三位

#include<bits/stdc++.h>
using namespace std;
int main()
{int x,a,b,c;cin>>x;a=x/100;b=(x-a*100)/10;c=x%10;cout<<c<<b<<a;return 0;
}

 

第十四题 大象喝水

#include <iostream>
using namespace std;
int main()
{int h,r,a,b,v=20000;double pi=3.14159;cin>>h>>r;a=v/(pi*r*r*h);b=(int)a+1;cout<<b<<endl;return 0;
}

 

第十六题 苹果和虫子

#include <iostream>
using namespace std;
int main()
{int n,x,y,p;cin>>n>>x>>y;if(y%x==0) p=n-y/x;else p=n-y/x-1;cout<<p;return 0;
}

 

第十六题 计算线段长度

#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
int main()
{double x1,y1,x2,y2,p;cin>>x1>>y1>>x2>>y2;p=sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));printf("%.3lf",p);return 0;
}

 

第十七题 计算三角形面积

#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
int main()
{float x1,y1,x2,y2,x3,y3;float s,p,a,b,c,x,y,z;cin>>x1>>y1>>x2>>y2>>x3>>y3;x=(x2-x1)*(x2-x1)+(y2-y1)*(y2-y1);y=(x3-x1)*(x3-x1)+(y3-y1)*(y3-y1);z=(x3-x2)*(x3-x2)+(y3-y2)*(y3-y2);a=sqrt(x);b=sqrt(y);c=sqrt(z);p=(a+b+c)/2; s=sqrt(p*(p-a)*(p-b)*(p-c));printf("%.2lf",s);return 0;
}

 

第十八题 等差数列末项计算

#include <iostream>
using namespace std;
int main()
{int n,a1,a2,an,d;cin>>a1>>a2>>n;d=a2-a1;an=a1+(n-1)*d;cout<<an;return 0;
}

 

第十九题 A*B问题

#include <bits/stdc++.h>
using namespace std;
int main()
{long long a,b,c;cin>>a>>b;c=a*b;printf("%lld",c);return 0;
}

 

第二十题 计算2的幂

#include<iostream>
using namespace std;
int main()
{int a=1,n,x;cin>>n;for(x=1;x<=n;x++){a=a*2;}cout<<a<<endl;system("pause");return 0;
}
  相关解决方案