贺巩山的博客

没有伞的孩子更要努力奔跑


  • 首页

  • 文件系统

  • Linux运维

  • 剑指Offer

  • LeetCode题解

  • PAT甲级题解

  • PAT乙级题解

  • CCF CSP题解

  • 分类

  • 标签

  • 归档

  • 书单

  • 关于

  • 搜索

PAT甲级 1065.A+B and C (64bit) (20 分)

发表于 2019-04-06 | 更新于 2019-04-06 | 分类于 pat甲级
字数统计: 495

Given three integers A, B and C in [−2^63,2^63], you are supposed to tell whether A+B>C.

阅读全文 »

PAT甲级 1046.Shortest Distance (20 分)

发表于 2019-04-05 | 更新于 2019-04-05 | 分类于 pat甲级
字数统计: 441

The task is really simple: given N exits on a highway which forms a simple cycle, you are supposed to tell the shortest distance between any pair of exits.

阅读全文 »

LeetCode 21.合并两个有序链表/《剑指Offer》25.合并两个排序的链表

发表于 2019-04-05 | 更新于 2020-02-27 | 分类于 leetcode
字数统计: 478

题目描述

将两个有序链表合并为一个新的有序链表并返回。新链表是通过拼接给定的两个链表的所有节点组成的。

示例:

1
2
输入:1->2->4, 1->3->4
输出:1->1->2->3->4->4
阅读全文 »

LeetCode 25.k个一组翻转链表

发表于 2019-04-04 | 更新于 2019-04-05 | 分类于 leetcode
字数统计: 702

题目描述

给出一个链表,每 k 个节点一组进行翻转,并返回翻转后的链表。

k 是一个正整数,它的值小于或等于链表的长度。如果节点总数不是 k 的整数倍,那么将最后剩余节点保持原有顺序。

示例 :

给定这个链表:1->2->3->4->5

当 k = 2 时,应当返回: 2->1->4->3->5

当 k = 3 时,应当返回: 3->2->1->4->5

说明 :

  • 你的算法只能使用常数的额外空间。
  • 你不能只是单纯的改变节点内部的值,而是需要实际的进行节点交换。
阅读全文 »

PAT甲级 1042.Shuffling Machine (20 分)

发表于 2019-04-03 | 更新于 2019-04-03 | 分类于 pat甲级
字数统计: 941

Shuffling is a procedure used to randomize a deck of playing cards. Because standard shuffling techniques are seen as weak, and in order to avoid “inside jobs” where employees collaborate with gamblers by performing inadequate shuffles, many casinos employ automatic shuffling machines. Your task is to simulate a shuffling machine.

The machine shuffles a deck of 54 cards according to a given random order and repeats for a given number of times. It is assumed that the initial status of a card deck is in the following order:

1
2
3
4
5
S1, S2, ..., S13, 
H1, H2, ..., H13,
C1, C2, ..., C13,
D1, D2, ..., D13,
J1, J2

where “S” stands for “Spade”, “H” for “Heart”, “C” for “Club”, “D” for “Diamond”, and “J” for “Joker”. A given order is a permutation of distinct integers in [1, 54]. If the number at the i-th position is j, it means to move the card from position i to position j. For example, suppose we only have 5 cards: S3, H5, C1, D13 and J2. Given a shuffling order {4, 2, 5, 3, 1}, the result will be: J2, H5, D13, S3, C1. If we are to repeat the shuffling again, the result will be: C1, H5, S3, J2, D13.

阅读全文 »

PAT乙级 1018.锤子剪刀布 (20 分)

发表于 2019-04-01 | 更新于 2019-04-05 | 分类于 pat乙级
字数统计: 583

大家应该都会玩“锤子剪刀布”的游戏:两人同时给出手势,胜负规则如图所示:

FigCJB.jpg

现给出两人的交锋记录,请统计双方的胜、平、负次数,并且给出双方分别出什么手势的胜算最大。

阅读全文 »

PAT乙级 1012.数字分类 (20 分)

发表于 2019-04-01 | 更新于 2019-04-01 | 分类于 pat乙级
字数统计: 543

给定一系列正整数,请按要求对数字进行分类,并输出以下 5 个数字:

  • A1 = 能被 5 整除的数字中所有偶数的和;
  • A2 = 将被 5 除后余 1 的数字按给出顺序进行交错求和,即计算 n1−n2+n3−n4⋯;
  • A3 = 被 5 除后余 2 的数字的个数;
  • A4 = 被 5 除后余 3 的数字的平均数,精确到小数点后 1 位;
  • A5 = 被 5 除后余 4 的数字中最大数字。
阅读全文 »

PAT乙级 1046.划拳 (15 分)

发表于 2019-03-31 | 更新于 2019-03-31 | 分类于 pat乙级
字数统计: 477

划拳是古老中国酒文化的一个有趣的组成部分。酒桌上两人划拳的方法为:每人口中喊出一个数字,同时用手比划出一个数字。如果谁比划出的数字正好等于两人喊出的数字之和,谁就赢了,输家罚一杯酒。两人同赢或两人同输则继续下一轮,直到唯一的赢家出现。

阅读全文 »

PAT乙级 1026.程序运行时间 (15 分)

发表于 2019-03-28 | 更新于 2019-03-31 | 分类于 pat乙级
字数统计: 648

要获得一个 C 语言程序的运行时间,常用的方法是调用头文件 time.h,其中提供了 clock() 函数,可以捕捉从程序开始运行到 clock() 被调用时所耗费的时间。这个时间单位是 clock tick,即“时钟打点”。同时还有一个常数 CLK_TCK,给出了机器时钟每秒所走的时钟打点数。于是为了获得一个函数 f 的运行时间,我们只要在调用 f 之前先调用 clock(),获得一个时钟打点数 C1;在 f 执行完成后再调用 clock(),获得另一个时钟打点数 C2;两次获得的时钟打点数之差 (C2-C1) 就是 f 运行所消耗的时钟打点数,再除以常数 CLK_TCK,就得到了以秒为单位的运行时间。

这里不妨简单假设常数 CLK_TCK 为 100。现给定被测函数前后两次获得的时钟打点数,请你给出被测函数运行的时间。

阅读全文 »

PAT乙级 1016.部分A+B (15 分)

发表于 2019-03-28 | 更新于 2019-03-28 | 分类于 pat乙级
字数统计: 407

正整数 A 的“$D_A​$(为 1 位整数)部分”定义为由 A 中所有 $D_A​$ 组成的新整数 $P_A​$。例如:给定 A=3862767,$D_A​$=6,则 A的“6 部分”$P_A​$是66,因为 A 中有 2 个 6。

现给定 A、$D_A$、B、$D_A$,请编写程序计算 $P_A+P_B$。

阅读全文 »
1…414243…49
Gongshan He

Gongshan He

490 日志
62 分类
89 标签
GitHub 微博 知乎 Linkedin E-Mail
友情链接
  • 卢明冬的博客
  • lipixun
  • 柳婼 の blog
  • 心灵港
  • Liudeyin
© 2016 — 2023 Gongshan He
访问人数 总访问量 次