proj1003:
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
Output
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:
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 111130 | Accepted: 52480 |
Description
Input
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:
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 80540 | Accepted: 34745 |
Description
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
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
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
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; }