河南省第四届ACM程序设计大赛(共八道,目前只做两道。待续)

来源:互联网 发布:绥化seo服务 编辑:程序博客网 时间:2024/04/20 08:21

1630: 序号互换

时间限制: 1 Sec  内存限制: 128 MB
提交: 65  解决: 26
[提交][状态]

题目描述

Dr.Kong设计了一个聪明的机器人卡多,卡多会对电子表格中的单元格坐标快速计算出来。单元格的行坐标是由数字编号的数字序号,而列坐标使用字母序号。观察字母序号,发现第1列到第26列的字母序号分别为A,B,…,Z,接着,第27列序号为AA,第28列为AB,依此类推。

若给Dr.Kong的机器人卡多一个数字序号(比如32),它能很快算出等价的字母序号(即AF),若给机器人一个字母序号(比如AA)),它也能很快算出等价的数字序号(27),你能不能与卡多比试比试,看谁能算得更快更准确。 

输入

第一行: N        表示有多少组测试数据。

接下来有N行,    每行或者是一个正整数,或者是一个仅由大写字母组成的字符串。

输入保证,所有数字序号和字母序号对应的数字序号均 ≤ 2*10^9

输出

对于每一行测试数据,输出一行。如果输入为一个正整数序号,则输出等价的字母序号;如果输入为字符串,则输出等价的数字序号。

样例输入

327GAA

样例输出

AA727

提示

来源

河南省第四届大学生程序设计竞赛

#include<stdio.h>#include<ctype.h>#include<string.h>int main(){char s[15];int t, len, i, sum;scanf("%d",&t);while(t--&&scanf("%s",s)){if(isalpha(s[0]))     //输入的是字母 {len = strlen(s);for(i = sum = 0; i != len; ++i){sum = sum * 26 + (s[i] - 'A' + 1);   //AA-27  }  printf("%d\n",sum);}else     //输入的是数字 {sscanf(s,"%d",&sum);for(i = 0; sum; ++i){s[i] = (sum - 1) % 26 + 'A';sum = (sum - 1) / 26;   //关键 }for(--i; i >= 0; --i){putchar(s[i]);}putchar('\n'); }}return 0;}

1631: 节 能

时间限制: 1 Sec  内存限制: 128 MB
提交: 21  解决: 5
[提交][状态]

题目描述

Dr.Kong设计的机器人卡多越来越聪明。最近市政公司交给卡多一项任务,每天早晨5:00开始,它负责关掉ZK大道右侧上所有的路灯。

卡多每到早晨5:00准会在ZK大道上某盏路灯的旁边,然后他开始关灯。每盏灯都有一定的功率,机器人卡多有着自觉的节能意识,它希望在关灯期间,ZK大道右侧上所有路灯的耗电量总数是最少的。

机器人卡多以1m/s的速度行走。假设关灯动作不需要花费额外的时间,因为当它通过某盏路灯时就顺手将灯关掉。

请你编写程序,计算在给定路灯设置,灯泡功率以及机器人卡多的起始位置的情况下,卡多关灯期间,ZK大道上所有灯耗费的最小能量。

输入

第一行:  N       表示ZK大道右侧路灯的数量         (2≤ N ≤ 1000) 

第二行:  V       表示机器人卡多开始关灯的路灯号码。   (1≤V≤N)

接下来的N行中,每行包含两个用空格隔开的整数D和W,用来描述每盏灯的参数

D表示该路灯与ZK大道起点的距离  (用米为单位来表示),

W表示灯泡的功率,即每秒该灯泡所消耗的能量数。路灯是按顺序给定的。

( 0≤D≤1000, 0≤W≤1000 )

输出

输出一个整数,即消耗能量之和的最小值。注意结果小于200,000,000

样例输入

4 32 25 86 18 7

样例输出

56

提示

来源

河南省第四届大学生程序设计竞赛



1632: 表达式求值

时间限制: 1 Sec  内存限制: 128 MB
提交: 69  解决: 28
[提交][状态]

题目描述

Dr.Kong设计的机器人卡多掌握了加减法运算以后,最近又学会了一些简单的函数求值,比如,它知道函数min(20,23)的值是20 ,add(10,98) 的值是108等等。经过训练,Dr.Kong设计的机器人卡多甚至会计算一种嵌套的更复杂的表达式。

假设表达式可以简单定义为:

1. 一个正的十进制数 x 是一个表达式。

2. 如果 x 和 y 是 表达式,则 函数min(x,y )也是表达式,其值为x,y 中的最小数。

3. 如果 x 和 y 是 表达式,则 函数max(x,y )也是表达式,其值为x,y 中的最大数。

4.如果 x 和 y 是 表达式,则 函数add(x,y )也是表达式,其值为x,y 之和。

