Codeforces Round #299 Div2 解题报告

Codeforces Round #299 Div2 解题报告_第1张图片

  这场比赛并没有打现场,昨天晚上做了ABCD四道题,今天做掉了E题

  以前还没有过切完一场比赛的所有题呢~爽~

 

 


 

 

A. Tavas and Nafas
 

Today Tavas got his test result as an integer score and he wants to share it with his girlfriend, Nafas.

His phone operating system is Tavdroid, and its keyboard doesn't have any digits! He wants to share his score with Nafas via text, so he has no choice but to send this number using words.

He ate coffee mix without water again, so right now he's really messed up and can't think.

Your task is to help him by telling him what to type.

  最简单的模拟题..我还是喜欢定义三个常量来解决~跪跪手速帝(由于不是现场打所以慢悠悠地写

  心想如果是现场应该会紧张拼错好多个单词WA掉吧..QAQ

 

 

 


 

 

B. Tavas and SaDDas
 

Once again Tavas started eating coffee mix without water! Keione told him that it smells awful, but he didn't stop doing that. That's why Keione told his smart friend, SaDDas to punish him! SaDDas took Tavas' headphones and told him: "If you solve the following problem, I'll return it to you."

The problem is:

You are given a lucky number nLucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.

If we sort all lucky numbers in increasing order, what's the 1-based index of n?

Tavas is not as smart as SaDDas, so he asked you to do him a favor and solve this problem so he can have his headphones back.

 

  首先我们需要统计所有位数小于这个数的数字

  显然n为位lucky number有2^n个

  然后接下来对于每一位,我们统计:

  所有在这一位前的都等于原数,这一位小于原数的数

  所以只有当某位为7的时候我们才累加答案

  也就是这一位后面可以随意取

  最后答案+1输出即可

 

 


 

 C. Tavas and Karafs

  Karafs is some kind of vegetable in shape of an  1 × h rectangle. Tavaspolis people love Karafs and they use Karafs in almost any kind of food. Tavas, himself, is crazy about Karafs.
Codeforces Round #299 Div2 解题报告_第2张图片

Each Karafs has a positive integer height. Tavas has an infinite 1-based sequence of Karafses. The height of the i-th Karafs is si = A + (i - 1) × B.

For a given m, let's define an m-bite operation as decreasing the height of at most m distinct not eaten Karafses by 1. Karafs is considered as eaten when its height becomes zero.

Now SaDDas asks you n queries. In each query he gives you numbers lt and m and you should find the largest number r such that l ≤ r and sequence sl, sl + 1, ..., sr can be eaten by performing m-bite no more than t times or print -1 if there is no such number r.

 

 

  C题首先我们需要证明一个东西:

    对于一个区间[l,r]若(m*t>=sigma(s[i])(l<=i<=r))&(t>=max(s[i])(l<=i<=r))那么这个区间满足要求

  刚开始觉得这个结论并不正确...

  后来思考了一下,首先很显然,任意一个条件不满足肯定不可行,必要性得证

  接着,我们思考m<=(r-l+1)的时候,我们每次都可以在剩下的地方取m个

  由于m*t>=sigma(s[i]),所以显然是取得完的

  m>(r-l+1)的时候,我们每次都把所有l~r的数取一遍,由于t>=max(s[i]),所以显然也是取得完的

  充分性得证

  接下来简单的二分的就可以了

 

 


 

 

 

D. Tavas and Malekas
 

 

Tavas is a strange creature. Usually "zzz" comes out of people's mouth while sleeping, but string s of length n comes out from Tavas' mouth instead.

Today Tavas fell asleep in Malekas' place. While he was sleeping, Malekas did a little process on s. Malekas has a favorite string p. He determined all positions x1 < x2 < ... < xk where p matches s. More formally, for each xi (1 ≤ i ≤ k) he condition sxisxi + 1... sxi + |p| - 1 = pis fullfilled.

Then Malekas wrote down one of subsequences of x1, x2, ... xk (possibly, he didn't write anything) on a piece of paper. Here a sequence b is a subsequence of sequence a if and only if we can turn a into b by removing some of its elements (maybe no one of them or all).

After Tavas woke up, Malekas told him everything. He couldn't remember string s, but he knew that both p and s only contains lowercase English letters and also he had the subsequence he had written on that piece of paper.

Tavas wonders, what is the number of possible values of s? He asked SaDDas, but he wasn't smart enough to solve this. So, Tavas asked you to calculate this number for him.

Answer can be very large, so Tavas wants you to print the answer modulo 109 + 7.

 

 

  D题意很简单,就是给出给出一个字符串p,和它在字符串s中的一些匹配位置,以及s的位数

  判断是否存在这样的字符串,以及存在的话这样的字符串的个数

 

  首先,匹配位置是所有匹配位置的subsequence实际上是对问题的简化,我们考虑其他位置的时候

  就不需要再考虑是否又构成了一次匹配

 

  然后对于s的个数其实很简单...我们考虑匹配完全不重叠的情况,那些没有p覆盖的位置位数设为x

  则26^x就是答案

 

  然而实际上这道题的主要问题都在判断是否存在,简单的扩展KMP的应用

  //再去巩固一下KMP 扩展KMP 后缀数组这些东西各个数组的含义 以免下次套用错算法

 

 


 

 

E. Tavas and Pashmaks
 

Tavas is a cheerleader in the new sports competition named "Pashmaks".

Codeforces Round #299 Div2 解题报告_第3张图片

This competition consists of two part: swimming and then running. People will immediately start running R meters after they finished swimming exactly S meters. A winner is a such person that nobody else finishes running before him/her (there may be more than one winner).

Before the match starts, Tavas knows that there are n competitors registered for the match. Also, he knows that i-th person's swimming speed is si meters per second and his/her running speed is ri meters per second. Unfortunately, he doesn't know the values of R and S, but he knows that they are real numbers greater than 0.

As a cheerleader, Tavas wants to know who to cheer up. So, he wants to know all people that might win. We consider a competitor might win if and only if there are some values of R and S such that with these values, (s)he will be a winner.

Tavas isn't really familiar with programming, so he asked you to help him.

  E题首先我们可以把每个人的两个数据(x,y)转化成(1/x,1/y)将新数设为(a,b)

  最后的答案s/x+r/y=sx+ry

  Codeforces Round #299 Div2 解题报告_第4张图片

  我们考虑1,3,2三个点,4是3号点作与x轴的平行线与线段12的交点

  首先,与合金问题相似,我们设1(x1,y1),2(x2,y2)

  4(ax1+bx2,ay1+by2),ans = s(ax1+bx2) + r(ay1+by2)

  = a(sx1+ry1)+b(sx2+ry2) (0

  不仅4号点的x,y坐标是1,2两点的混合,最后的ans也是x,y答案的混合

  那么也就是min(ans1,ans2)<=ans4<=max(ans1,ans2)

  然而3号点显然答案<4号点,所以3号点不可能成为winner

  于是转化成了凸包的问题

  然而需要注意几个问题

  1)加的点:我们需要加右上角左上角右下角各一点来维护凸包

        然而左上与右下不能直接等于边界的值,因为这样就不能去除掉边上的点

        然而也不能大于边界的值太多..因为可能会排除掉很多不应该排除的点

        所以最后赋一个边界的值-eps 卡卡精度应该就可以了(可是考试的时候怎么办啊TAT

  2)精度问题:判一判eps

  3)重点问题:显然做Graham算法是不能存在重点的

          于是我们添加的时候加一条if语句重点不再进

         最后累积答案的时候再处理一下即可

 

 


 

  还是非常喜欢CF的题,由于时间限制的关系不会出一些数据结构题

  平时多做做这样的题练练思维和手速真的很棒

  还有以后还是尽量打现场,会有不一样的感受

 

  20/.Apr.

  

  

 

  

  

 

转载于:https://www.cnblogs.com/mjy0724/p/4442209.html

你可能感兴趣的:(数据结构与算法)