中石油补题题板

目录

2021-5-14

问题 K: 立方

问题 L: 排队

2021-5-16

问题 M: 一箭多雕

 问题 L: 鸭子唱歌

 问题 E: Memory Overflow


2021-5-14

问题 K: 立方

今年乐乐开始学编程了,上几天刚刚解决了一个平方数的问题,问题是这样的:随便告诉你一个不超过 1 个亿的正整数,请你算出不超过该数的所有立方数的个数。 
但是,如果这个超过 1 亿,是一个 18 位正整数,或 28 位的正整数呢? 
乐乐不会算,你会吗? 

输入

只有一行且只有一个正整数:n

输出

只有一行且只有一个正整数:不超过 n 的平方数个数

样例输入 Copy

100

样例输出 Copy

4

提示

1*1*1 = 1        2*2*2 = 8 
3*3*3 = 27       4*4*4 = 64 
5*5*5 = 125   但是  125  >  100 

对于 30%的数据,  1 <= n <= 10^8 
对于 70%的数据,  1 <= n <= 10^18  
对于 100%的数据, 1 <= n <= 10^28  

问题 L: 排队

乐乐的 n 位朋友都拥有唯一的一个编号,编号分别为 1 至 n。某天按到达的时间顺序又给了一个顺序号,此时发现顺序号与多数的朋友编号不一致。乐乐想:如果俩俩交换顺序号,使得每位朋友的编号与顺序号相同,则最少需要交换几次? 

输入

包含二行: 
第一行只有一个正整数:n,表示乐乐朋友的人数 
第二行共有 n 个正整数,分别表示按顺序到达的朋友编号 

输出

只有一行且只有一个正整数:最少的交换次数 

样例输入 Copy

5  
4 2 1 5 3

样例输出 Copy

3

提示

对于 30%的数据,  1 <= n <= 100 
对于 80%的数据,  1 <= n <= 10 000 
对于 100%的数据, 1 <= n <= 100 000 

2021-5-16

问题 M: 一箭多雕

小明喜欢武侠小说,在武侠世界里,他不但练就了一箭双雕的能力,还可以一箭多雕。
现在所有雕在一条直线上从左到右排列,但是他们的高度不同。而小明想要把他们都射下来。小明使用的是一种特殊的弓箭,他可以将弓箭射到任意一个高度为H的雕,当射中一个高度为H的雕后,弓箭的高度会下降到H-1,再从左到右飞行,直到射到高度为H-1的大雕,再降低1的高度,直到飞出大雕的队列。
由于弓箭数量有限,小明想要知道,最少用多少的弓箭,就可以射下所有的大雕。

输入

第一行一个整数,n表示直线上的大雕数量。
第二行n个整数,表示从左到右每个大雕的高度。

输出

输出一个整数,表示最少用的弓箭数量。

样例输入 Copy

【样例1】
5
2 1 5 4 3
【样例2】
5
1 2 3 4 5
【样例3】
5
4 5 2 1 4

样例输出 Copy

【样例1】
2
【样例2】
5
【样例3】
3

提示

样例1解释
第一箭射向第一个大雕,射中后高度下降到1,会射中第二只大雕。
第二箭射向第三个大雕,依次射中高度为5,4,3的三只大雕。
样例2解释
5只大雕,分别使用1个弓箭。
样例3解释
第一箭射向第一个大雕,射中后高度下降到3。
第二箭射向第二个大雕,射下高度为5和4的大雕。
第三箭射向第三个大雕,射下高度为2和1的大雕。

【数据范围】
30%的数据,n<=5000, 大雕的高度<=10000
70%的数据,n<=1000000, 大雕的高度<=1000000
100%的数据,n<=1000000, 大雕的高度<=1000000000。

 问题 L: 鸭子唱歌

