# POJ 1006-Biorhythms

POJ 1006-Biorhythms
Biorhythms
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 114815 Accepted: 35991
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
East Central North America 1999

If a triple peak occurs on the given date, you should give the number of days to the next occurrence of a triple peak.
and you may assume that a triple peak will occur within 21252 days of the given date.

```#include<iostream>
#include<string>
using namespace std;
int main()
{
int p,e,i,d;
int case_num=1;
while(cin>>p>>e>>i>>d&&p!=-1&&e!=-1&&i!=-1&&d!=-1)
{
for(int rs=d+1;rs<=21252+d;rs++)
{
if(((rs-p)%23==0)&&((rs-e)%28==0)&&((rs-i)%33==0))
{
cout<<"Case "<<case_num<<": the next triple peak occurs in "<<rs-d<<" days."<<endl;
break;
}
}
case_num++;
}
return 0;
}
```

# hihoCoder 1039-字符消除

hihoCoder 1039-字符消除
#1039 : 字符消除

1)如果s包含长度超过1的由相同字母组成的子串，那么这些子串会被同时消除，余下的子串拼成新的字符串。例如"ABCCBCCCAA"中"CC","CCC"和"AA"会被同时消除，余下"AB"和"B"拼成新的字符串"ABB"。
2)上述消除会反复一轮一轮进行，直到新的字符串不包含相邻的相同字符为止。例如”ABCCBCCCAA”经过一轮消除得到"ABB"，再经过一轮消除得到"A"

3
ABCBCCCAA
AAA
ABC

9
4
2

1)如果s包含长度超过1的由相同字母组成的子串，那么这些子串会被同时消除，余下的子串拼成新的字符串。
2)上述消除会反复一轮一轮进行，直到新的字符串不包含相邻的相同字符为止。

```#include <iostream>
#include<string>
using namespace std;
//递归求解一个字符串最多能消除多少个字符
int get_erase_num(string s,int rs)
{
int G={0};//用来记录整个字符串能够消除的字符的位置
int s_size=s.size();
bool is_done=true;//是否检查结束的标识
for(int i=0;i<s_size-1;i++)//注意上限s_size-1
{
if(s[i]==s[i+1])//然后判断是否有至少两个连续的字符出现
{
G[i]=1;
is_done=false;
rs++;
int j=i+1;
while(s[i]==s[j])
{
G[j]=1;
rs++;
j++;
if(j>=s_size)//检查是否超限
{
break;
}
}
i=j-1;
}
}
if(!is_done)//如果可以消除，则还没有结束
{
string ss="";
for(int i=0;i<s_size;i++)
{
if(G[i]==0)
ss+=s[i];//同时消除重复子串后的结果串
}
return get_erase_num(ss,rs);//递归
}
return rs;//结束返回
}
int main()
{
int n;
string s;
cin>>n;
while(n--)
{
cin>>s;
int s_size=s.size();
int max_m=-1;
//在所有可以插入的位置依次分别测试插入A,B,C的结果
for(int i=0;i<s_size+1;i++)
{
if(i==s_size)//如果要在字符串的末尾插入字符
{
int A_result=get_erase_num(s+"A",0);
if(A_result>max_m)
max_m=A_result;
int B_result=get_erase_num(s+"B",0);
if(B_result>max_m)
max_m=B_result;
int C_result=get_erase_num(s+"C",0);
if(C_result>max_m)
max_m=C_result;
}
else//插入位置除了末尾
{
int A_result=get_erase_num(s.substr(0,i)+"A"+s.substr(i),0);
if(A_result>max_m)
max_m=A_result;
int B_result=get_erase_num(s.substr(0,i)+"B"+s.substr(i),0);
if(B_result>max_m)
max_m=B_result;
int C_result=get_erase_num(s.substr(0,i)+"C"+s.substr(i),0);
if(C_result>max_m)
max_m=C_result;
}
}
cout<<max_m<<endl;
}
return 0;
}
```

# POJ 1005-I Think I Need a Houseboat

POJ 1005-I Think I Need a Houseboat
I Think I Need a Houseboat
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 87833 Accepted: 38137
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
Mid-Atlantic 2001

```#include<iostream>
#include<string>
#include<cmath>
using namespace std;
double R;//Fred is hoping to live in this house the rest of his life.余生最多设为100年
//初始化
void init()
{
for(int i=0;i<100;i++)
{
R[i]=sqrt(2*50*(i+1)/3.14);
}
}
//二分查找
int bin_search(double r)
{
int start=0,end=99,mid;
while(start<=end)
{
mid=(start+end)/2;
if(R[mid]>r)
end=mid-1;
else
start=mid+1;
}
//这个时候start==end
if(R[start]<r)
return start+1;
else
return start;
}
int main()
{
init();
int n;
double x,y;
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>x>>y;
double r=sqrt(x*x+y*y);
cout<<"Property "<<i<<": This property will begin eroding in year "<<bin_search(r)+1<<"."<<endl;
}
cout<<"END OF OUTPUT.";
return 0;
}
```

