某校寒假作业题解

来源:互联网 发布:组态软件是什么 编辑:程序博客网 时间:2024/06/08 16:27

寒假尾声组队做了点其他学校的寒假作业题,水题居多。

发下我做的一些题的题解,会把有价值的题目放在前面

先发个公共头文件

#include <iostream>#include <cstdio>#include <cstring>#include <string>#include <ctime>#include <cmath>#include <vector>#include <deque>#include <algorithm>#include <list>#include <map>#include <set>#include <queue>#include <stack>#define rep(i,n) for(int i=0;i<(n);i++)#define rep1(i,n) for(int i=1;i<=(n);i++)#define For(i,a,b) for (int i=(a);i<=(b);i++)#define clr(x) memset(x,0,sizeof(x))#define pn printf("\n")#define ll long long#define pr(x) cout<<#x<<"="<<x<<"$";

然后是题解

L - Delta-wave
Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u
Submit Status

Description

A triangle field is numbered with successive integers in the way shown on the picture below. 



The traveller needs to go from the cell with number M to the cell with number N. The traveller is able to enter the cell through cell edges only, he can not travel from cell to cell through vertices. The number of edges the traveller passes makes the length of the traveller's route. 

Write the program to determine the length of the shortest route connecting cells with numbers N and M. 
 

Input

Input contains two integer numbers M and N in the range from 1 to 1000000000 separated with space(s).
 

Output

Output should contain the length of the shortest route.
 

Sample Input

6 12
 

Sample Output

3

本题我的做法比较有趣:对于两个格子,计算出它在第几行、将图顺时针旋转120度后它在倒数第几行,将图逆时针旋转120度后它在倒数第几行,三个参数分别为p,q,r,容易发现按照规则移动一步,这三个参数恰有一个参数有变化,且变化1,于是计算出两个格子的参数后分别做差取绝对值即可。

