秒数与标准时间互换-no more than one line

本文介绍了如何利用Shell中的date命令来获取特定日期距离1970年1月1日的秒数,以及如何根据秒数反推日期。文中还解释了CST、UTC和GMT等时区的概念。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

    from ysuncn

        很多时候解决这个题,大家都选择自己编个脚本,其实一句shell的date命令就足以了。

        --------------------------------------------

        得到某个时间距1970年1月1日00:00:00的秒数

        date -d '1971/01/01 00:00:00' +%s       -------------31507200

        --------------------------------------------

        由秒数反查时间

        date -d ' 1970-01-01 UTC 31507200 seconds'   ----Fri Jan  1 00:00:00 CST 1971

        --------------------------------------------

        试试这个

        date -d ' 1970-01-01 CST 1185974627 seconds'  --------Thu Dec 31 16:00:00 CST 1970

  这个格式里面的CST是中国标准时间(China Standard Time)的意思。关于时区,在/etc/sysconfig/clock里有记录。时区很多,一般没必要记住,知道以下几个可能就差不多了:

  CST:中国标准时间(China Standard Time)。

  UTC:协调世界时,又称世界标准时间,简称UTC,从英文国际时间/法文协调时间”Universal Time/Temps Cordonné”而来。中国大陆、香港、澳门、台湾、蒙古国、新加坡、马来西亚、菲律宾、澳洲西部的时间与UTC的时差均为+8,也就是UTC+8。 (上边的例子是不是很清楚了:)

  GMT:格林尼治标准时间(旧译格林威治平均时间或格林威治标准时间;英语:Greenwich Mean Time,GMT)是指位于英国伦敦郊区的皇家格林尼治天文台的标准时间,因为本初子午线被定义在通过那里的经线。

        附世界时间对照表:http://www.time.ac.cn/stime.asp
 

At the entrance to the university, there is a huge rectangular billboard of size h*w (h is its height and w is its width). The board is the place where all possible announcements are posted: nearest programming competitions, changes in the dining room menu, and other important information. 在大学的入口处,有一个巨大的矩形广告牌,尺寸为h*w (h为其高度,w为其宽度)。公告板是张贴所有可能的公告的地方:最近的编程比赛,餐厅菜单的变化以及其他重要信息。 On September 1, the billboard was empty. One by one, the announcements started being put on the billboard. 9月1日,广告牌空无一人。公告开始一个接一个地贴在广告牌上。 Each announcement is a stripe of paper of unit height. More specifically, the i-th announcement is a rectangle of size 1 * wi. 每个公告都是单位高度的条纹纸。更具体地说,第i个公告是一个大小为1 * wi的矩形。 When someone puts a new announcement on the billboard, she would always choose the topmost possible position for the announcement. Among all possible topmost positions she would always choose the leftmost one. 当有人在广告牌上张贴新的公告时,她总是选择最可能的位置来张贴公告。在所有可能的最上面的位置中,她总是选择最左边的位置。 If there is no valid location for a new announcement, it is not put on the billboard (that's why some programming contests have no participants from this university). 如果一个新的公告没有有效的位置,它就不会被放在广告牌上(这就是为什么一些编程比赛没有来自这所大学的参者)。 Given the sizes of the billboard and the announcements, your task is to find the numbers of rows in which the announcements are placed. 给定广告牌和公告的大小,您的任务是找到放置公告的行数。 Input 输入 There are multiple cases (no more than 40 cases). 有多例(不超过40例)。 The first line of the input file contains three integer numbers, h, w, and n (1 <= h,w <= 10^9; 1 <= n <= 200,000) - the dimensions of the billboard and the number of announcements. 输入文件的第一行包含三个整数,h,w和n (1 <= h,w <= 10^9;1 <= n <= 200,000) -广告牌的尺寸和公告的数量。 Each of the next n lines contains an integer number wi (1 <= wi <= 10^9) - the width of i-th announcement. 接下来的n行每一行都包含一个整数wi (1 <= wi <= 10^9)——第i条公告的宽度。 Output 输出 For each announcement (in the order they are given in the input file) output one number - the number of the row in which this announcement is placed. Rows are numbered from 1 to h, starting with the top row. If an announcement can't be put on the billboard, output "-1" for this announcement. 对于每个公告(按照输入文件中给出的顺序),输出一个数字——该公告所在行的编号。行从1到h编号,从第一行开始。如果一个公告不能放在广告牌上,则为该公告输出“-1”。 Sample Input 样例输入 3 5 5 2 4 3 3 3 Sample Output 样例输出 1 2 1 3 -1 使用二分算法并且不能超时
最新发布
06-30
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值