【1】ZOJ Problem Set - 1045
【【简单题】】
【题目】
HangOver
Time Limit: 1 Second Memory Limit:32768 KB
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.
The input consists of one or more test cases, followed by a line containing the number 0.00 that signals the end of the input. Each test case is a single line containing a positive floating-point number c whose value is at least 0.01 and at most 5.20; c will contain exactly three digits.
For each test case, output the minimum number of cards necessary to achieve an overhang of at least c card lengths. Use the exact output format shown in the examples.
Example input:
1.00
3.71
0.04
5.19
0.00
Example output:
3 card(s)
61 card(s)
1 card(s)
273 card(s)
Source: Mid-Central USA 2001
【题意说明】
给n张长度都为1的牌,第1张叠在第2张上悬出1/2的长度,第2张叠在第3张上悬出1/3的长度,以此类推,第n-1张叠在第n张上悬出1/n的长度,第n张叠在桌子上悬出1/(n+1)的长度,则n张牌悬出桌子共1/2+1/3+......+1/(n+1)的长度。题目给出一个长度,问多少张牌的悬挂长度最接近给定的长度。
【解答】
代码:
#include<iostream>
using namespace std;
int main()
{
double in_sum,sum;int i,count;
while(cin>>in_sum)
{
if(in_sum==0.0) break;
sum=0.0;
for(i=2;sum<in_sum;i++)
sum+=1.0/i;
count=i-2;
cout<<count<<" card(s)"<<endl;
}
return 0;
}
//Accepted
【2】ZOJ Problem Set - 1048
【【简单题】】
【题目】
Financial Management
Time Limit: 1 Second Memory Limit:32768 KB
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.
Input Format:
The input will be twelve lines. Each line will contain the closing balance of his bank account for a particular month. Each number will be positive and displayed to the penny. No dollar sign will be included.
Output Format:
The output will be a single number, the average (mean) of the closing balances for the twelve months. It will be rounded to the nearest penny, preceded immediately by a dollar sign, and followed by the end-of-line. There will be no other spaces or characters in the output.
Sample Input:
100.00
489.12
12454.12
1234.10
823.05
109.20
5.27
1542.25
839.18
83.99
1295.01
1.75
Sample Output:
$1581.42
Source: Mid-Atlantic USA 2001
【题意说明】
输入每个月的金额,计算1年的平均金额。主要考察保留小数点的输出。
【解答】
代码:
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
double a,sum,avg;
int i;
while(cin>>a)
{
sum=a;
for(i=1;i<=11;i++)
{
cin>>a;
sum+=a;
}
avg=sum/12;
cout<<'$'<<setiosflags(ios::fixed)<<setprecision(2)<<avg<<endl;
}
return 0;
}
//Accepted
(解于2009/10)