2013-10-25-北大acmproj 1003 1004 1005 1006

proj1003:

Hangover
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 93180   Accepted: 45118

Description

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 ncards 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.


Input

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.

Output

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.

Sample Input

1.00
3.71
0.04
5.19
0.00

Sample Output

3 card(s)
61 card(s)
1 card(s)
273 card(s)

Source

 
通过测试:
#include<iostream>

using namespace std;

int overhang(double in){
	if(in < 0.5){
		return 1;
	}else{
		int m = 100000*in;
		int i = 1;
		while((m = (m - 100000/(++i))) > 0);
		return i - 1;
	}

}

int main()
{
	double in;
	while(cin>>in){
		if(in != 0.0)
			cout<<overhang(in)<<" card(s)"<<endl;
	}
	return 0;
}





proj1004:

Financial Management
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 111130   Accepted: 52480

Description

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

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

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

测试通过:
#include<iostream>

using namespace std;


double aver(double *in){
	double temp = 0.0;
	int i = 0;
	while(i < 12){
		temp += in[i];
		++i;
	}
	int aver = 100*temp/12;
	return (double)aver/100;
}
int main()
{
	double in[12];
	for(int i = 0; i < 12; ++i)cin>>in[i];
	cout<<"$"<<aver(in);
	return 0;
}




proj1005:
I Think I Need a Houseboat
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 80540   Accepted: 34745

Description

Fred Mapper is considering purchasing some land in Louisiana to build his house on. In the process of investigating the land, he learned that the state of Louisiana is actually shrinking by 50 square miles each year, due to erosion caused by the Mississippi River. Since Fred is hoping to live in this house the rest of his life, he needs to know if his land is going to be lost to erosion. 

After doing more research, Fred has learned that the land that is being lost forms a semicircle. This semicircle is part of a circle centered at (0,0), with the line that bisects the circle being the X axis. Locations below the X axis are in the water. The semicircle has an area of 0 at the beginning of year 1. (Semicircle illustrated in the Figure.) 

Input

The first line of input will be a positive integer indicating how many data sets will be included (N). Each of the next N lines will contain the X and Y Cartesian coordinates of the land Fred is considering. These will be floating point numbers measured in miles. The Y coordinate will be non-negative. (0,0) will not be given.

Output

For each data set, a single line of output should appear. This line should take the form of: “Property N: This property will begin eroding in year Z.” Where N is the data set (counting from 1), and Z is the first year (start from 1) this property will be within the semicircle AT THE END OF YEAR Z. Z must be an integer. After the last data set, this should print out “END OF OUTPUT.”

Sample Input

2
1.0 1.0
25.0 0.0

Sample Output

Property 1: This property will begin eroding in year 1.
Property 2: This property will begin eroding in year 20.
END OF OUTPUT.

Hint

1.No property will appear exactly on the semicircle boundary: it will either be inside or outside. 
2.This problem will be judged automatically. Your answer must match exactly, including the capitalization, punctuation, and white-space. This includes the periods at the ends of the lines. 
3.All locations are given in miles.

Source

测试通过:
#include<iostream>

using namespace std;
int erison_year(double num1, double num2){
	double year = 0.5*3.14159*(num1*num1 + num2*num2)/50;
	return (int)year;
}
int main()
{
	double x,y;
	int i = 1;
	int N;
	cin>>N;
	while(i <= N){
		cin>>x>>y;
		cout<<"Property "<<i<<": "<<"This property will begin eroding in year "<<erison_year(x,y) + 1<<"."<<endl;
		++i;
	}
	cout<<"END OF OUTPUT.";
	return 0;
}


proj1006:
Biorhythms
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 105571   Accepted: 32720

Description

Some people believe that there are three cycles in a person's life that start the day he or she is born. These three cycles are the physical, emotional, and intellectual cycles, and they have periods of lengths 23, 28, and 33 days, respectively. There is one peak in each period of a cycle. At the peak of a cycle, a person performs at his or her best in the corresponding field (physical, emotional or mental). For example, if it is the mental curve, thought processes will be sharper and concentration will be easier. 
Since the three cycles have different periods, the peaks of the three cycles generally occur at different times. We would like to determine when a triple peak occurs (the peaks of all three cycles occur in the same day) for any person. For each cycle, you will be given the number of days from the beginning of the current year at which one of its peaks (not necessarily the first) occurs. You will also be given a date expressed as the number of days from the beginning of the current year. You task is to determine the number of days from the given date to the next triple peak. The given date is not counted. For example, if the given date is 10 and the next triple peak occurs on day 12, the answer is 2, not 3. If a triple peak occurs on the given date, you should give the number of days to the next occurrence of a triple peak. 

Input

You will be given a number of cases. The input for each case consists of one line of four integers p, e, i, and d. The values p, e, and i are the number of days from the beginning of the current year at which the physical, emotional, and intellectual cycles peak, respectively. The value d is the given date and may be smaller than any of p, e, or i. All values are non-negative and at most 365, and you may assume that a triple peak will occur within 21252 days of the given date. The end of input is indicated by a line in which p = e = i = d = -1.

Output

For each test case, print the case number followed by a message indicating the number of days to the next triple peak, in the form: 

Case 1: the next triple peak occurs in 1234 days. 

Use the plural form ``days'' even if the answer is 1.

Sample Input

0 0 0 0
0 0 0 100
5 20 34 325
4 5 6 7
283 102 23 320
203 301 203 40
-1 -1 -1 -1

Sample Output

Case 1: the next triple peak occurs in 21252 days.
Case 2: the next triple peak occurs in 21152 days.
Case 3: the next triple peak occurs in 19575 days.
Case 4: the next triple peak occurs in 16994 days.
Case 5: the next triple peak occurs in 8910 days.
Case 6: the next triple peak occurs in 10789 days.

Source

 测试通过:

#include<iostream>

using namespace std;

int Biorhythms(int i,int j,int k,int start){
	float t = 1;
	while((((28*t + j - i)/23 - (int)((28*t + j - i)/23)) != 0)|| (((28*t + j - k)/33 - (int)((28*t + j - k)/33)) != 0)){
		++t;
	}
	int temp = j + 28*t - start;
	if(temp < 0)temp = temp + 21252;
	if(temp > 21252)temp = temp - 21252;
	return temp;
}
int main()
{

	int i,j,k,d;
	cin>>i>>j>>k>>d;
	int count = 1;
	while(!((i == -1)&& (j == -1)&& (k == -1)&& (d == -1))){
		cout<<"Case "<<count<<": the next triple peak occurs in "<<Biorhythms(i,j,k,d)<<" days."<<endl;
		cin>>i>>j>>k>>d;
		++count;
	}
	return 0;
}

posted on 2013-10-25 22:31  程序猿猿猿  阅读(269)  评论(0编辑  收藏  举报

导航