小明的楼下出现了许多鸭子,一开始只有一只鸭子在唱歌,“quack……quack……quack……”,小明觉得还挺好听的。紧接着,所有鸭子都一起唱了起来。小明开始厌烦了,他想要知道到底有多少只鸭子在他家楼下。
由于鸭子们边唱边跳,小明数着数着就数不清楚了。因此他想到了一个办法,把鸭子的声音录下来,用计算机来进行分析。一只鸭子发出的声音,只能是“quack”唱完整的一遍或者连续多遍,但是不同鸭子的声音会叠加,同一个微小的时刻就只有1只鸭子发出一个声音。例如:“ququaackck”就是由两只鸭子的声音叠加而成的,第一只是“qu___ack”,第二只是“__qua___ck”;又例如,“quackquack”这段声音,可能是1只鸭子,也可能是2只鸭子发出的。如果小明获取的声音是类似“quakc”不是由“quack”重复构成,或者只是其中一部分,这样的声音就是不规则,无效的。
现在,小明记录下了一段时间内鸭子的声音,问,这段声音中最少包含多少只鸭子?

输入

输入只有一行,一个字符串表示鸭子的声音。字符串中只包含“q”,“u”,“a”,“c”,“k”这5种小写字母。

输出

输出最少包含鸭子数量。若小明的声音录制无效,输出-1。

样例输入 Copy

【样例1】
quqacukqauackck
【样例2】
quackquakc
【样例3】
qqqqqqqqqquuuuuuuuuuaaaaaaaaaacccccccccckkkkkkkkkk

样例输出 Copy

【样例1】
2
【样例2】
-1
【样例3】
10

提示

样例1解释
鸭子1:qu_ac_kq_uack__
鸭子2:__q__u__a____ck
声音最少由2只鸭子构成,第一只鸭子唱了2遍,第二只鸭子唱了一遍。

样例2解释
不规则序列,不能由“quack”构成


【数据范围】
30%的数据,鸭子的声音长度不超过200
70%的数据,鸭子的声音长度不超过1000
100%的数据,鸭子的声音长度不超过2500

 问题 E: Memory Overflow

 

The Great Sultan Mahbub is having some serious issues with his memory. His busy days filled with great works and surrounded by even greater people have brought him to a situation where he has become quite forgetful. For example, he often forgets trivial things like the size of his suit, his weight,small grammatical issues related to gender & number, the address of his in-laws house, how to ride a cycle, deadlines, the day of the week, the name of the guy who forgot his wedding day and even the date of his own wedding (thus spending the day writing alternate solutions to ICPC problems). But when his father-in-law captured him to his in-laws house and he failed to recognize his mother-in-law it became a fiasco. And after some rather presumable events following that debacle, the detail of which does not seem really safe to mention, he decided that the matter has become pressing enough for his attention. His physician is startled by this weird problem and decides to collect statistical data to begin with.
During the examination period consisting n consecutive days, the Sultan meets a single person everyday. He only recognizes the person if he has met him in the last k days (excluding today of course). You need to count the number of days (among these n days) he manages to recognize the people he meets. You can assume that before these n consecutive days he did not meet any person.

输入

The input begins with a number t (1 ≤ t ≤ 100), the number of test cases. Each of the following lines contains a case. A case begins with n (1 ≤ n ≤ 500) & k (1 ≤ k ≤ 500). A list of n names follows. All
names consist of a single uppercase letter and names are unique. They are given in the order of which Sultan meets them during the investigation. There won’t be any invalid character or space between
any two names.

输出

For each test case produce a line of the form ‘Case X: Y ’. X is the serial number of the test case while Y is the number of people Sultan recognizes.
Illustration of Third sample:
Day 1: Sultan remembers nobody, meets ’M’. Does not recognize.
Day 2: Remembers only ’M’ but meets ’A’. Does not recognize again.
Day 3: Now remembers ’M’ & ’A’. Meets ’H’. Recognition count remains 0.
Day 4: Forgets ’M’, remembers ’A’ & ’H’. Meets ’B’. Still nothing happens.
Day 5: Forgets ’A’, remembers ’H’ & ’B’. Meets ’U’. No luck yet.
Day 6: Forgets ’H’, remembers ’B’ & ’U’. Meets ’B’ again and recognizes this time making the recognition count 1.

样例输入 Copy

3
6 2 SULTAN
6 1 MAHBUB
6 2 MAHBUB

样例输出 Copy

Case 1: 0
Case 2: 0
Case 3: 1
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值