SDNUOJ刷题杂谈(—)小题大做

本文通过两个编程题目的解析,强调了编程过程中细节的重要性。作者分享了在解决具体问题时遇到的陷阱,提醒读者注意诸如角度计算、递归函数输出等易被忽视的细节。

天天刷题,慢慢的也会有一些感想。一般情况下我们会认为那些题目很多字,样例很大很多,代码很多行的题是难题。当然,这样的题一般不好做,但有时候我们也会在阴沟翻船,小坑摔倒。

就比如:

1094.Clock

Time Limit: 1000 MS    Memory Limit: 32768 KB
Total Submission(s): 102    Accepted Submission(s): 39

Description

There is an analog clock with two hands: an hour hand and a minute hand. The two hands form an angle. The angle is measured as the smallest angle between the two hands. The angle between the two hands has a measure that is greater than or equal to 0 and less than or equal to 180 degrees.
Given a sequence of five distinct times written in the format hh : mm , where hh are two digits representing full hours (00 <= hh <= 23) and mm are two digits representing minutes (00 <= mm <= 59) , you are to write a program that finds the median, that is, the third element of the sorted sequence of times in a nondecreasing order of their associated angles. Ties are broken in such a way that an earlier time precedes a later time.
For example, suppose you are given a sequence (06:05, 07:10, 03:00, 21:00, 12:55) of times. Because the sorted sequence is (12:55, 03:00, 21:00, 06:05, 07:10), you are to report 21:00.

Input

The input consists of T test cases. The number of test cases (T) is given on the first line of the input file. Each test case is given on a single line, which contains a sequence of five distinct times, where times are given in the format hh : mm and are separated by a single space.

Output

Print exactly one line for each test case. The line is to contain the median in the format hh : mm of the times given. The following shows sample input and output for three test cases.

Sample Input

3
00:00 01:00 02:00 03:00 04:00
06:05 07:10 03:00 21:00 12:55
11:05 12:05 13:05 14:05 15:05

Sample Output

02:00
21:00
14:05

Source

这个题,其实思路很好找的,转换成分钟排个序喽。
然而,在真正实现的时候,我们可能会忘记他的角度始终在0到180之间,至极则反,取个绝对值啦;对于每个格式time算角度时,别忘了分针转的时候时针也在转,每分钟半度 etc. 这些可供粗心的方面固然重要,再加上做后的输出,也不好写。这种格式在 office里自然好弄,要是自己写的话你确定会弄吗。关于:printf ("%02d : %02d\n", a, b); 这种老司机的熟练手法,反正我是自己查了百度之后才get 到这个新技能的。事出毫末,也是不可不察啊。或许,一个合格程序员的打造过程,就是它不断吸收这些细节知识的路吧。
还有一个极好的反面样例供大家吸取教训,也为我自己默哀:
 

1072.我们爱递归

Time Limit: 1000 MS    Memory Limit: 32768 KB
Total Submission(s): 211    Accepted Submission(s): 65

Description

我们想明白递归函数到底是怎么运作的,所以想用递归来计算当给定一个正整数n(n < 16)时,求出n + (n-1)……+1的值,同时进行一些输出
要求写一个int plus1(int a)形式的函数,在进入递归函数时,输出相关信息。在调用结束返回值前,输出相关信息。最后输出n + (n-1)……+1的值

Input

3

Output

[plus1(3) output]Begin invoke plus1(3)
[plus1(3) output]I want to calculate plus1(3), require 3 and the value of plus1(2),so I need to invoke plus1(2)
[plus1(2) output]Begin invoke plus1(2)
[plus1(2) output]I want to calculate plus1(2), require 2 and the value of plus1(1),so I need to invoke plus1(1)
[plus1(1) output]Begin invoke plus1(1)
[plus1(1) output]return plus1(1) = 1
[plus1(2) output]I got the value of plus1(1), and plus it to 2then return3
[plus1(3) output]I got the value of plus1(2), and plus it to 3then return6
6

Sample Input

3

Sample Output

[plus1(3) output]Begin invoke plus1(3)
[plus1(3) output]I want to calculate plus1(3), require 3 and the value of plus1(2),so I need to invoke plus1(2)
[plus1(2) output]Begin invoke plus1(2)
[plus1(2) output]I want to calculate plus1(2), require 2 and the value of plus1(1),so I need to invoke plus1(1)
[plus1(1) output]Begin invoke plus1(1)
[plus1(1) output]return plus1(1) = 1
[plus1(2) output]I got the value of plus1(1), and plus it to 2then return3
[plus1(3) output]I got the value of plus1(2), and plus it to 3then return6
6

Hint

int plus1(int a)
{
    // 从这里输出开始调用时的信息
    if(a == 1)
    {
        // 从这里输出最后一次调用的返回信息
        return ……;
    }
    else
    {
        // 从这里输出调用时的信息
        // 开始进行递归调用下一步
        ……
        int c = plus1(a - 1);
        // 从这里输出返回值前的信息
        ……
        return ……;
    }
}

Source

清清白白的一个大水题,而我从一个多月之前直到现在还是做不出来。真是天苍苍那个野茫茫,有一人他想骂娘~~
据我自己分析,应当是某些细节上没弄好,以至于这样的基础题做不出来,丢人啊。
还有一些相对简单的题,要用到数组,并且是多组样例,加EOF。就因为我没有养成好习惯,听师哥和课本的话,用 memset 函数对他们进行初始化,而WA了无数次,不说了,说多了都是泪啊。
所谓细节决定成败,也就是如此吧,对于我们程序员来说尤为如此。
与其粗放式操作和学习,成为败犬,还不如变成患有完美主义强迫症的程序员来的潇洒,还可以独自在冷风中,无敌着,寂寞着,多帅~~

### 智能车技术最新进展 智能车技术近年来取得了显著进步,尤其是在自动驾驶领域。长城汽车于2021年6月推出的咖啡智能2.0智慧线控底盘整合了多个核心底盘系统,包括线控转向、线控制动、线控换挡、线控油门和线控悬挂,成为国内首个支持L4+级自动驾驶的线控转向底盘系统[^4]。 此外,中航集团旗下的耐世特也在2018年发布了SBW技术,并推出了静默方向盘系统及随需转向系统,这些技术支持L3+级自动驾驶。这表明在高级别自动驾驶方面,国内外厂商都在积极布局并取得了一定的技术突破。 与此同时,新能源汽车市场的快速发展也为智能车技术提供了更多可能性。根据外媒CleanTechnica统计的数据,比亚迪、特斯拉和上汽通用五菱分别以506,868辆、406,869辆和183,054辆的销量位居前列,占据了全球新能源汽车市场约34%的份额[^3]。这种市场需求的增长推动了智能车技术的研发与应用。 值得注意的是,随着深度学习技术的进步及其广泛应用,人工智能伦理和社会影响逐渐引起重视。确保人工智能技术发展既能提升社会福祉又能规避潜在风险已成为重要议[^2]。这一趋势同样适用于智能车领域,特别是在数据隐私保护、算法公平性和安全性等方面需要持续关注。 ```python class AutonomousDrivingSystem: def __init__(self, level): self.level = level def describe(self): if self.level >= 4: return f"L{self.level} autonomous driving system with full automation capabilities." elif self.level == 3: return f"L{self.level} autonomous driving system requiring driver attention but capable of handling most situations autonomously." else: return f"Lower-level ({self.level}) autonomous assistance features." # Example usage ad_system_l4 = AutonomousDrivingSystem(4) print(ad_system_l4.describe()) ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值