百练-2018计算机学科夏令营上机考试题解(待续)

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

地址:

http://bailian.openjudge.cn/xly2018/

A:计算两个日期之间的天数

全局题号7595 提交次数663 尝试人数225 通过人数211

总时间限制:
1000ms
内存限制:
65536kB
描述
给定两个日期,计算相差的天数。比如2010-1-1和2010-1-3相差2天。
输入
共两行:
第一行包含三个整数startYear,startMonth,startDay,分别是起始年、月、日。
第二行包含三个整数endYear,endMonth,endDay,分别是结束年、月、日。
相邻两个整数之间用单个空格隔开。年份范围在1~3000。保证日期正确且结束日期不早于起始日期。
输出
输出一个整数,即是两个日期相差的天数。
样例输入
样例输出
提示
闰年被定义为能被4整除的年份,但是能被100整除而不能被400整除的年是例外,它们不是闰年。闰年的2月份有29天。

C++实现


B:回文子串

全局题号17415 提交次数450 尝试人数215 通过人数199

动态规划
总时间限制:
1000ms
内存限制:
65536kB
描述
给定一个字符串,寻找并输出字符串中最长回文子串。回文串即从左到右和从右到左读都一样的字符串。
如果字符串中包含多个回文子串,则返回第一个。
输入
第一行是整数n,字符串的个数(n < 20)
输出
接下来n行,每行一个字符串
字符串的长度不超过100
样例输入
样例输出

C++实现


C:The Die Is Cast

全局题号483 提交次数293 尝试人数77 通过人数39

DFS回溯

总时间限制:
1000ms
内存限制:
65536kB
描述
InterGames is a high-tech startup company that specializes in developing technology that allows users to play games over the Internet. A market analysis has alerted them to the fact that games of chance are pretty popular among their potential customers. Be it Monopoly, ludo or backgammon, most of these games involve throwing dice at some stage of the game.
Of course, it would be unreasonable if players were allowed to throw their dice and then enter the result into the computer, since cheating would be way to easy. So, instead, InterGames has decided to supply their users with a camera that takes a picture of the thrown dice, analyzes the picture and then transmits the outcome of the throw automatically.For this they desperately need a program that, given an image containing several dice, determines the numbers of dots on the dice.We make the following assumptions about the input images. The images contain only three different pixel values: for the background, the dice and the dots on the dice. We consider two pixels connected if they share an edge – meeting at a corner is not enough. In the figure, pixels A and B are connected, but B and C are not.


A set S of pixels is connected if for every pair (a,b) of pixels in S, there is a sequence a1, a2, …, ak in S such that a = a1 and b = ak , and ai and ai+1 are connected for 1 <= i < k.

We consider all maximally connected sets consisting solely of non-background pixels to be dice. `Maximally connected’ means that you cannot add any other non-background pixels to the set without making it dis-connected. Likewise we consider every maximal connected set of dot pixels to form a dot.

输入
The input consists of pictures of several dice throws. Each picture description starts with a line containing two numbers w and h, the width and height of the picture, respectively. These values satisfy 5 <= w, h <= 50.

The following h lines contain w characters each. The characters can be: “.” for a background pixel, “*” for a pixel of a die, and “X” for a pixel of a die’s dot.

Dice may have different sizes and not be entirely square due to optical distortion. The picture will contain at least one die, and the numbers of dots per die is between 1 and 6, inclusive.

The input is terminated by a picture starting with w = h = 0, which should not be processed.

输出
For each throw of dice, first output its number. Then output the number of dots on the dice in the picture, sorted in increasing order.

Print a blank line after each test case.

样例输入

样例输出

C++实现


D:Euro Efficiency

动态规划

全局题号254 提交次数90 尝试人数35 通过人数17

总时间限制:
1000ms
内存限制:
65536kB
描述
On January 1st 2002, The Netherlands, and several other European countries abandoned their national currency in favour of the Euro. This changed the ease of paying, and not just internationally.
A student buying a 68 guilder book before January 1st could pay for the book with one 50 guilder banknote and two 10 guilder banknotes, receiving two guilders in change. In short:50+10+10-1-1=68. Other ways of paying were: 50+25-5-1-1, or 100-25-5-1-1.Either way, there are always 5 units (banknotes or coins) involved in the payment process, and it
could not be done with less than 5 units.
Buying a 68 Euro book is easier these days: 50+20-2 = 68, so only 3 units are involved.This is no coincidence; in many other cases paying with euros is more efficient than paying with guilders. On average the Euro is more efficient. This has nothing to do, of course, with the value of the Euro, but with the units chosen. The units for guilders used to be: 1, 2.5, 5, 10, 25, 50,whereas the units for the Euro are: 1, 2, 5, 10, 20, 50.
For this problem we restrict ourselves to amounts up to 100 cents. The Euro has coins with values 1, 2, 5, 10, 20, 50 eurocents. In paying an arbitrary amount in the range [1, 100] eurocents, on average 2.96 coins are involved, either as payment or as change. The Euro series is not optimal in this sense. With coins 1, 24, 34, 39, 46, 50 an amount of 68 cents can be paid using two coins.The average number of coins involved in paying an amount in the range [1, 100] is 2.52.
Calculations with the latter series are more complex, however. That is, mental calculations.These calculations could easily be programmed in any mobile phone, which nearly everybody carries around nowadays. Preparing for the future, a committee of the European Central Bank is studying the efficiency of series of coins, to find the most efficient series for amounts up to 100 eurocents. They need your help.
Write a program that, given a series of coins, calculates the average and maximum number of coins needed to pay any amount up to and including 100 cents. You may assume that both parties involved have sufficient numbers of any coin at their disposal.
输入
The first line of the input contains the number of test cases. Each test case is described by 6 different positive integers on a single line: the values of the coins, in ascending order. The first number is always 1. The last number is less than 100.
输出
For each test case the output is a single line containing first the average and then the maximum number of coins involved in paying an amount in the range [1, 100]. These values are separated by a space. As in the example, the average should always contain two digits behind the decimal point. The maximum is always an integer.
样例输入
样例输出

C++实现


 

一条评论

  1. Euro Efficiency中动态规划的二重循环次数不够,无法仿真高面值货币的情况,建议j的范围到2000

留下评论

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