百练-2016研究生推免上机考试(待续)

作为一个编程菜鸡,先刷刷前几题,八道题目争取6题有思路,5题能写出来,3题能AC(大佬勿嘲笑)。由于部分题目已经关闭,无法看到是否AC(以下代码可能无法通过全部测试用例),如有错误,请指出,O(∩_∩)O谢谢。

A:石头剪刀布

全局题号4973 提交次数222 尝试人数100 通过人数95

总时间限制:
1000ms
内存限制:
65536kB
描述
石头剪刀布是常见的猜拳游戏。石头胜剪刀,剪刀胜布,布胜石头。如果两个人出拳一样,则不分胜负。

一天,小A和小B正好在玩石头剪刀布。已知他们的出拳都是有周期性规律的,比如:“石头-布-石头-剪刀-石头-布-石头-剪刀……”,就是以“石头-布-石头-剪刀”为周期不断循环的。请问,小A和小B比了N轮之后,谁赢的轮数多?

输入
输入包含三行。
第一行包含三个整数:N,NA,NB,分别表示比了N轮,小A出拳的周期长度,小B出拳的周期长度。0 < N,NA,NB < 100。
第二行包含NA个整数,表示小A出拳的规律。
第三行包含NB个整数,表示小B出拳的规律。
其中,0表示“石头”,2表示“剪刀”,5表示“布”。相邻两个整数之间用单个空格隔开。
输出
输出一行,如果小A赢的轮数多,输出A;如果小B赢的轮数多,输出B;如果两人打平,输出draw。
样例输入

样例输出

提示
对于测试数据,猜拳过程为:
A:0 2 5 0 2 5 0 2 5 0
B:0 5 0 2 0 5 0 2 0 5
A赢了4轮,B赢了2轮,双方打平4轮,所以A赢的轮数多。

C++代码


B:字符串判等

全局题号1745 提交次数246 尝试人数97 通过人数90

总时间限制:
1000ms
内存限制:
65536kB
描述
判断两个由大小写字母和空格组成的字符串在忽略大小写,且忽略空格后是否相等。
输入
两行,每行包含一个字符串。
输出
若两个字符串相等,输出YES,否则输出NO。
样例输入
样例输出

C++实现


C:图像旋转

全局题号8065 提交次数174 尝试人数98 通过人数94

总时间限制:
1000ms
内存限制:
65536kB
描述
输入一个n行m列的黑白图像,将它顺时针旋转90度后输出。
输入
第一行包含两个整数n和m,表示图像包含像素点的行数和列数。1 <= n <= 100,1 <= m <= 100。
接下来n行,每行m个整数,表示图像的每个像素点灰度。相邻两个整数之间用单个空格隔开,每个元素均在0~255之间。
输出
m行,每行n个整数,为顺时针旋转90度后的图像。相邻两个整数之间用单个空格隔开。
样例输入
样例输出

C++实现


D:棋盘问题

全局题号323 提交次数131 尝试人数52 通过人数26

总时间限制:
1000ms
内存限制:
65536kB
描述
在一个给定形状的棋盘(形状可能是不规则的)上面摆放棋子,棋子没有区别。要求摆放时任意的两个棋子不能放在棋盘中的同一行或者同一列,请编程求解对于给定形状和大小的棋盘,摆放k个棋子的所有可行的摆放方案C。
输入
输入含有多组测试数据。
每组数据的第一行是两个正整数,n k,用一个空格隔开,表示了将在一个n*n的矩阵内描述棋盘,以及摆放棋子的数目。 n <= 8 , k <= n
当为-1 -1时表示输入结束。
随后的n行描述了棋盘的形状:每行有n个字符,其中 # 表示棋盘区域, . 表示空白区域(数据保证不出现多余的空白行或者空白列)。
输出
对于每一组数据,给出一行输出,输出摆放的方案数目C (数据保证C<2^31)。
样例输入
样例输出

C++实现

 


G:Tangled in Cables

全局题号1077 提交次数126 尝试人数56 通过人数41

总时间限制:
1000ms
内存限制:
65536kB
描述
You are the owner of SmallCableCo and have purchased the franchise rights for a small town. Unfortunately, you lack enough funds to start your business properly and are relying on parts you have found in an old warehouse you bought. Among your finds is a single spool of cable and a lot of connectors. You want to figure out whether you have enough cable to connect every house in town. You have a map of town with the distances for all the paths you may use to run your cable between the houses. You want to calculate the shortest length of cable you must have to connect all of the houses together.
输入
Only one town will be given in an input.

  • The first line gives the length of cable on the spool as a real number.
  • The second line contains the number of houses, N
  • The next N lines give the name of each house’s owner. Each name consists of up to 20 characters {a–z,A–Z,0–9} and contains no whitespace or punctuation.
  • Next line: M, number of paths between houses
  • next M lines in the form

< house name A > < house name B > < distance >
Where the two house names match two different names in the list above and the distance is a positive real number. There will not be two paths between the same pair of houses.

输出
The output will consist of a single line. If there is not enough cable to connect all of the houses in the town, output
Not enough cable
If there is enough cable, then output
Need < X > miles of cable
Print X to the nearest tenth of a mile (0.1).
样例输入

样例输出

C++实现


 

留下评论

您的电子邮箱地址不会被公开。 必填项已用*标注