ll p1, q1, r1, p2, q2, r2;int main(){    ll m, n;     while(scanf("%lld%lld", &m, &n) == 2){        ll x1 = ceil(sqrt(m));        ll x2 = ceil(sqrt(n));        ll Y1 = m - (x1-1)*(x1-1), Y2 = n - (x2-1)*(x2-1);        p1 = x1; q1 = (Y1+1)/2; r1 = (2*x1-Y1+1)/2;        p2 = x2; q2 = (Y2+1)/2; r2 = (2*x2-Y2+1)/2;        //printf("%lld %lld %lld\n%lld %lld %lld\n", p1, q1, r1, p2, q2, r2);        printf("%lld\n", abs(p1-p2)+abs(q1-q2)+abs(r1-r2));    }    return 0;}


S - Counterfeit Dollar
Time Limit:1000MS     Memory Limit:10000KB     64bit IO Format:%I64d & %I64u
Submit Status

Description

Sally Jones has a dozen Voyageur silver dollars. However, only eleven of the coins are true silver dollars; one coin is counterfeit even though its color and size make it indistinguishable from the real silver dollars. The counterfeit coin has a different weight from the other coins but Sally does not know if it is heavier or lighter than the real coins. 
Happily, Sally has a friend who loans her a very accurate balance scale. The friend will permit Sally three weighings to find the counterfeit coin. For instance, if Sally weighs two coins against each other and the scales balance then she knows these two coins are true. Now if Sally weighs 
one of the true coins against a third coin and the scales do not balance then Sally knows the third coin is counterfeit and she can tell whether it is light or heavy depending on whether the balance on which it is placed goes up or down, respectively. 
By choosing her weighings carefully, Sally is able to ensure that she will find the counterfeit coin with exactly three weighings.

Input

The first line of input is an integer n (n > 0) specifying the number of cases to follow. Each case consists of three lines of input, one for each weighing. Sally has identified each of the coins with the letters A--L. Information on a weighing will be given by two strings of letters and then one of the words ``up'', ``down'', or ``even''. The first string of letters will represent the coins on the left balance; the second string, the coins on the right balance. (Sally will always place the same number of coins on the right balance as on the left balance.) The word in the third position will tell whether the right side of the balance goes up, down, or remains even.

Output

For each case, the output will identify the counterfeit coin by its letter and tell whether it is heavy or light. The solution will always be uniquely determined.

Sample Input

1 ABCD EFGH even ABCI EFJK up ABIJ EFGH even 

Sample Output

K is the counterfeit coin and it is light. 
我按照逻辑推理做的这道题,暴搜也能过这题。

思路就是如果平则秤上的球都是清白的,如果不平则不在秤上的球都是清白的,给重的那一方和轻的那一方没有清白标记的打上标记

最后还有标记的输出即可

结果WA了

我漏了一个关键问题,如果一个球被打上可能重的标记之后又在秤的偏轻一端出现,则这个球是清白的

加上这一点就能A了


int vis[20]; //-1 :unknown, 0 : clean 1 : light 2 : heavy char s1[20], s2[20], s3[20];int main(){    int tt; cin>>tt;    rep(kk, tt){        memset(vis, -1, sizeof(vis));        rep(j, 3){            scanf("%s%s%s", s1, s2, s3);            if (s3[0] == 'e'){                rep(i, strlen(s1)) vis[s1[i]-'A'] = 0;                rep(i, strlen(s2)) vis[s2[i]-'A'] = 0;            }else{                set<int> mset;                rep(i, strlen(s1)) mset.insert(s1[i] - 'A');                rep(i, strlen(s2)) mset.insert(s2[i] - 'A');                rep(i, 12) if (mset.count(i) == 0) vis[i] = 0;                rep(i, strlen(s1)) {                    int val = s3[0] == 'u' ? 2 : 1;;                    if (vis[s1[i]-'A'] == -1)                    vis[s1[i]-'A'] = val;                    if (vis[s1[i]-'A'] != 0 && vis[s1[i]-'A'] != val) vis[s1[i]-'A'] = 0; //                }                rep(i, strlen(s2)) {                    int val = s3[0] == 'u' ? 1 : 2;                    if (vis[s2[i]-'A'] == -1)                    vis[s2[i]-'A'] = val;                    if (vis[s2[i]-'A'] != 0 && vis[s2[i]-'A'] != val) vis[s2[i]-'A'] = 0; //                }            }            //rep(i, 12) printf("%d %d\n", i, vis[i]);            }        int ans = -1, dir = -1;        rep(i, 12) if (vis[i] != 0) {            ans = i; dir = vis[i];                    }        printf("%c is the counterfeit coin and it is %s. \n", ans + 'A', dir == 1 ? "light" : "heavy");    }    return 0;}


D - 不容易系列之(3)―― LELE的RPG难题

Description

人称“AC女之杀手”的超级偶像LELE最近忽然玩起了深沉,这可急坏了众多“Cole”(LELE的粉丝,即"可乐"),经过多方打探,某资深Cole终于知道了原因,原来,LELE最近研究起了著名的RPG难题: 

有排成一行的n个方格,用红(Red)、粉(Pink)、绿(Green)三色涂每个格子,每格涂一色,要求任何相邻的方格不能同色,且首尾两格也不同色.求全部的满足要求的涂法. 

以上就是著名的RPG难题. 

如果你是Cole,我想你一定会想尽办法帮助LELE解决这个问题的;如果不是,看在众多漂亮的痛不欲生的Cole女的面子上,你也不会袖手旁观吧? 

 

Input

输入数据包含多个测试实例,每个测试实例占一行,由一个整数N组成,(0<n<=50)。 
 

Output

对于每个测试实例,请输出全部的满足要求的涂法,每个实例的输出占一行。 
 

Sample Input

12
 

Sample Output

36

这题还是不错的,我找规律推完公式才找到关键。

如果不要求最后一位和第一位不同的话,答案就是3*2^(n-1),现在要求的话,我们只需扣除第n位和第1位相同的情况,这个情况有多少种?

其实很简单,就是n-1位下的标准答案,通过这个完成递推。

代码就不贴了。

R - Joseph
Time Limit:1000MS     Memory Limit:10000KB     64bit IO Format:%I64d & %I64u
Submit Status

Description

The Joseph's problem is notoriously known. For those who are not familiar with the original problem: from among n people, numbered 1, 2, . . ., n, standing in circle every mth is going to be executed and only the life of the last remaining person will be saved. Joseph was smart enough to choose the position of the last remaining person, thus saving his life to give us the message about the incident. For example when n = 6 and m = 5 then the people will be executed in the order 5, 4, 6, 2, 3 and 1 will be saved. 

Suppose that there are k good guys and k bad guys. In the circle the first k are good guys and the last k bad guys. You have to determine such minimal m that all the bad guys will be executed before the first good guy. 

Input

The input file consists of separate lines containing k. The last line in the input file contains 0. You can suppose that 0 < k < 14.

Output

The output file will consist of separate lines containing m corresponding to k in the input file.

Sample Input

340

Sample Output

530

这题还是不错的。约瑟夫问题一般是用模拟解决的,但这题用到了一个递推公式来计算被踢掉的人的序号,

设f(i)为第i+1轮被踢掉的人的序号(从0起算),则f(i) = (f(i-1) + m - 1) % (n - i)

f(0) = m - 1;

以n = 7, m = 5为例

f(0) = 4; f(1) = 2; f(2) = 1; f(3) = 1; f(4) = 2; f(5) = 0; f(6) = 0;

这个很明显不对啊

事实上,f(i)代表的是去掉之前被踢掉的人重新编号之后的序号

比如前三轮过后,情况是 1 4 6 7, 2刚被踢掉,下一个被踢的应该是4

而f(3) = 1, 1 4 6 7,重编号即0 1 2 3,1代表4

4被踢后,剩下1 6 7,下一个是7,f(4) = 2,也符合

个人认为这不是一个很有用的公式

但在这道题里非常有用,直接枚举m,按照这个公式进行递推,前k轮 值一旦小于k就代表这个值不对

按照这个思路进行打表即可.


P - Reduced ID Numbers
Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u
Submit Status

Description

T. Chur teaches various groups of students at university U. Every U-student has a unique Student Identification Number (SIN). A SIN s is an integer in the range 0 ≤ s ≤ MaxSIN with MaxSIN = 10 6-1. T. Chur finds this range of SINs too large for identification within her groups. For each group, she wants to find the smallest positive integer m, such that within the group all SINs reduced modulo m are unique.

Input

On the first line of the input is a single positive integer N, telling the number of test cases (groups) to follow. Each case starts with one line containing the integer G (1 ≤ G ≤ 300): the number of students in the group. The following G lines each contain one SIN. The SINs within a group are distinct, though not necessarily sorted.

Output

For each test case, output one line containing the smallest modulus m, such that all SINs reduced modulo m are distinct.

Sample Input

211248663124866111111987651

Sample Output

18
给G个数,求最小的m,使得这G个数模m互不相同。

这题我是用暴力过的,即从小到大枚举答案然后测试,测试的时候使用bitset就能过,用普通数组记录就可能T


const int maxn = 310;int a[maxn];bitset<1000010> vis;int main(){    int kk; cin>>kk;    rep(tt, kk){        int n; cin>>n;        rep(i, n) scanf("%d", &a[i]);        int ans = n;        while(1){            int flag = 1;            vis.reset();            rep(i, n){                int x = a[i] % ans;                if (vis[x] == 1) {flag = 0; break;}                vis[x] = 1;            }            if (flag) break;            ++ans;        }        printf("%d\n", ans);    }             return 0;}



C - Edge

Description

For products that are wrapped in small packings it is necessary that the sheet of paper containing the directions for use is folded until its size becomes small enough. We assume that a sheet of paper is rectangular and only folded along lines parallel to its initially shorter edge. The act of folding along such a line, however, can be performed in two directions: either the surface on the top of the sheet is brought together, or the surface on its bottom. In both cases the two parts of the rectangle that are separated by the folding line are laid together neatly and we ignore any differences in thickness of the resulting folded sheet. 
After several such folding steps have been performed we may unfold the sheet again and take a look at its longer edge holding the sheet so that it appears as a one-dimensional curve, actually a concatenation of line segments. If we move along this curve in a fixed direction we can classify every place where the sheet was folded as either type A meaning a clockwise turn or type V meaning a counter-clockwise turn. Given such a sequence of classifications, produce a drawing of the longer edge of the sheet assuming 90 degree turns at equidistant places. 
 

Input

The input contains several test cases, each on a separate line. Each line contains a nonempty string of characters A and V describing the longer edge of the sheet. You may assume that the length of the string is less than 200. The input file terminates immediately after the last test case. 
 

Output

For each test case generate a PostScript drawing of the edge with commands placed on separate lines. Start every drawing at the coordinates (300, 420) with the command "300 420 moveto". The first turn occurs at (310, 420) using the command "310 420 lineto". Continue with clockwise or counter-clockwise turns according to the input string, using a sequence of "x y lineto" commands with the appropriate coordinates. The turning points are separated at a distance of 10 units. Do not forget the end point of the edge and finish each test case by the commands stroke and showpage. 

You may display such drawings with the gv PostScript interpreter, optionally after a conversion using the ps2ps utility. 

Sample Input

VAVV
 

Sample Output

300 420 moveto310 420 lineto310 430 linetostrokeshowpage300 420 moveto310 420 lineto310 410 lineto320 410 lineto320 420 linetostrokeshowpage

这题看上去各种高大上有没有?什么gv PostScript之类的,事实上每组数据的第一行和最后两行都是套话,中间的输入长度+1行才有价值,这些行表示一些连笔的线段,线段的方向由输入控制.


int dx[] = {10,0,-10,0};int dy[] = {0,-10,0,10};char s[300];int main(){    while(scanf("%s", s) == 1){        int now = 0, x = 300, y = 420;        printf("300 420 moveto\n");        int len = strlen(s);        x += dx[now]; y += dy[now];        printf("%d %d lineto\n", x, y);        rep(i, len){            if (s[i] == 'A') now = (now + 1) % 4;            else now = now == 0 ? 3 : now - 1;            x += dx[now]; y += dy[now];            printf("%d %d lineto\n", x, y);        }        printf("stroke\nshowpage\n");    }    return 0;}



E - A + B
Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u
Description
读入两个小于100的正整数A和B,计算A+B. 
需要注意的是:A和B的每一位数字由对应的英文单词给出. 
 

Input

测试输入包含若干测试用例,每个测试用例占一行,格式为"A + B =",相邻两字符串有一个空格间隔.当A和B同时为0时输入结束,相应的结果不要输出. 
 

Output

对每个测试用例输出1行,即A+B的值. 
 

Sample Input

one + two =three four + five six =zero seven + eight nine =zero + zero =
 

Sample Output

39096
就是个模拟题

map<string, int> mmap;int num[10];int main(){    mmap["zero"] = 0;    mmap["one"] = 1;     mmap["two"] = 2;    mmap["three"] = 3;    mmap["four"] = 4;    mmap["five"] = 5;    mmap["six"] = 6;    mmap["seven"] = 7;    mmap["eight"] = 8;    mmap["nine"] = 9;    char s[100];    int now = 0;    while(scanf("%s", s) == 1){        if (s[0] == '+') now ^= 1;        else if (s[0] == '='){            int ans = num[0] + num[1];            //printf("%d %d\n", num[0], num[1]);            if (ans)printf("%d\n", ans); else break;            num[0] = num[1] = 0;            now ^= 1;        }else{            rep(i, strlen(s)) if (s[i] <= 'Z') s[i] = s[i] - 'A' + 'a';            int tmp = mmap[s];            num[now] = num[now] * 10 + tmp;        }    }    return 0;}

J - Ignatius and the Princess IV
Time Limit:1000MS     Memory Limit:32767KB     64bit IO Format:%I64d & %I64u
Submit Status

Description

"OK, you are not too bad, em... But you can never pass the next test." feng5166 says. 

"I will tell you an odd number N, and then N integers. There will be a special integer among them, you have to tell me which integer is the special one after I tell you all the integers." feng5166 says. 

"But what is the characteristic of the special integer?" Ignatius asks. 

"The integer will appear at least (N+1)/2 times. If you can't find the right integer, I will kill the Princess, and you will be my dinner, too. Hahahaha....." feng5166 says. 

Can you find the special integer for Ignatius? 
 

Input

The input contains several test cases. Each test case contains two lines. The first line consists of an odd integer N(1<=N<=999999) which indicate the number of the integers feng5166 will tell our hero. The second line contains the N integers. The input is terminated by the end of file. 
 

Output

For each test case, you have to output only one line which contains the special number you have found. 
 

Sample Input

51 3 2 3 3111 1 1 1 1 5 5 5 5 5 571 1 1 1 1 1 1
 

Sample Output

35

本想搞个map什么的,其实求个中位数就行了


K - next_permutation
Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u
Submit Status

Description

Now our hero finds the door to the BEelzebub feng5166. He opens the door and finds feng5166 is about to kill our pretty Princess. But now the BEelzebub has to beat our hero first. feng5166 says, "I have three question for you, if you can work them out, I will release the Princess, or you will be my dinner, too." Ignatius says confidently, "OK, at last, I will save the Princess." 

"Now I will show you the first problem." feng5166 says, "Given a sequence of number 1 to N, we define that 1,2,3...N-1,N is the smallest sequence among all the sequence which can be composed with number 1 to N(each number can be and should be use only once in this problem). So it's easy to see the second smallest sequence is 1,2,3...N,N-1. Now I will give you two numbers, N and M. You should tell me the Mth smallest sequence which is composed with number 1 to N. It's easy, isn't is? Hahahahaha......" 
Can you help Ignatius to solve this problem? 
 

Input

The input contains several test cases. Each test case consists of two numbers, N and M(1<=N<=1000, 1<=M<=10000). You may assume that there is always a sequence satisfied the BEelzebub's demand. The input is terminated by the end of file. 
 

Output

For each test case, you only have to output the sequence satisfied the BEelzebub's demand. When output a sequence, you should print a space between two numbers, but do not output any spaces after the last number. 
 

Sample Input

6 411 8
 

Sample Output

1 2 3 5 6 41 2 3 4 5 6 7 9 8 11 10
 

善用C++的话是个水题


M - 枚举答案能不能做?
Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u
Submit Status

Description

The digital root of a positive integer is found by summing the digits of the integer. If the resulting value is a single digit then that digit is the digital root. If the resulting value contains two or more digits, those digits are summed and the process is repeated. This is continued as long as necessary to obtain a single digit. 

For example, consider the positive integer 24. Adding the 2 and the 4 yields a value of 6. Since 6 is a single digit, 6 is the digital root of 24. Now consider the positive integer 39. Adding the 3 and the 9 yields 12. Since 12 is not a single digit, the process must be repeated. Adding the 1 and the 2 yeilds 3, a single digit and also the digital root of 39. 
 

Input

The input file will contain a list of positive integers, one per line. The end of the input will be indicated by an integer value of zero. 
 

Output

For each integer in the input, output its digital root on a separate line of the output. 
 

Sample Input

24390
 

Sample Output

63
 

这题就是求输入的数加起来模9,如果是0的话改成9就行了。

int getint(){    int ans = 0; char c;    while( (c = getchar()) != '\n'){        if (c <= '9' && c >= '0') ans = (ans + c - '0' - 1) % 9 + 1;    }        return ans;}int main(){    int sum;    while( (sum = getint()) != 0){        printf("%d\n", sum);    }    return 0;}

N - Bullseye
Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u
Submit Status

Description

A simple dartboard consists of a flat, circular piece of cork with concentric rings drawn on it. Darts are thrown at the board by players in an attempt to hit the center of the dartboard (the Bullseye). The region between each pair of rings (or the center and the first ring) represents a certain point value. The closer the region is to the center of the dartboard, the more points the region is worth, as shown in the diagram below: 

Ring radii are at 3", 6", 9", 12" and 15" (the Bullseye has a diameter of 6"). A game of Simple Darts between two players is played as follows. The first player throws 3 darts at the board. A score is computed by adding up the point values of each region that a dart lands in. The darts are removed. The second player throws 3 darts at the board; the score for player two is computed the same way as it is for player one. The player with the higher score wins. 

For this problem, you are to write a program that computes the scores for two players, and determine who, if anyone, wins the game. If a dart lands exactly on a ring (region boundary), the higher point value is awarded. Any dart outside the outer ring receives no points. For the purposes of this problem, you can assume that a dart has an infinitely fine point and can not land paritially on a ring; it is either on the ring or it is not on the ring. Standard double precision floating point operations will be should be used. 

Input

Input consists of 1 or more datasets. A dataset is a line with 12 double-precision values separated by spaces. Each pair of values represents the X and Y distances respectively of a dart from the center of the board in inches. (the center is located at X = 0, Y = 0. The range of values are: -20.0<=X, Y<=20.0. Player one's darts are represented by the first 3 pairs of values, and player two's by the last 3 pairs of values. Input is terminated by the first value of a dataset being -100.

Output

For each dataset, print a line of the form: 
SCORE: N to M, PLAYER P WINS. 

Or: 
SCORE: N to M, TIE. 

N is player one's score, and M is player two's score. P is either 1 or 2 depending on which player wins. All values are non-negative integers. 

Formula 

Recall: r 2 = x 2 + y 2 where r is the radius, and (x, y) are the coordinates of a point on the circle. 

Sample Input

-9 0 0 -4.5 -2 2 9 0 0 4.5 2 -2-19.0 19.0 0 0 0 0 3 3 6 6 12 12-100 0 0 0 0 0 0 0 0 0 0 0

Sample Output

SCORE: 240 to 240, TIE.SCORE: 200 to 140, PLAYER 1 WINS.
模拟题


O - Dirichlet's Theorem on Arithmetic Progressions
Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u
Submit Status

Description

If a and d are relatively prime positive integers, the arithmetic sequence beginning with a and increasing by d, i.e., aa + da + 2da + 3da + 4d, ..., contains infinitely many prime numbers. This fact is known as Dirichlet's Theorem on Arithmetic Progressions, which had been conjectured by Johann Carl Friedrich Gauss (1777 - 1855) and was proved by Johann Peter Gustav Lejeune Dirichlet (1805 - 1859) in 1837.

For example, the arithmetic sequence beginning with 2 and increasing by 3, i.e.,

2, 5, 8, 11, 14, 17, 20, 23, 26, 29, 32, 35, 38, 41, 44, 47, 50, 53, 56, 59, 62, 65, 68, 71, 74, 77, 80, 83, 86, 89, 92, 95, 98, ... ,

contains infinitely many prime numbers

2, 5, 11, 17, 23, 29, 41, 47, 53, 59, 71, 83, 89, ... .

Your mission, should you decide to accept it, is to write a program to find the nth prime number in this arithmetic sequence for given positive integers ad, and n.

Input

The input is a sequence of datasets. A dataset is a line containing three positive integers ad, and n separated by a space. a and d are relatively prime. You may assume a <= 9307, d <= 346, and n <= 210.

The end of the input is indicated by a line containing three zeros separated by a space. It is not a dataset.

Output

The output should be composed of as many lines as the number of the input datasets. Each line should contain a single integer and should never contain extra characters.

The output integer corresponding to a dataset adn should be the nth prime number among those contained in the arithmetic sequence beginning with a and increasing by d.

FYI, it is known that the result is always less than 106 (one million) under this input condition.

Sample Input

367 186 151179 10 203271 37 39103 230 127 104 185253 50 851 1 19075 337 210307 24 79331 221 177259 170 40269 58 1020 0 0

Sample Output

928096709120371039352314503289942951074127172269925673
筛出素数按要求模拟即可


U - Long Distance Racing
Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u
Submit Status

Description

Bessie is training for her next race by running on a path that includes hills so that she will be prepared for any terrain. She has planned a straight path and wants to run as far as she can -- but she must be back to the farm within M seconds (1 ≤ M ≤ 10,000,000).

The entire path she has chosen is T units (1 ≤ ≤ 100,000) in length and consists of equal-length portions that are uphill, flat, or downhill. The input data describes path segment i with a single character Si that is uf, or d, indicating respectively uphill, flat, or downhill.

Bessie takes U seconds (1 ≤ ≤ 100) to run one unit of uphill path, F (1 ≤ F ≤ 100) seconds for a unit of flat path, and (1 ≤ D ≤ 100) seconds for a unit of downhill path. Note that, when returning home, uphill paths become downhill paths and downhill paths become uphill paths.

Find the farthest distance Bessie can get from the farm and still make it back in time.

Input

* Line 1: Five space-separated integers: MT,UF, and D
* Lines 2..T+1: Line i+1 describes path segment i with a single letter: Si

Output

* Line 1: A single integer that is the farthest distance (number of units) that Bessie can get from the farm and make it back in time.

Sample Input

13 5 3 2 1ufudf

Sample Output

3
把每个单位的来回耗时统计一下,然后一步一步往前走就行了。
X - Specialized Four-Digit Numbers
Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u
Submit Status

Description

Find and list all four-digit numbers in decimal notation that have the property that the sum of its four digits equals the sum of its digits when represented in hexadecimal (base 16) notation and also equals the sum of its digits when represented in duodecimal (base 12) notation. 
For example, the number 2991 has the sum of (decimal) digits 2+9+9+1 = 21. Since 2991 = 1*1728 + 8*144 + 9*12 + 3, its duodecimal representation is 1893 12, and these digits also sum up to 21. But in hexadecimal 2991 is BAF 16, and 11+10+15 = 36, so 2991 should be rejected by your program. 
The next number (2992), however, has digits that sum to 22 in all three representations (including BB0 16), so 2992 should be on the listed output. (We don't want decimal numbers with fewer than four digits -- excluding leading zeroes -- so that 2992 is the first correct answer.) 

Input

There is no input for this problem

Output

Your output is to be 2992 and all larger four-digit numbers that satisfy the requirements (in strictly increasing order), each on a separate line with no leading or trailing blanks, ending with a new-line character. There are to be no blank lines in the output. The first few lines of the output are shown below.

Sample Input

There is no input for this problem

Sample Output

29922993299429952996299729982999...

转换进制即可

0 0
原创粉丝点击