b && a > c)cout else{if(b>c)c" />

0 noip阅读程序题 打印版

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

全国信息学奥林匹克竞赛阅读程序题

1、#include

using namespace std;

int main()

{

freopen("d1.in","r",stdin);

freopen("d1.out","w",stdout);

int a, b, c;

a = 1;

b = 2;

c = 3;

if (a > b && a > c)

cout << a << ' ';

else

{

if(b>c)

cout << b << ' ';

else

cout<

}

}

程序运行结果:

3□

2、#include

using namespace std;

int main()

{

freopen("a.in","r",stdin);

freopen("a.out","w",stdout);

int p,q,s,t;

cin>>p;

for(q=p+1;q<=p*2;++q)

{

t=0;

s=(p*q)%(q-p);

if(s==0)

{

t=p+q+(p*q)/(q-p);

cout<

}

}

}

输入:12

根据程序列表分别计算各变量的值:

□181□110□□87□□76□□66□□62□□61□□60

3、#include

using namespace std;

int main()

{

freopen("d1.in","r",stdin);

freopen("d1.out","w",stdout);

int max, min, sum, count=0;

int tmp;

cin >> tmp;

if (tmp == 0)

return 0;

max = min = sum = tmp;

count++;

while(tmp != 0)

{

cin >> tmp;

if (tmp != 0)

{

sum += tmp;

count++;

if (tmp > max)

max = tmp;

if (tmp < min)

min = tmp;

}

}

cout << max <<"," << min << "," << sum / count<< endl; return 0;

}

d1.in

1 2 3 4 5 6 0 7

tmp=1 max=2 min=1 sum=3 count=2

tmp=2 max=3 min=1 sum=6 count=3

tmp=3 max=4 min=1 sum=10 count=4

tmp=4 max=5 min=1 sum=15 count=5

tmp=5 max=6 min=1 sum=21 count=6

tmp=6 {当循环至读入6后,条件tmp<>0为trun, 循环结束,输出结果}

程序运行结果:

6,1,3

4、#include

using namespace std;

long int a,b,n;

int main()

{

freopen("c3.in","r",stdin);

freopen("c3.out","w",stdout);

cin>>n;

a=0;b=0;

do

{ a=a+1;

b=b+a;

}

while (!(b>=n));

cout<

}

输入:20100

输出:

根据程序列表分别计算a、b的值:

从列表中可知:是求a的前n项和。首先应该想到的是前100项和还是前200项和呢?

条件是大于等于20100。

根据前n项和通项公式:

n*(n+1)/2 ,得:

n*(n+1)/2=20100

n*(n+1)=40200

∴n=200 输出:200

5、#include

#include

#include

using namespace std;

int main()

{

freopen("d8.in","r",stdin);

freopen("d8.out","w",stdout);

double d1,d2,x,min;

min=10000; x=3;

while(x<15) {

d1=sqrt(9+(x-3)*(x-3)); {可以理解成平面直角坐标系中点(0,x)至点(3,3)的距离} d2=sqrt(36+(15-x)*(15-x)); {可以理解成平面直角坐标系中点(0,x)到点(6,15)的距离}

if((d1+d2)

cout<

解法:

程序是求x 在0至15之间d1+d2的最小值。即平面直角坐标系中点(0,x)到点(3,3)与到点(6,15)距离和的最小值。利用对称原理,点(0,x)到点(3,3)的距离等于点(0,x)到点(-3,3)的距离。由于两点问直线距离最短,故d1+d2的最小值为点(-3,3)到点(6,15)的直线距离。

15)153()

63(2

2

=+---

6、#include using namespace std; int main() {

freopen("d9.in","r",stdin); freopen("d9.out","w",stdout); int x,y1,y2,y3; cin>>x; y1=0; y2=1; y3=1;

while(y2<=x) {

y1=y1+1; y3=y3+2; y2=y2+y3; }

cout<

输入:23420

相关文档
最新文档