A - Spreadsheets
CodeForces - 1B
In the popular spreadsheets systems (for example, in Excel) the following numeration of columns is used. The first column has number A, the second — number B, etc. till column 26 that is marked by Z. Then there are two-letter numbers: column 27 has number AA, 28 — AB, column 52 is marked by AZ. After ZZ there follow three-letter numbers, etc.
The rows are marked by integer numbers starting with 1. The cell name is the concatenation of the column and the row numbers. For example, BC23 is the name for the cell that is in column 55, row 23.
Sometimes another numeration system is used: RXCY, where X and Y are integer numbers, showing the column and the row numbers respectfully. For instance, R23C55 is the cell from the previous example.
Your task is to write a program that reads the given sequence of cell coordinates and produce each item written according to the rules of another numeration system.
Input
The first line of the input contains integer number n (1 ≤ n ≤ 105), the number of coordinates in the test. Then there follow n lines, each of them contains coordinates. All the coordinates are correct, there are no cells with the column and/or the row numbers larger than 106 .
Output
Write n lines, each line should contain a cell coordinates in the other numeration system.
Example
2
R23C55
BC23
BC23
R23C55
#include#include"cstdio" #include #include"string.h" #include"algorithm" #include using namespace std; const int max_n=1e3+50; char exc[max_n],t[max_n]; int main() { int n; scanf("%d",&n); while(n--) { int i,a=0,b=0; scanf("%s",exc); if(sscanf(exc,"R%dC%d",&a,&b)==2) { for(i=0;b>0;i++) { t[i]=(b-1)%26+'A'; b=(b-1)/26; } i--; for(;i>=0;i--) printf("%c",t[i]); printf("%d\n",a); } else { sscanf(exc,"%[A-Z]%d",t,&a); for(i=0;t[i]!=0;i++) { b*=26;b+=t[i]-'A'+1; } printf("R%dC%d\n",a,b); } } }
B - Ancient Berland Circus
CodeForces - 1C
Nowadays all circuses in Berland have a round arena with diameter 13 meters, but in the past things were different.
In Ancient Berland arenas in circuses were shaped as a regular (equiangular) polygon, the size and the number of angles could vary from one circus to another. In each corner of the arena there was a special pillar, and the rope strung between the pillars marked the arena edges.
Recently the scientists from Berland have discovered the remains of the ancient circus arena. They found only three pillars, the others were destroyed by the time.
You are given the coordinates of these three pillars. Find out what is the smallest area that the arena could have.
Input
The input file consists of three lines, each of them contains a pair of numbers –– coordinates of the pillar. Any coordinate doesn't exceed 1000 by absolute value, and is given with at most six digits after decimal point.
Output
Output the smallest possible area of the ancient arena. This number should be accurate to at least 6 digits after the decimal point. It's guaranteed that the number of angles in the optimal polygon is not larger than 100.
Example
0.000000 0.000000
1.000000 1.000000
0.000000 1.000000
1.00000000
C - Triangle
CodeForces - 6A
Johnny has a younger sister Anne, who is very clever and smart. As she came home from the kindergarten, she told his brother about the task that her kindergartener asked her to solve. The task was just to construct a triangle out of four sticks of different colours. Naturally, one of the sticks is extra. It is not allowed to break the sticks or use their partial length. Anne has perfectly solved this task, now she is asking Johnny to do the same.
The boy answered that he would cope with it without any difficulty. However, after a while he found out that different tricky things can occur. It can happen that it is impossible to construct a triangle of a positive area, but it is possible to construct a degenerate triangle. It can be so, that it is impossible to construct a degenerate triangle even. As Johnny is very lazy, he does not want to consider such a big amount of cases, he asks you to help him.
Input
The first line of the input contains four space-separated positive integer numbers not exceeding 100 — lengthes of the sticks.
Output
Output TRIANGLE if it is possible to construct a non-degenerate triangle. Output SEGMENT if the first case cannot take place and it is possible to construct a degenerate triangle. Output IMPOSSIBLE if it is impossible to construct any triangle. Remember that you are to use three sticks. It is not allowed to break the sticks or use their partial length.
Example
4 2 1 3
TRIANGLE
7 2 2 4
SEGMENT
3 5 9 1
IMPOSSIBLE
#include"stdio.h" #include"cstdio" #include"algorithm" using namespace std; const int max_n=5; int len[max_n]; int main() { while(scanf("%d%d%d%d",&len[1],&len[2],&len[3],&len[4])!=EOF) { int i,p=-1; sort(len+1,len+5); for(i=4;i>=3;i--) { if(len[i]==len[i-1]+len[i-2]||len[4]==len[1]+len[3]) p=0; if(len[i]1]+len[i-2]) { p=1;break; } } if(p==0) printf("SEGMENT\n"); if(p==1) printf("TRIANGLE\n"); if(p==-1) printf("IMPOSSIBLE\n"); } }
D - 折线分割平面
HDU - 2050
我们看到过很多直线分割平面的题目,今天的这个题目稍微有些变化,我们要求的是n条折线分割平面的最大数目。比如,一条折线可以将平面分成两部分,两条折线最多可以将平面分成7部分,具体如下所示。
Input输入数据的第一行是一个整数C,表示测试实例的个数,然后是C 行数据,每行包含一个整数n(0
Output对于每个测试实例,请输出平面的最大分割数,每个实例的输出占一行。
Sample Input
2 1 2
Sample Output
2 7
#include"stdio.h" #include"cstdio" #include"algorithm" using namespace std; const int max_n=1e4+10; int dp[max_n]; int main() { int n,i,j; dp[1]=2;dp[2]=7; for(i=1;i<=max_n;i++) { dp[i+1]=dp[i]+4*(i)+1; } while(scanf("%d",&n)!=EOF) { int m; while(n--) { scanf("%d",&m); printf("%d\n",dp[m]); } } }
E - Coins
HDU - 2844
Whuacmers use coins.They have coins of value A1,A2,A3...An Silverland dollar. One day Hibix opened purse and found there were some coins. He decided to buy a very nice watch in a nearby shop. He wanted to pay the exact price(without change) and he known the price would not more than m.But he didn't know the exact price of the watch.
You are to write a program which reads n,m,A1,A2,A3...An and C1,C2,C3...Cn corresponding to the number of Tony's coins of value A1,A2,A3...An then calculate how many prices(form 1 to m) Tony can pay use these coins.InputThe input contains several test cases. The first line of each test case contains two integers n(1 ≤ n ≤ 100),m(m ≤ 100000).The second line contains 2n integers, denoting A1,A2,A3...An,C1,C2,C3...Cn (1 ≤ Ai ≤ 100000,1 ≤ Ci ≤ 1000). The last test case is followed by two zeros.OutputFor each test case output the answer on a single line.Sample Input
3 10 1 2 4 2 1 1 2 5 1 4 2 1 0 0
Sample Output
8 4
F - Buy Tickets
POJ - 2828
Railway tickets were difficult to buy around the Lunar New Year in China, so we must get up early and join a long queue…
The Lunar New Year was approaching, but unluckily the Little Cat still had schedules going here and there. Now, he had to travel by train to Mianyang, Sichuan Province for the winter camp selection of the national team of Olympiad in Informatics.
It was one o’clock a.m. and dark outside. Chill wind from the northwest did not scare off the people in the queue. The cold night gave the Little Cat a shiver. Why not find a problem to think about? That was none the less better than freezing to death!
People kept jumping the queue. Since it was too dark around, such moves would not be discovered even by the people adjacent to the queue-jumpers. “If every person in the queue is assigned an integral value and all the information about those who have jumped the queue and where they stand after queue-jumping is given, can I find out the final order of people in the queue?” Thought the Little Cat.
Input
There will be several test cases in the input. Each test case consists of N + 1 lines where N (1 ≤ N ≤ 200,000) is given in the first line of the test case. The next N lines contain the pairs of values Posi and Vali in the increasing order of i (1 ≤ i ≤ N). For each i, the ranges and meanings of Posi and Vali are as follows:
- Posi ∈ [0, i − 1] — The i-th person came to the queue and stood right behind the Posi-th person in the queue. The booking office was considered the 0th person and the person at the front of the queue was considered the first person in the queue.
- Vali ∈ [0, 32767] — The i-th person was assigned the value Vali.
There no blank lines between test cases. Proceed to the end of input.
Output
For each test cases, output a single line of space-separated integers which are the values of people in the order they stand in the queue.
Sample Input
4 0 77 1 51 1 33 2 69 4 0 20523 1 19243 1 3890 0 31492
Sample Output
77 33 69 51 31492 20523 3890 19243
Hint
The figure below shows how the Little Cat found out the final order of people in the queue described in the first test case of the sample input.
G - Chinese Mahjong
UVA - 11210
Mahjong ( ) is a game of Chinese origin usually played by four persons with tiles resembling dominoes and bearing various designs, which are drawn and discarded until one player wins with a hand of four combinations of three tiles each and a pair of matching tiles. A set of Mahjong tiles will usually differ from place to place. It usually has at least 136 tiles, most commonly 144, although sets originating from America or Japan will have more. The 136-tile Mahjong includes:
Dots: named as each tile consists of a number of circles. Each circle is said to represent copper (tong) coins with a square hole in the middle. In this problem, they’re represented by 1T, 2T, 3T, 4T, 5T, 6T, 7T, 8T and 9T.
Bams: named as each tile (except the 1 Bamboo) consists of a number of bamboo sticks. Each stick is said to represent a string (suo) that holds a hundred coins. In this problem, they’re represented by 1S, 2S, 3S, 4S, 5S, 6S, 7S, 8S and 9S.
Craks: named as each tile represents ten thousand (wan) coins, or one hundred strings of one hundred coins. In this problem, they’re represented by 1W, 2W, 3W, 4W, 5W, 6W, 7W, 8W and 9W.
Wind tiles: East, South, West, and North. In this problem, they’re represented by DONG, NAN, XI, BEI.
Dragon tiles: red, green, and white. The term dragon tile is a western convention introduced by Joseph Park Babcock in his 1920 book introducing Mahjong to America. Originally, these tiles are said to have something to do with the Chinese Imperial Examination. The red tile means you pass the examination and thus will be appointed a government official. The green tile means, consequently you will become financially well off. The white tile (a clean board) means since you are now doing well you should act like a good, incorrupt official. In this problem, they’re represented by ZHONG, FA, BAI.
There are 9∗3 + 4 + 3 = 34 kinds, with exactly 4 tiles of each kind, so there are 136 tiles in total. To who may be interested, the 144-tile Mahjong also includes:
Flower tiles: typically optional components to a set of mahjong tiles, often contain artwork on their tiles. There are exactly one tile of each kind, so 136+8=144 tiles in total. In this problem, we don¡t consider these tiles.
Chinese Mahjong is very complicated. However, we only need to know very few of the rules in order to solve this problem. A meld is a certain set of tiles in one’s hand. There are three kinds of melds you need to know (to who knows Mahjong already, kong is not considered):
Pong: A set of three identical titles. Example: , .
Chow: A set of three suited tiles in sequence. All three tiles must be of the same suites. Sequences of higher length are not permissible (unless it forms more than one meld). Obviously, wind tiles and
dragon tiles can never be involved in chows. Example: , .
Eye: The pair, while not a meld, is the final component to the standard hand. It consists of any two identical tiles. A player wins the round by creating a standard mahjong hand. That means, the hand consists of an eye and several (possible zero) pongs and chows. Note that each title can be involved in exactly one eye/pong/chow. When a hand is one tile short of wining, the hand is said to be a ready hand, or more figuratively, ’on the pot’. The player holding a ready hand is said to be waiting for certain tiles. For example
is waiting for , and . To who knows more about Mahjong: don’t consider special winning hands such as ‘ ’.
Input
The input consists of at most 50 test cases. Each case consists of 13 tiles in a single line. The hand is legal (e.g. no invalid tiles, exactly 13 tiles). The last case is followed by a single zero, which should not be processed.
Output
For each test case, print the case number and a list of waiting tiles sorted in the order appeared in the problem description (1T˜9T, 1S˜9S, 1W˜9W, DONG, NAN, XI, BEI, ZHONG, FA, BAI). Each waiting tile should be appeared exactly once. If the hand is not ready, print a message ‘Not ready’ without quotes.
Sample Input
1S 1S 2S 2S 2S 3S 3S 3S 7S 8S 9S FA FA 1S 2S 3S 4S 5S 6S 7S 8S 9S 1T 3T 5T 7T 0
Sample Output
Case 1: 1S 4S FA Case 2: Not ready