1.5编程基础之循环控制
Portal:http://noi.openjudge.cn/ch0105/
01 http://noi.openjudge.cn/ch0105/01/
求平均数
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<iostream> #include<algorithm> #include<set> #include<cstdlib> #include<cstdio> using namespace std; #define FOR(i,j,k) for(int i=j;i<=k;i++) #define FORD(i,j,k) for(int i=j;i>=k;i--) int a[110]; int main() { int n; double ans=0; cin>>n; FOR(i,1,n) { cin>>a[i]; ans+=a[i]; } printf("%.2f", ans/n); return 0; }
02 http://noi.openjudge.cn/ch0105/02/
求平均数
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<iostream> #include<algorithm> #include<set> #include<cstdlib> #include<cstdio> using namespace std; #define FOR(i,j,k) for(int i=j;i<=k;i++) #define FORD(i,j,k) for(int i=j;i>=k;i--) double a[20]; int main() { double ans=0; FOR(i,1,12) { cin>>a[i]; ans+=a[i]; } printf("$%.2f", ans/12); return 0; }
03 http://noi.openjudge.cn/ch0105/03/
呵 求平均数
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<iostream> #include<algorithm> #include<set> #include<cstdlib> #include<cstdio> using namespace std; #define FOR(i,j,k) for(int i=j;i<=k;i++) #define FORD(i,j,k) for(int i=j;i>=k;i--) double a[110]; int main() { int n; double ans=0; cin>>n; FOR(i,1,n) { cin>>a[i]; ans+=a[i]; } printf("%.4f", ans/n); return 0; }
04 http://noi.openjudge.cn/ch0105/04/
求整数的和与均值
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<iostream> #include<algorithm> #include<set> #include<cstdlib> #include<cstdio> using namespace std; #define FOR(i,j,k) for(int i=j;i<=k;i++) #define FORD(i,j,k) for(int i=j;i>=k;i--) int a[10010]; int main() { int n; double ans=0; cin>>n; FOR(i,1,n) { cin>>a[i]; ans+=a[i]; } printf("%.lf %.5f",ans,ans/n); return 0; }
05 http://noi.openjudge.cn/ch0105/05/
求最大值
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<iostream> #include<algorithm> #include<set> #include<cstdlib> #include<cstdio> using namespace std; #define FOR(i,j,k) for(int i=j;i<=k;i++) #define FORD(i,j,k) for(int i=j;i>=k;i--) int a[110]; int main() { int n,max; cin>>n; FOR(i,1,n) cin>>a[i]; max=a[1]; FOR(i,2,n) if(a[i]>max) max=a[i]; cout<<max; return 0; }
06 http://noi.openjudge.cn/ch0105/06/
求最大值减去最小值
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<iostream> #include<algorithm> #include<set> #include<cstdlib> #include<cstdio> using namespace std; #define FOR(i,j,k) for(int i=j;i<=k;i++) #define FORD(i,j,k) for(int i=j;i>=k;i--) int a[1010]; int main() { int n,max,min; cin>>n; FOR(i,1,n) cin>>a[i]; max=a[1]; FOR(i,2,n) if(a[i]>max) max=a[i]; min=a[1]; FOR(i,2,n) if(a[i]<min) min=a[i]; cout<<max-min; return 0; }
07 http://noi.openjudge.cn/ch0105/07/
奥运奖牌计数
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<iostream> #include<algorithm> #include<set> #include<cstdlib> #include<cstdio> using namespace std; #define FOR(i,j,k) for(int i=j;i<=k;i++) #define FORD(i,j,k) for(int i=j;i>=k;i--) int a[4]; int main() { int n,b,c,d; cin>>n; FOR(i,1,n) { cin>>b>>c>>d; a[1]+=b; a[2]+=c; a[3]+=d; } cout<<a[1]<<' '<<a[2]<<' '<<a[3]<<' '<<a[1]+a[2]+a[3]; return 0; }
08 http://noi.openjudge.cn/ch0105/08/
给出多边形边数及n-1个内角大小,求剩下的一个角大小
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<iostream> #include<algorithm> #include<set> #include<cstdlib> #include<cstdio> using namespace std; #define FOR(i,j,k) for(int i=j;i<=k;i++) #define FORD(i,j,k) for(int i=j;i>=k;i--) int a[4]; int main() { int n,ans,x; cin>>n; ans=(n-2)*180; FOR(i,1,n-1) { cin>>x; ans-=x; } cout<<ans; return 0; }
09 http://noi.openjudge.cn/ch0105/09/
求[m,n]中所有奇数的和
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<iostream> #include<algorithm> #include<set> #include<cstdlib> #include<cstdio> using namespace std; #define FOR(i,j,k) for(int i=j;i<=k;i++) #define FORD(i,j,k) for(int i=j;i>=k;i--) #define LL long long int a[4]; int main() { int m,n; cin>>m>>n; LL ans=0; FOR(i,m,n) if(i%2) ans+=i; cout<<ans; return 0; }
10 http://noi.openjudge.cn/ch0105/10/
求[m,n]中所有是17整数倍数的和
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<iostream> #include<algorithm> #include<set> #include<cstdlib> #include<cstdio> using namespace std; #define FOR(i,j,k) for(int i=j;i<=k;i++) #define FORD(i,j,k) for(int i=j;i>=k;i--) #define LL long long int a[4]; int main() { int m,n; cin>>m>>n; LL ans=0; FOR(i,m,n) if(i%17==0) ans+=i; cout<<ans; return 0; }
11 http://noi.openjudge.cn/ch0105/11/
给定k(1<k<100)个正整数,其中每个数都是大于等于1,小于等于10的数。写程序计算给定的k个正整数中,1,5和10出现的次数。
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<iostream> #include<algorithm> #include<set> #include<cstdlib> #include<cstdio> using namespace std; #define FOR(i,j,k) for(int i=j;i<=k;i++) #define FORD(i,j,k) for(int i=j;i>=k;i--) #define LL long long int a[4]; int main() { int n,x; cin>>n; int a,b,c; a=0; b=0; c=0; FOR(i,1,n) { cin>>x; if (x==10) c++; else if(x==5) b++; else if(x==1) a++; } cout<<a<<endl<<b<<endl<<c<<endl; return 0; }
12 http://noi.openjudge.cn/ch0105/12/
输出一个整数序列中与指定数字相同的数的个数。
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<iostream> #include<algorithm> #include<set> #include<cstdlib> #include<cstdio> using namespace std; #define FOR(i,j,k) for(int i=j;i<=k;i++) #define FORD(i,j,k) for(int i=j;i>=k;i--) #define LL long long int a[4]; int main() { int n,m,x; int sum=0; cin>>n>>m; FOR(i,1,n) { cin>>x; if(x==m) sum++; } cout<<sum; return 0; }
13 http://noi.openjudge.cn/ch0105/13/
给出一个整数a和一个正整数n,求乘方an。
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<iostream> #include<algorithm> #include<set> #include<cstdlib> #include<cstdio> using namespace std; #define FOR(i,j,k) for(int i=j;i<=k;i++) #define FORD(i,j,k) for(int i=j;i>=k;i--) #define LL long long int a[4]; int main() { int a,n; cin>>a>>n; LL ans=1; FOR(i,1,n) ans*=a; cout<<ans; return 0; }
14 http://noi.openjudge.cn/ch0105/14/
我国现有x亿人口,按照每年0.1%的增长速度,n年后将有多少人?输出最后的人口数,以亿为单位,保留到小数点后四位。
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<iostream> #include<algorithm> #include<set> #include<cstdlib> #include<cstdio> using namespace std; #define FOR(i,j,k) for(int i=j;i<=k;i++) #define FORD(i,j,k) for(int i=j;i>=k;i--) #define LL long long int a[4]; int main() { double x,n,ans; cin>>x>>n; ans=x; FOR(i,1,n) ans*=1.001; printf("%.4f",ans); return 0; }
15 http://noi.openjudge.cn/ch0105/15/
USACO银行利息
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<iostream> #include<algorithm> #include<set> #include<cstdlib> #include<cstdio> using namespace std; #define FOR(i,j,k) for(int i=j;i<=k;i++) #define FORD(i,j,k) for(int i=j;i>=k;i--) #define LL long long int a[4]; int main() { double r,m,y; cin>>r>>m>>y; double ans; ans=m; FOR(i,1,y) ans*=(1+r*0.01); int ansz; ansz=ans/1; cout<<ansz; return 0; }
16 http://noi.openjudge.cn/ch0105/16/
很阴险,文字题,买房子
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<iostream> #include<algorithm> #include<set> #include<cstdlib> #include<cstdio> using namespace std; #define FOR(i,j,k) for(int i=j;i<=k;i++) #define FORD(i,j,k) for(int i=j;i>=k;i--) #define LL long long int a[4]; int main() { int n,k,ans; cin>>n>>k; double h; h=200; ans=1; while(ans*n<h&&ans<=20) { ans++; h*=(1+0.01*k); } if (ans==21) cout<<"Impossible"; else cout<<ans; return 0; }
17 http://noi.openjudge.cn/ch0105/17/
菲波那契数列是指这样的数列: 数列的第一个和第二个数都为1,接下来每个数都等于前面2个数之和。
给出一个正整数k,要求菲波那契数列中第k个数是多少。
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<iostream> #include<algorithm> #include<set> #include<cstdlib> #include<cstdio> using namespace std; #define FOR(i,j,k) for(int i=j;i<=k;i++) #define FORD(i,j,k) for(int i=j;i>=k;i--) #define LL long long int a[4]; int main() { int k; cin>>k; if (k==1) cout<<1; else if (k==2) cout<<1; else { LL a=1; LL b=1; LL c=2; FOR(i,3,k) { c=a+b; a=b; b=c; } cout<<c; } return 0; }
18 http://noi.openjudge.cn/ch0105/18/
鸡尾酒疗法
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<iostream> #include<algorithm> #include<set> #include<cstdlib> #include<cstdio> using namespace std; #define FOR(i,j,k) for(int i=j;i<=k;i++) #define FORD(i,j,k) for(int i=j;i>=k;i--) #define LL long long int a[4]; int main() { int n; double x,y,xx,yy; cin>>n; cin>>x>>y; xx=y/x; FOR(i,1,n-1) { cin>>x>>y; yy=y/x; if (yy-xx>0.05) cout<<"better"<<endl; else if (xx-yy>0.05) cout<<"worse"<<endl; else cout<<"same"<<endl; } return 0; }
19 http://noi.openjudge.cn/ch0105/19/
救援
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<iostream> #include<algorithm> #include<set> #include<cstdlib> #include<cstdio> #include<cmath> using namespace std; #define FOR(i,j,k) for(int i=j;i<=k;i++) #define FORD(i,j,k) for(int i=j;i>=k;i--) #define LL long long int a[4]; int main() { int n; cin>>n; double x,y,z; double t=0.0; FOR(i,1,n) { cin>>x>>y>>z; t+=sqrt(x*x+y*y)/25+z*1.5; } if (int(t)==t) cout<<int(t); else cout<<int(t)+1; return 0; }
20 http://noi.openjudge.cn/ch0105/20/
球弹跳高度的计算 "第10次落地时,共经过多少米? " 好算计
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<iostream> #include<algorithm> #include<set> #include<cstdlib> #include<cstdio> #include<cmath> using namespace std; #define FOR(i,j,k) for(int i=j;i<=k;i++) #define FORD(i,j,k) for(int i=j;i>=k;i--) #define LL long long int a[4]; int main() { double ans=0; double sum=0; cin>>ans; FOR(i,1,10) { sum+=ans+ans/2; ans/=2; } cout<<sum-ans<<endl<<ans<<endl; return 0; }
21 http://noi.openjudge.cn/ch0105/21/
角谷猜想 算计!中间结果超过maxint
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<iostream> #include<algorithm> #include<set> #include<cstdlib> #include<cstdio> #include<cmath> using namespace std; #define FOR(i,j,k) for(int i=j;i<=k;i++) #define FORD(i,j,k) for(int i=j;i>=k;i--) #define LL long long int a[4]; int main() { LL n; cin>>n; while(n!=1) { if (n%2) {cout<<n<<"*3+1="<<n*3+1<<endl; n=n*3+1;} else {cout<<n<<"/2="<<n/2<<endl; n=n/2;} } cout<<"End"; return 0; }
22 http://noi.openjudge.cn/ch0105/22/
津津的储蓄计划
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<iostream> #include<algorithm> #include<set> #include<cstdlib> #include<cstdio> #include<cmath> using namespace std; #define FOR(i,j,k) for(int i=j;i<=k;i++) #define FORD(i,j,k) for(int i=j;i>=k;i--) #define LL long long int a[12]; int main() { int mm=0; int jj=0; int x; FOR(i,1,12) cin>>a[i]; FOR(i,1,12) { x=a[i]; jj+=300-x; if (jj<0) {cout<<-i;break;} mm+=jj/100; jj%=100; } if (jj>=0) cout<<mm*120+jj; return 0; }
23 http://noi.openjudge.cn/ch0105/23/
药房管理
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<iostream> #include<algorithm> #include<set> #include<cstdlib> #include<cstdio> #include<cmath> using namespace std; #define FOR(i,j,k) for(int i=j;i<=k;i++) #define FORD(i,j,k) for(int i=j;i>=k;i--) #define LL long long int main() { int m,n,x,ans=0; cin>>m>>n; FOR(i,1,n) { cin>>x; m-=x; if(m<0){m+=x;ans++;} } cout<<ans; return 0; }
24 http://noi.openjudge.cn/ch0105/24/
正常血压
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<iostream> #include<algorithm> #include<set> #include<cstdlib> #include<cstdio> #include<cmath> using namespace std; #define FOR(i,j,k) for(int i=j;i<=k;i++) #define FORD(i,j,k) for(int i=j;i>=k;i--) #define LL long long int main() { int n,x,y; int sum=0; int max=0; cin>>n; FOR(i,1,n) { cin>>x>>y; if (90<=x&&x<=140) if (60<=y&&y<=90) sum++; else sum=0; else sum=0; if(sum>max) max=sum; } cout<<max; return 0; }
25 http://noi.openjudge.cn/ch0105/25/
求特殊自然数 答案题
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<iostream> #include<algorithm> #include<set> #include<cstdlib> #include<cstdio> #include<cmath> using namespace std; #define FOR(i,j,k) for(int i=j;i<=k;i++) #define FORD(i,j,k) for(int i=j;i>=k;i--) #define LL long long int a[14]; int b[14]; int main() { cout<<248<<endl<<503<<endl<<305; return 0; }
26 http://noi.openjudge.cn/ch0105/26/
统计满足条件的4位数个数
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<iostream> #include<algorithm> #include<set> #include<cstdlib> #include<cstdio> #include<cmath> using namespace std; #define FOR(i,j,k) for(int i=j;i<=k;i++) #define FORD(i,j,k) for(int i=j;i>=k;i--) #define LL long long int main() { int n,x; cin>>n; int ans=0; FOR(i,1,n) { cin>>x; int f=x%10; x/=10; while(x>0) { f-=x%10; x/=10; } if (f>0) ans++; } cout<<ans; return 0; }
27 http://noi.openjudge.cn/ch0105/27/
级数求和
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<iostream> #include<algorithm> #include<set> #include<cstdlib> #include<cstdio> #include<cmath> using namespace std; #define FOR(i,j,k) for(int i=j;i<=k;i++) #define FORD(i,j,k) for(int i=j;i>=k;i--) #define LL long long int main() { double k,n; double sn=0; cin>>k; n=1; while(sn<=k) { sn+=1/n; n++; } cout<<int(n-1); return 0; }
28 http://noi.openjudge.cn/ch0105/28/
分离整数的各个数位
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<iostream> #include<algorithm> #include<set> #include<cstdlib> #include<cstdio> #include<cmath> using namespace std; #define FOR(i,j,k) for(int i=j;i<=k;i++) #define FORD(i,j,k) for(int i=j;i>=k;i--) #define LL long long int main() { int n; cin>>n; cout<<n%10; n/=10; while(n>0) { cout<<' '<<n%10; n/=10; } return 0; }
29 http://noi.openjudge.cn/ch0105/29/
数字反转
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<iostream> #include<algorithm> #include<set> #include<cstdlib> #include<cstdio> #include<cmath> using namespace std; #define FOR(i,j,k) for(int i=j;i<=k;i++) #define FORD(i,j,k) for(int i=j;i>=k;i--) #define LL long long int main() { LL n; LL s=0; cin>>n; if(n>0) { while(n>0) { s*=10; s+=n%10; n/=10; } cout<<s; } else if(n==0) cout<<0; else { cout<<'-'; n=-n; while(n>0) { s*=10; s+=n%10; n/=10; } cout<<s; } return 0; }
30 http://noi.openjudge.cn/ch0105/30/
含k个3的数
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<iostream> #include<algorithm> #include<set> #include<cstdlib> #include<cstdio> #include<cmath> using namespace std; #define FOR(i,j,k) for(int i=j;i<=k;i++) #define FORD(i,j,k) for(int i=j;i>=k;i--) #define LL long long int main() { int n,k,s,t; cin>>n>>k; t=n; s=0; while(n>0) { if(n%10==3) s++; n/=10; } if(s==k&&t%19==0) cout<<"YES"; else cout<<"NO"; return 0; }
31 http://noi.openjudge.cn/ch0105/31/
开关灯
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<iostream> #include<algorithm> #include<set> #include<cstdlib> #include<cstdio> #include<cmath> using namespace std; #define FOR(i,j,k) for(int i=j;i<=k;i++) #define FORD(i,j,k) for(int i=j;i>=k;i--) #define LL long long int a[5010]; int main() { int n,m; cin>>n>>m; FOR(i,1,n) a[i]=1; FOR(i,1,n) FOR(j,1,m) if(i%j==0) a[i]*=-1; int ans=0; int tt; FOR(i,1,n) if(a[i]==-1) {cout<<i; tt=i; break;} FOR(i,tt+1,n) if(a[i]==-1) cout<<','<<i; return 0; }
32 http://noi.openjudge.cn/ch0105/32/
求分数序列和
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<iostream> #include<algorithm> #include<set> #include<cstdlib> #include<cstdio> #include<cmath> using namespace std; #define FOR(i,j,k) for(int i=j;i<=k;i++) #define FORD(i,j,k) for(int i=j;i>=k;i--) #define LL long long int a[5010]; int main() { double n,a,b,c; a=1; b=2; cin>>n; double ans=b/a; FOR(i,2,n) { c=a+b; a=b; b=c; ans+=b/a; } printf("%.4f",ans); return 0; }
33 http://noi.openjudge.cn/ch0105/33/
计算分数加减表达式的值
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<iostream> #include<algorithm> #include<set> #include<cstdlib> #include<cstdio> #include<cmath> using namespace std; #define FOR(i,j,k) for(int i=j;i<=k;i++) #define FORD(i,j,k) for(int i=j;i>=k;i--) #define FORrare(i,j,k) for(double i=j;i<=k;i++) #define LL long long int a[5010]; int main() { int n; cin>>n; int s=1; double ans=0; FORrare(i,1,n) { ans+=s*(1/i); s*=-1; } printf("%.4f",ans); return 0; }
34 http://noi.openjudge.cn/ch0105/34/
求阶乘的和
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<iostream> #include<algorithm> #include<set> #include<cstdlib> #include<cstdio> #include<cmath> using namespace std; #define FOR(i,j,k) for(int i=j;i<=k;i++) #define FORD(i,j,k) for(int i=j;i>=k;i--) #define LL long long int a[5010]; int main() { int n; cin>>n; int ans=1; int sum=1; FOR(i,2,n) { ans*=i; sum+=ans; } cout<<sum; return 0; }
35 http://noi.openjudge.cn/ch0105/35/
求出e的值
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<iostream> #include<algorithm> #include<set> #include<cstdlib> #include<cstdio> #include<cmath> using namespace std; #define FOR(i,j,k) for(int i=j;i<=k;i++) #define FORD(i,j,k) for(int i=j;i>=k;i--) #define LL long long int a[5010]; int main() { int n; cin>>n; double ans=1; double sum=1; FOR(i,1,n) { ans*=i; sum+=1/ans; } printf("%.10f", sum); return 0; }
36 http://noi.openjudge.cn/ch0105/36/
计算多项式的值
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<iostream> #include<algorithm> #include<set> #include<cstdlib> #include<cstdio> #include<cmath> using namespace std; #define FOR(i,j,k) for(int i=j;i<=k;i++) #define FORD(i,j,k) for(int i=j;i>=k;i--) #define LL long long int a[5010]; int main() { double x; int n; double ans,s; cin>>x>>n; s=1; ans=1; FOR(i,1,n) { s*=x; ans+=s; } printf("%.2f",ans); return 0; }
37 http://noi.openjudge.cn/ch0105/37/
雇佣兵 文字题
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<iostream> #include<algorithm> #include<set> #include<cstdlib> #include<cstdio> #include<cmath> using namespace std; #define FOR(i,j,k) for(int i=j;i<=k;i++) #define FORD(i,j,k) for(int i=j;i>=k;i--) #define LL long long int a[5010]; int main() { int n,m,x; cin>>m>>n>>x; while(x*n>=m) { x-=(m+0.5)/n; n+=m/n; } cout<<n; return 0; }
38 http://noi.openjudge.cn/ch0105/38/
计算多项式的导函数
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<iostream> #include<algorithm> #include<set> #include<cstdlib> #include<cstdio> #include<cmath> using namespace std; #define FOR(i,j,k) for(int i=j;i<=k;i++) #define FORD(i,j,k) for(int i=j;i>=k;i--) #define LL long long int a[5010]; int main() { int n,x; cin>>n; if (n==0) cout<<0; else{ FORD(i,n,1) { cin>>x; cout<<x*i; if(i!=1) cout<<' '; } } return 0; }
39 http://noi.openjudge.cn/ch0105/39/
与7无关的数
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<iostream> #include<algorithm> #include<set> #include<cstdlib> #include<cstdio> #include<cmath> using namespace std; #define FOR(i,j,k) for(int i=j;i<=k;i++) #define FORD(i,j,k) for(int i=j;i>=k;i--) #define LL long long int a[5010]; int main() { int n; cin>>n; int ans=0; FOR(i,1,n) { bool flag=true; if(i%7==0) flag=false; int t=i; while(t>0) { if(t%10==7) flag=false; t/=10; } if(flag) ans+=i*i; } cout<<ans; return 0; }
40 http://noi.openjudge.cn/ch0105/40/
数1的个数
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<iostream> #include<algorithm> #include<set> #include<cstdlib> #include<cstdio> #include<cmath> using namespace std; #define FOR(i,j,k) for(int i=j;i<=k;i++) #define FORD(i,j,k) for(int i=j;i>=k;i--) #define LL long long int a[5010]; int main() { int n; cin>>n; int ans=0; FOR(i,1,n) { int t=i; while(t>0) { if(t%10==1) ans++; t/=10; } } cout<<ans; return 0; }
41 http://noi.openjudge.cn/ch0105/41/
数字统计
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<iostream> #include<algorithm> #include<set> #include<cstdlib> #include<cstdio> #include<cmath> using namespace std; #define FOR(i,j,k) for(int i=j;i<=k;i++) #define FORD(i,j,k) for(int i=j;i>=k;i--) #define LL long long int a[5010]; int main() { int m,n; cin>>m>>n; int ans=0; FOR(i,m,n) { int t=i; while(t>0) { if(t%10==2) ans++; t/=10; } } cout<<ans; return 0; }
42 http://noi.openjudge.cn/ch0105/42/
画矩形
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<iostream> #include<algorithm> #include<set> #include<cstdlib> #include<cstdio> #include<cmath> using namespace std; #define FOR(i,j,k) for(int i=j;i<=k;i++) #define FORD(i,j,k) for(int i=j;i>=k;i--) #define LL long long int a[5010]; int main() { int m,n,x; char xx; cin>>m>>n>>xx>>x; if(x) FOR(i,1,m) { FOR(j,1,n) cout<<xx; cout<<endl; } else { FOR(j,1,n) cout<<xx; cout<<endl; FOR(i,2,m-1) { cout<<xx; FOR(j,2,n-1) cout<<' '; cout<<xx<<endl; } FOR(j,1,n) cout<<xx; cout<<endl; } return 0; }
43 http://noi.openjudge.cn/ch0105/43/
质因数分解 sb题
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<iostream> #include<algorithm> #include<set> #include<cstdlib> #include<cstdio> #include<cmath> using namespace std; #define FOR(i,j,k) for(int i=j;i<=k;i++) #define FORD(i,j,k) for(int i=j;i>=k;i--) #define LL long long int main() { int n; cin>>n; FOR(i,2,sqrt(n)) if(n%i==0) {cout<<n/i;break;} return 0; }
为什么43题我反着找就TLE了?卡我
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<iostream> #include<algorithm> #include<set> #include<cstdlib> #include<cstdio> #include<cmath> using namespace std; #define FOR(i,j,k) for(int i=j;i<=k;i++) #define FORD(i,j,k) for(int i=j;i>=k;i--) #define LL long long int main() { int n; cin>>n; FORD(i,n/2,3) { if(n%i==0) {cout<<i;break;} } return 0; }
44 http://noi.openjudge.cn/ch0105/44/
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<iostream> #include<algorithm> #include<set> #include<cstdlib> #include<cstdio> #include<cmath> using namespace std; #define FOR(i,j,k) for(int i=j;i<=k;i++) #define FORD(i,j,k) for(int i=j;i>=k;i--) #define LL long long bool p(int x) { for(int i=2;i*i<=x;i++) if (x%i==0) return false; return true; } int main() { int n; cin>>n; int k=0; int j=1; while(k<n) { j++; if(p(j)) k++; } cout<<j; return 0; }
第n小的质数
45 http://noi.openjudge.cn/ch0105/45/
金币
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<iostream> #include<algorithm> #include<set> #include<cstdlib> #include<cstdio> #include<cmath> using namespace std; #define FOR(i,j,k) for(int i=j;i<=k;i++) #define FORD(i,j,k) for(int i=j;i>=k;i--) #define LL long long int main() { int k,n,s,ans; cin>>n; s=1; ans=0; k=0; FOR(i,1,n) { ans+=s; k++; if(k==s){s++;k=0;} } cout<<ans; return 0; }