poj1003 Hangover && poj1004 Financial Management
来源:互联网 发布:移动互联网软件开发 编辑:程序博客网 时间:2024/06/05 03:57
这两题比较水,就合在一起了。
1003:
How far can you make a stack of cards overhang a table? If you have one card, you can create a maximum overhang of half a card length. (We're assuming that the cards must be perpendicular to the table.) With two cards you can make the top card overhang the bottom one by half a card length, and the bottom one overhang the table by a third of a card length, for a total maximum overhang of 1/2+ 1/3= 5/6 card lengths. In general you can make n cards overhang by 1/2+ 1/3+ 1/4 + ... + 1/(n + 1) card lengths, where the top card overhangs the second by 1/2, the second overhangs tha third by 1/3, the third overhangs the fourth by 1/4, etc., and the bottom card overhangs the table by 1/(n + 1). This is illustrated in the figure below.
1.003.710.045.190.00
3 card(s)61 card(s)1 card(s)273 card(s)
题意:给出m,求1/2+1/3+1/4+..+1/(n+1)>=m的最小n。
思路:数据小,模拟。
#include<cstdio>#include<algorithm>#include<cmath>#include<cstring>#include<iostream>#include<queue>#include<map>#include<string>#define ll long longusing namespace std;double n;int main(){ while (scanf("%lf",&n),n){ double m=0,k=2; int ans=0; while (m<n){ m+=1/k; k++; ans++; } printf("%d card(s)\n",ans); } return 0;}
1004:
Larry graduated this year and finally has a job. He's making a lot of money, but somehow never seems to have enough. Larry has decided that he needs to grab hold of his financial portfolio and solve his financing problems. The first step is to figure out what's been going on with his money. Larry has his bank account statements and wants to see how much money he has. Help Larry by writing a program to take his closing balance from each of the past twelve months and calculate his average account balance.
100.00489.1212454.121234.10823.05109.205.271542.25839.1883.991295.011.75
$1581.42
题意:给出12个数,求它们的平均值。
C++里double的scanf读入scanf("%lf",..)
然后很坑,交G++WA了n遍,C++就能过了。
#include<cstdio>#include<algorithm>#include<cmath>#include<cstring>#include<iostream>#include<queue>#include<map>#include<string>#define ll long longusing namespace std;int main(){ double sum,n; sum=(double)0; for (int i=0;i<12;i++){ scanf("%lf",&n); sum+=n; } printf("$%.2lf\n",sum/(double)12); return 0;}
- poj1003 Hangover && poj1004 Financial Management
- POJ1004·Financial Management
- POJ1004 Financial Management
- POJ1004 Financial Management
- POJ1004:Financial Management
- poj1004---Financial Management
- POJ1004 Financial Management
- POJ1004---Financial Management
- POJ1004 Financial Management
- [Poj1004]Financial Management
- POJ1004 Financial Management
- poj1004 Financial Management
- POJ1004 && Financial Management
- poj1004 Financial Management
- POJ1004 Financial Management
- POJ1004-Financial Management
- poj1004"Financial Management"解题报告
- poj1004——Financial Management
- 解决本地运行RMMV的HTML5游戏时出现Failed to load: data/actos.json 问题
- Java中1000==1000为false而100==100为true
- gazebo简明教程
- android游戏开发实例-可局域网对战的飞行棋(一)
- hdu1010(Tempter of the Bone)深搜+剪枝
- poj1003 Hangover && poj1004 Financial Management
- Oracle中查看所有表和字段
- 前事不忘,后事之师——第三次自考总结
- 关于安卓开发中Activity动画切换效果无效的一个总结
- (c语言)比较两个字符串的长度
- 用Javascript实现checkbox全选、全不选
- invalid bound statement (not found)
- MSSQL_2017年4月最新全国手机号段手机归属地数据库360000条记录
- C++ sizeof的使用总结