例如, 表达式 add(max(add(1,2),7) 的值为 7。

请你编写程序,对于给定的一组表达式,帮助 Dr.Kong 算出正确答案,以便校对卡多计算的正误。

输入

第一行: N        表示要计算的表达式个数 (1≤ N ≤ 10) 

接下来有N行,    每行是一个字符串,表示待求值的表达式

(表达式中不会有多余的空格,每行不超过300个字符,表达式中出现的十进制数都不

超过1000。)

输出

输出有N行,每一行对应一个表达式的值。

样例输入

3add(1,2) max(1,999) add(min(1,1000),add(100,99))

样例输出

3999200

提示

来源

河南省第四届大学生程序设计竞赛




1633: 走迷宫

时间限制: 2 Sec  内存限制: 128 MB
提交: 64  解决: 12
[提交][状态]

题目描述

Dr.Kong设计的机器人卡多非常爱玩,它常常偷偷跑出实验室,在某个游乐场玩之不疲。这天卡多又跑出来了,在SJTL游乐场玩个不停,坐完碰碰车,又玩滑滑梯,这时卡多又走入一个迷宫。整个迷宫是用一个N * N的方阵给出,方阵中单元格中填充了一个整数,表示走到这个位置的难度。
这个迷宫可以向上走,向下走,向右走,向左走,但是不能穿越对角线。走迷宫的取胜规则很有意思,看谁能更快地找到一条路径,其路径上单元格最大难度值与最小难度值之差是最小的。当然了,或许这样的路径不是最短路径。
     机器人卡多现在在迷宫的左上角(第一行,第一列)而出口在迷宫的右下角(第N行,第N列)。
卡多很聪明,很快就找到了这样的一条路径。你能找到吗?

输入

第一行:         N     表示迷宫是N*N方阵        (2≤ N≤ 100)
接下来有N行,    每一行包含N个整数,用来表示每个单元格中难度 (0≤任意难度≤120)。

输出

输出为一个整数,表示路径上最高难度与和最低难度的差。

样例输入

51 1 3 6 81 2 2 5 54 4 0 3 38 0 2 3 44 3 0 2 1

样例输出

2

提示

来源

河南省第四届大学生程序设计竞赛




1634: 宝 物

时间限制: 1 Sec  内存限制: 128 MB
提交: 9  解决: 4
[提交][状态]

题目描述

传说HMH大沙漠中有一个迷宫,里面藏有许多宝物。迷宫里可能有N个藏宝地点,用1到N标记。藏宝地点之间最多有一条通路相连。标记1为迷宫的进出口。

某天,Dr.Kong找到了迷宫的地图,他已经知道其中K(1<=K<=N)个不同的地点真的藏有宝物。Dr.Kong决定让他的机器人卡多去探险。卡多在经过某个藏宝地点时可能会拿走宝物。但它每拿走一个藏宝地点的宝物后,它的载重量就会增加W。迷宫中的通路不是平坦的,到处都是陷阱。假设每条通路都有一个危险度,其值与通过此路的载重量成正比。

当机器人卡多进入迷宫时,它的载重量为0。只有当卡多携带宝物的载重量不大于某个通路的危险度时,它才能顺利通过此条道路,否则就会掉入陷阱,不能出来。

Dr.Kong希望他的机器人卡多尽量多的带出宝物,当然他更希望卡多最后能从标记1的地点走出去。

请你编写程序,帮助Dr.Kong计算一下,卡多最多能带出多少个藏宝地点的宝物。

输入

第1行:         N M K W

接下来有K行,  每行一个整数,表示藏有宝物的地点标号。

再接下来有M行,每行三个整数X,Y,Z,表示地点X与地点Y之间有一条危险度为Z的通路。

1 ≤ N ≤ 8000   1 ≤ K ≤ N    1 ≤ M ≤ 15000  1 ≤ W, Z ≤ 10000

数据保证所有的地点之间都是有道路可以到达的。

提示:机器人卡多经过一个藏宝地点时可以不拿走宝物, 而且同一个藏宝地点可以经过多次。

输出

输出有一个整数, 表示卡多最多能带出的宝物的堆数。

样例输入

6 7 5 1123451 2 33 6 26 2 102 4 15 1 14 5 11 6 1

样例输出

4

提示

来源

河南省第四届大学生程序设计竞赛



1635: SUBSTRING

时间限制: 1 Sec  内存限制: 128 MB
提交: 48  解决: 19
[提交][状态]

题目描述

You are given a string input. You are to find the longest substring of input such that the reversal of the substring is also a substring of input. In case of a tie, return the string that occurs earliest in input. 

Note well: The substring and its reversal may overlap partially or completely. The entire original string is itself a valid substring . The best we can do is find a one character substring, so we implement the tie-breaker rule of taking the earliest one first.

输入

The first line of input gives a single integer, 1 ≤ N ≤ 10,  the number of test cases. Then follow, for each test case,  a  line  containing between 1 and 50 characters, inclusive. Each character of input will be an uppercase letter ('A'-'Z').

输出

Output for each test case  the longest substring of input such that the reversal of the substring is also a substring of input

样例输入

3                   ABCABAXYZXCVCX

样例输出

ABAXXCVCX

提示

来源

河南省第四届大学生程序设计竞赛

#include<stdio.h>#include<string.h>int main(){int T,i,j;int len,max,k;char a[55],b[55],c[55][55];scanf("%d",&T);while(T--){memset(a,0,sizeof(a));memset(b,0,sizeof(b));memset(c,0,sizeof(c));scanf("%s",a);len = strlen(a);for(i = len - 1; i >= 0; i--){b[len - 1 - i]  = a[i];}max = 0;for(i = 1; i <= len; i++){for(j = 1; j <= len; j++){if(a[i-1] == b[j-1]){c[i][j] = c[i-1][j-1]+1;if(max<c[i][j]){max = c[i][j];k = i;}}}}for(i = k - max; i < k; i++){printf("%c",a[i]);}printf("\n");}return 0;}

1636: BOBSLEDDING

时间限制: 1 Sec  内存限制: 128 MB
提交: 94  解决: 26
[提交][状态]

题目描述

Dr.Kong has entered a bobsled competition because he hopes his hefty weight will give his an advantage over the L meter course (2 <= L<= 1000).
 
Dr.Kong will push off the starting line at 1 meter per second, but  his speed can change while he rides along the course. Near the middle of every meter Bessie travels, he can change his  speed  either by using gravity to accelerate by one meter per second or by braking to stay at the same speed or decrease his speed by one meter per second.
 
Naturally, Dr.Kong must negotiate N (1 <= N <= 500) turns on the way down the hill. Turn i is located T_i  meters from the course start (1 <= T_i <= L-1), and  he must be enter the corner meter at  a peed of at most S_i  meters per second (1 <= S_i <= 1000).  Dr.Kong can cross the finish line at any speed he likes.
 
Help Dr.Kong learn the fastest speed he can attain without exceeding the speed limits on the turns.
 
Consider this course with the meter markers as integers and the  turn speed limits in brackets (e.g., '[3]'):
 
0    1   2   3   4   5   6   7[3]   8   9  10  11[1]  12   13[8]    14                    
(Start) |------------------------------------------------------------------------------------- ---------à|  (Finish)   
                    
Below is a chart of  Dr.Kong 's speeds at the beginning of each meter length of the course:
Max:                               [3]             [1]      [8]
Mtrs:   0   1   2   3   4   5   6   7   8   9  10  11  12   13   14 
Spd:    1   2   3   4   5   5   4   3   4   3   2   1   2   3    4
 
His maximum speed was 5 near the beginning of meter 4.

输入

Line 1:       Two space-separated integers: L and N
Lines 2..N+1:  Line i+1 describes turn i with two space-separated  integers: T_i and S_i

输出

Line 1:   A single integer,  representing the maximum speed which   Dr.Kong can attain between the start and the finish line,  inclusive.

样例输入

14 37 311 113 8

样例输出

5

提示

来源

河南省第四届大学生程序设计竞赛

1637: SECRET

时间限制: 1 Sec  内存限制: 128 MB
提交: 16  解决: 2
[提交][状态]

题目描述

Dr.Kong is constructing a new machine and wishes to keep it secret as long as possible. He has hidden in it deep within some forest  and needs to be able to get to the machine  without being detected.  He must make a total of T (1 <= T <= 200) trips to the  machine during its construction. He has a secret tunnel that he uses only for the return trips.

 

The forest comprises N (2 <= N <= 200) landmarks (numbered 1..N)  connected by P (1 <= P <= 40,000) bidirectional trails (numbered  1..P) and with a positive length that does not exceed 1,000,000.  Multiple trails might join a pair of landmarks.

 

To minimize his chances of detection, Dr.Kong knows he cannot use any  trail on the forest more than once and that he should try  to use the shortest trails.

 

Help Dr.Kong get from the entrance (landmark 1) to the secret  machine  (landmark N) a total of T times.  Find the minimum possible length of the longest single trail that he will have to use, subject to the  constraint that he use no trail more than once.

 

 (Note well: The goal is to minimize the length of the longest trail, not the sum of the  trail lengths.)

 

It is guaranteed that  Dr.Kong can make all T trips without reusing a trail.

输入

Line 1:       Three space-separated integers: N, P, and T

Lines 2..P+1:  Line i+1 contains three space-separated integers, A_i,  B_i, and L_i,

 indicating that a trail connects landmark A_i to  landmark B_i with length L_i.

输出

Line 1:    A single integer that is the minimum possible length of the  longest segment of

Dr.Kong 's route.

样例输入

7 9 21 2 22 3 53 7 51 4 14 3 14 5 75 7 11 6 36 7 3

样例输出

5

提示

来源

河南省第四届大学生程序设计竞赛


0 1