poj1552 Doubles
题目链接: http://poj.org/problem?id=1552
#include<cstdio> #include<iostream> #include<cmath> using namespace std; int main(){ int a[100],i=0,ans=0;; while(1){ int x; cin>>x; if(x==-1) break; else if(x==0){ for(int j=0;j<i;j++) for(int k=j+1;k<i;k++) if(a[k]==2*a[j]||a[j]==2*a[k]) ans++; cout<<ans<<endl; i=0; ans=0; } else a[i++]=x; } }
题目链接:http://poj.org/problem?id=1004
题意:Larry毕业之后挣钱了想知道他的财务状况,他现在有他的存款清单,想知道他12个月的结余有多少
思路:依次读入12个月的金额,输出平均值就好,记得要加一个$
#include<cstdio> #include<iostream> #include<algorithm> using namespace std; int main(){ float a[15],sum=0; for(int i=0;i<12;i++){ cin>>a[i]; sum+=a[i]; } sum/=12; printf("$%.2f\n",sum); }
题目链接:http://poj.org/problem?id=2521
题意:商人做生意有亏有赚,如果有个给了假币,商人会亏损:货物价格+找钱价格,
注意:N<M,P也有可能小于M,因为买东西的不全是假币,如果赚了,就输出负数。
#include<cstdio> #include<iostream> using namespace std; int main(){ int n,m,p,c; while((cin>>n>>m>>p>>c)&&(m||n||p||c)) cout<<p-m+n<<endl; }
poj 2209 The King
题目链接: http://poj.org/problem?id=2209
题意:有个聪明的国王,他有个缺点,就是数不到3。现在敌军压境,他想要把自己的儿子派出去。他知道他的有些儿子像他一样聪明,有些却愚昧无知。而且他清楚的知道,他儿子们的脑力潜能,从-3到3之间的一个值(因为他只能数到3),他也知道他们取胜的机会和儿子们脑力潜能的幂之和和成比例。现在想要知道最后的战力之和。
#include<cstdio> #include<iostream> #include<cmath> using namespace std; int main(){ int n,m,sum=0; cin>>n>>m; for(int i=1;i<=n;i++){ int x; cin>>x; if(x<0&&m%2==1) ; else sum+=pow(x,m); } cout<<sum<<endl; }
poj3086 Triangular Sums
题目链接: http://poj.org/problem?id=3086
题意:三角数$T(n)=1+2+...+n$.这个三角形的权重是$W(n) = SUM[k = 1…n; k * T(k + 1)]$
输入n,求W(n),直接暴力即可
#include<cstdio> #include<iostream> using namespace std; int main(){ int a[1005]={0},b[1005]={0}; for(int i=1;i<=1004;i++) a[i]=a[i-1]+i; for(int i=1;i<=1003;i++) b[i]=b[i-1]+i*a[i+1]; int n; cin>>n; for(int i=1;i<=n;i++){ int m; cin>>m; cout<<i<<" "<<m<<" "<<b[m]<<endl; } }
poj2656 Unhappy Jinjin
题目链接: http://poj.org/problem?id=2656
#include <stdio.h> int main(){ while(1) { int i, n; int maxday, maxvalue = -1; scanf("%d", &n); if (n == 0) break; for (i = 1; i <= n; i++) { int a, b; scanf("%d%d", &a, &b); if (a + b > maxvalue) { maxvalue = a + b; maxday = i; } } if (maxvalue <= 8) printf("0\n"); else printf("%d\n", maxday); } return 0; }
poj2840 Big Clock
题目链接: http://poj.org/problem?id=2840
题意:大钟坏了,大家修好了,但是还是报时有问题,1点的时候敲13下,2点的时候敲14下,12点的时候敲24下,13点的时候敲1下,想知道现在该敲几下
#include<cstdio> #include<iostream> #include<cmath> using namespace std; int main(){ int n; cin>>n; while(n--){ int x,y; cin>>x; getchar(); cin>>y; if(y!=0){ cout<<0<<endl; continue; } if(x>=0&&x<=12) cout<<x+12<<endl; else cout<<x-12<<endl; } }
题目链接: http://poj.org/problem?id=3673
题意:定义了一个新的乘法方式: $12345 =14 + 15 + 24 + 25 + 34 + 3*5 = 54$
思路:循环求出每一位数即可
#include<cstdio> #include<iostream> #include<cstring> using namespace std; int main(){ int a,b,i=0,j=0,ans=0; int x[15],y[15]; cin>>a>>b; while(a>0){ x[i++]=a%10; a=a/10; } while(b>0){ y[j++]=b%10; b=b/10; } for(int k=0;k<i;k++) for(int l=0;l<j;l++) ans+=x[k]*y[l]; cout<<ans<<endl; }
题目链接: http://poj.org/problem?id=2871
题意:输入一系列温度,输出2个温度之间的差别
#include<cstdio> #include<iostream> using namespace std; int main(){ float a[1000]; int i=0; while(scanf("%f",&a[i])&&a[i]<900){ scanf("%f",&a[++i]); i++; } for(int j=1;j<i;j++) printf("%.2f\n",a[j]-a[j-1]); printf("End of Output\n"); }
题目链接: http://poj.org/problem?id=1005
题意:Fred Mapper有个半岛,每天以50 平方公里的速度被侵蚀,他想知道他的地多长时间会被侵蚀。直接用面积除下就好
#include<cstdio> #include<iostream> #define pi 3.1415926 using namespace std; int main(){ int n; cin>>n; for(int i=1;i<=n;i++){ double a,b; cin>>a>>b; b=a*a+b*b; b=b*pi/2; b=b/50.0; cout<<"Property "<<i<<": This property will begin eroding in year "<<int(b)+1<<"."<<endl; } cout<<"END OF OUTPUT."<<endl; }
poj 3916 Duplicate Removal
题目链接:http://poj.org/problem?id=3916
题意:一串数字,把中间连续相同的重复项去掉,只保留一个副本
思路:对比上一个数字,如果一样的话就不输出即可
#include<cstdio> #include<iostream> using namespace std; int main(){ int n,a[1000],b[1000]; while((cin>>n)&&n!=0){ a[0]=0; int k=0; for(int i=1;i<=n;i++){ cin>>a[i]; if(a[i]==a[i-1]) ; else b[k++]=a[i]; } for(int i=0;i<k;i++) cout<<b[i]<<" "; cout<<"$"<<endl; } }
poj2390 Bank Interest
题目链接: http://poj.org/problem?id=2390
题意:输入年利率、金额、年份,输出复利之后能拿到的金额数
#include<cstdio> #include<algorithm> #include<iostream> using namespace std; int main(){ int a,b,c; cin>>a>>b>>c; double s=b*1.0; for(int i=1;i<=c;i++) s=s*(1+0.01*a); cout<<(int)s<<endl; } <cstdio> #include<algorithm> #include<iostream> using namespace std; int main(){ int a,b,c; cin>>a>>b>>c; double s=b*1.0; for(int i=1;i<=c;i++) s=s*(1+0.01*a); cout<<(int)s<<endl; }
poj2509 Peter's smokes
题目链接: http://poj.org/problem?id=2509
题意:peter共有n根烟,还可以凭k根烟头换个新的烟,他最多可以抽多少根烟
#include<cstdio> #include<iostream> using namespace std; int main(){ int n,k; while((scanf("%d%d",&n,&k)!=EOF)){ int s=n; while(n>=k){ s+=n/k; n=n%k+n/k; } cout<<s<<endl; } }
poj1528 Perfection
题目链接: http://poj.org/problem?id=1528
题意:数字的因子之和等于该数字本身的,就是perfect numbers,比如$28=1+2+4+7+14$,$9>1+3 $就是deficient,$12<1+2+3+4+6$,就是abundant,判断数n是哪类数
直接暴力判断因子,注意输出,尤其是右对齐,用5d%
#include<cstdio> #include<iostream> using namespace std; int main(){ int n; bool f=true; while((cin>>n)&&n!=0){ if(f) { cout<<"PERFECTION OUTPUT"<<endl; f=0; } int sum=n; for(int i=1;i<n;i++){ if(n%i==0) sum=sum-i; } if(sum==0) printf("%5d PERFECT\n",n); else if(sum>0) printf("%5d DEFICIENT\n",n); else printf("%5d ABUNDANT\n",n); } cout<<"END OF OUTPUT"<<endl; }
poj3980取模运算
题目链接: http://poj.org/problem?id=3980
易知:a%b=a-a/b*b;
#include<cstdio> #include<iostream> #include<algorithm> using namespace std; int main(){ int a,b; while((scanf("%d%d",&a,&b)!=EOF)){ printf("%d\n",a-a/b*b); } }
poj 2388Who's in the Middle
题目链接: http://poj.org/problem?id=2388
题意:给n个数,求中位数
思路:排序,输出排序后中间的就好,注意排序的始末位置
#include<cstdio> #include<iostream> #include<algorithm> using namespace std; int main(){ int a[10005]; int n; cin>>n; for(int i=0;i<n;i++) cin>>a[i]; sort(a,a+n); cout<<a[n/2]<<endl; }