# POJ 1002-487-3279

POJ 1002-487-3279
487-3279
Time Limit: 2000MS Memory Limit: 65536K
Total Submissions: 245807 Accepted: 43582
Description
Businesses like to have memorable telephone numbers. One way to make a telephone number memorable is to have it spell a memorable word or phrase. For example, you can call the University of Waterloo by dialing the memorable TUT-GLOP. Sometimes only part of the number is used to spell a word. When you get back to your hotel tonight you can order a pizza from Gino’s by dialing 310-GINO. Another way to make a telephone number memorable is to group the digits in a memorable way. You could order your pizza from Pizza Hut by calling their ``three tens’’ number 3-10-10-10.
The standard form of a telephone number is seven decimal digits with a hyphen between the third and fourth digits (e.g. 888-1200). The keypad of a phone supplies the mapping of letters to numbers, as follows:
A, B, and C map to 2
D, E, and F map to 3
G, H, and I map to 4
J, K, and L map to 5
M, N, and O map to 6
P, R, and S map to 7
T, U, and V map to 8
W, X, and Y map to 9
There is no mapping for Q or Z. Hyphens are not dialed, and can be added and removed as necessary. The standard form of TUT-GLOP is 888-4567, the standard form of 310-GINO is 310-4466, and the standard form of 3-10-10-10 is 310-1010.
Two telephone numbers are equivalent if they have the same standard form. (They dial the same number.)
Your company is compiling a directory of telephone numbers from local businesses. As part of the quality control process you want to check that no two (or more) businesses in the directory have the same telephone number.
Input
The input will consist of one case. The first line of the input specifies the number of telephone numbers in the directory (up to 100,000) as a positive integer alone on the line. The remaining lines list the telephone numbers in the directory, with each number alone on a line. Each telephone number consists of a string composed of decimal digits, uppercase letters (excluding Q and Z) and hyphens. Exactly seven of the characters in the string will be digits or letters.
Output
Generate a line of output for each telephone number that appears more than once in any form. The line should give the telephone number in standard form, followed by a space, followed by the number of times the telephone number appears in the directory. Arrange the output lines by telephone number in ascending lexicographical order. If there are no duplicates in the input print the line:
No duplicates.
Sample Input
12
4873279
ITS-EASY
888-4567
3-10-10-10
888-GLOP
TUT-GLOP
967-11-11
310-GINO
F101010
888-1200
-4-8-7-3-2-7-9-
487-3279
Sample Output
310-1010 2
487-3279 4
888-4567 3
Source
East Central North America 1999

```#include<iostream>
#include<map>
#include<string>
using namespace std;
char hash_h={'2','2','2','3','3','3','4','4','4','5','5','5','6','6','6','7','0','7','7','8','8','8','9','9','9','0'};//题目给出的map对应关系，其中q和z对应0
//将输入转换成标准格式
string get_standard_form(string s)
{
string rs="";
int s_size=s.size();
for(int i=0;i<s_size;i++)
{
if(s[i]!='-')//将s中的连接符都去掉
rs+=s[i];
}
s_size=rs.size();
for(int i=0;i<s_size;i++)
{
if(rs[i]>='A'&&rs[i]<='Z')
rs[i]=hash_h[rs[i]-'A'];//替换
}
return rs.substr(0,3)+"-"+rs.substr(3);//添加连接符
}
int main()
{
int n;
string s;
cin>>n;
map<string,int> msi;
while(n--)
{
cin>>s;
msi[get_standard_form(s)]++;//使用map存储
}
map<string,int>::iterator it=msi.begin();//充分利用map的特性
int count=0;
while(it!=msi.end())//map已经自动按字典序排好了
{
if(it->second>1)
{
cout<<it->first<<" "<<it->second<<endl;
count++;
}
it++;
}
if(count==0)//记得判断是否有重复的！
cout<<"No duplicates. "<<endl;
return 0;
}
```

# POJ 1004-Financial Management

POJ 1004-Financial Management
Financial Management
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 138422 Accepted: 57882
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
Mid-Atlantic 2001

```#include<stdio.h>
int main()
{
double rs=0,d;
for(int i=0;i<12;i++)
{
scanf("%lf",&d);
rs+=d;
}
printf("\$%.2f",rs/12);
return 0;
}
```