ホームページ >データベース >mysql チュートリアル >Codeforces Round #256 (Div. 2) 题解

Codeforces Round #256 (Div. 2) 题解

WBOY
WBOYオリジナル
2016-06-07 15:31:151069ブラウズ

Problem A: A. Rewards time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Bizon the Champion is called the Champion for a reason. Bizon the Champion has recently got a present — a n

Problem A:

A. Rewards

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Bizon the Champion is called the Champion for a reason.

Bizon the Champion has recently got a present — a new glass cupboard with n shelves and he decided to put all his presents there. All the presents can be divided into two types: medals and cups. Bizon the Champion has a1 first prize cups, a2 second prize cups and a3third prize cups. Besides, he has b1 first prize medals, b2 second prize medals and b3 third prize medals.

Naturally, the rewards in the cupboard must look good, that's why Bizon the Champion decided to follow the rules:

  • any shelf cannot contain both cups and medals at the same time;
  • no shelf can contain more than five cups;
  • no shelf can have more than ten medals.

Help Bizon the Champion find out if we can put all the rewards so that all the conditions are fulfilled.

Input

The first line contains integers a1, a2 and a3 (0?≤?a1,?a2,?a3?≤?100). The second line contains integers b1, b2 and b3 (0?≤?b1,?b2,?b3?≤?100). The third line contains integer n (1?≤?n?≤?100).

The numbers in the lines are separated by single spaces.

Output

Print "YES" (without the quotes) if all the rewards can be put on the shelves in the described manner. Otherwise, print "NO" (without the quotes).

Sample test(s)

input

1 1 1
1 1 1
4

output

YES

input

1 1 3
2 3 4
2

output

YES

input

1 0 0
1 0 0
1

output

NO
传送门:点击打开链接

解题思路:

求出放置所有奖杯和奖牌需要的最少架子的数目num,和n进行比较。

代码:

#include <cstdio>
#include <cmath>

int main()
{
    int a1, a2, a3, b1, b2, b3, n;
    scanf("%d%d%d%d%d%d%d", &a1, &a2, &a3, &b1, &b2, &b3, &n);
    int num = ceil((a1 + a2 + a3) * 1.0 / 5) + ceil((b1 + b2 + b3) * 1.0 / 10);
    printf("%s\n", num <br>

<h2>Problem B:</h2>

<p>
</p>
<p>
B. Suffix Structures</p>
<p>
</p>
<p>
time limit per test</p>
1 second
<p>
</p>
<p>
memory limit per test</p>
256 megabytes
<p>
</p>
<p>
input</p>
standard input
<p>
</p>
<p>
output</p>
standard output

<p>
</p>
<p>Bizon the Champion isn't just a bison. He also is a favorite of the "Bizons" team.</p>
<p>At a competition the "Bizons" got the following problem: "You are given two distinct words (strings of English letters),<span> </span><span><em>s</em></span><span> </span>and<span> </span><span><em>t</em></span>.
 You need to transform word<span> </span><span><em>s</em></span><span> </span>into word<span> </span><span><em>t</em></span>".
 The task looked simple to the guys because they know the suffix data structures well. Bizon Senior loves suffix automaton. By applying it once to a string, he can remove from this string any single character. Bizon Middle knows suffix array well. By applying
 it once to a string, he can swap any two characters of this string. The guys do not know anything about the suffix tree, but it can help them do much more.</p>
<p>Bizon the Champion wonders whether the "Bizons" can solve the problem. Perhaps, the solution do not require both data structures. Find out whether the guys can solve the problem
 and if they can, how do they do it? Can they solve it either only with use of suffix automaton or only with use of suffix array or they need both structures? Note that any structure may be used an unlimited number of times, the structures may be used in any
 order.</p>

<p>
</p>
<p>
Input</p>
<p>The first line contains a non-empty word<span> </span><span><em>s</em></span>.
 The second line contains a non-empty word<span> </span><span><em>t</em></span>. Words<span> </span><span><em>s</em></span><span> </span>and<span> </span><span><em>t</em></span><span> </span>are
 different. Each word consists only of lowercase English letters. Each word contains at most 100 letters.</p>

<p>
</p>
<p>
Output</p>
<p>In the single line print the answer to the problem. Print "<span>need tree</span>" (without
 the quotes) if word<span> </span><span><em>s</em></span><span> </span>cannot be transformed into word<span> </span><span><em>t</em></span>even
 with use of both suffix array and suffix automaton. Print "<span>automaton</span>" (without the quotes) if you need only the suffix automaton to solve the problem. Print
 "<span>array</span>" (without the quotes) if you need only the suffix array to solve the problem. Print "<span>both</span>"
 (without the quotes), if you need both data structures to solve the problem.</p>
<p>It's guaranteed that if you can solve the problem only with use of suffix array, then it is impossible to solve it only with use of suffix automaton. This is also true for suffix
 automaton.</p>

<p>
</p>
<p>
Sample test(s)</p>
<p>
</p>
<p>
</p>
<p>
input</p>
<pre class="brush:php;toolbar:false">automaton
tomat

output

automaton

input

array
arary

output

array

input

both
hot

output

both

input

need
tree

output

need tree
传送门:点击打开链接

解题思路:

如果串A中包含串B的所有字母,并且这些字母在串A和串B中排列顺序相同,输出“automaton”,否则,如果串A中包含串B的所有字母,我们在这种情况下在进行讨论,如果A和B的长度相等,输出“array”,如果A比B长,输出“both”,否则输出“need tree”。

代码:

#include <cstring>
#include <string>
#include <iostream>
using namespace std;

const int MAXN = 105;
int vis[MAXN];

bool cmpa(string stra, string strb)
{
    memset(vis, 0, sizeof(vis));
    int lena = stra.length();
    int lenb = strb.length();
    int k = 0;
    for(int i = 0; i > stra >> strb;
    int lena = stra.length();
    int lenb = strb.length();
    if(cmpa(stra, strb))
    {
        cout  lenb)
        {
            cout <br>

<h2>Problem C:</h2>

<p>
</p>
<p>
C. Painting Fence</p>
<p>
</p>
<p>
time limit per test</p>
1 second
<p>
</p>
<p>
memory limit per test</p>
512 megabytes
<p>
</p>
<p>
input</p>
standard input
<p>
</p>
<p>
output</p>
standard output

<p>
</p>
<p>Bizon the Champion isn't just attentive, he also is very hardworking.</p>
<p>Bizon the Champion decided to paint his old fence his favorite color, orange. The fence is represented as<span> </span><span><em>n</em></span><span> </span>vertical
 planks, put in a row. Adjacent planks have no gap between them. The planks are numbered from the left to the right starting from one, the<span> </span><span><em>i</em></span>-th
 plank has the width of<span> </span><span>1</span><span> </span>meter and the height of<span> </span><span><em>a</em><sub><em>i</em></sub></span><span> </span>meters.</p>
<p>Bizon the Champion bought a brush in the shop, the brush's width is<span> </span><span>1</span><span> </span>meter.
 He can make vertical and horizontal strokes with the brush. During a stroke the brush's full surface must touch the fence at all the time (see the samples for the better understanding). What minimum number of strokes should Bizon the Champion do to fully paint
 the fence? Note that you are allowed to paint the same area of the fence multiple times.</p>

<p>
</p>
<p>
Input</p>
<p>The first line contains integer<span> </span><span><em>n</em></span><span> </span><span>(1?≤?<em>n</em>?≤?5000)</span><span> </span>—
 the number of fence planks. The second line contains<span> </span><span><em>n</em></span><span> </span>space-separated integers<span><em>a</em><sub>1</sub>,?<em>a</em><sub>2</sub>,?...,?<em>a</em><sub><em>n</em></sub></span><span> </span><span>(1?≤?<em>a</em><sub><em>i</em></sub>?≤?10<sup>9</sup>)</span>.</p>

<p>
</p>
<p>
Output</p>
<p>Print a single integer — the minimum number of strokes needed to paint the whole fence.</p>

<p>
</p>
<p>
Sample test(s)</p>
<p>
</p>
<p>
</p>
<p>
input</p>
<pre class="brush:php;toolbar:false">5
2 2 1 2 1

output

3

input

2
2 2

output

2

input

1
5

output

1
传送门:点击打开链接

解题思路:

递归,贪心。粉刷篱笆,我们可以水平方向粉刷(只能刷到连续的部分),也可以竖直方向粉刷。按水平方向粉刷的话,刷的最少次数是min(a1,a2,a3,...,an-1);按竖直方向刷的话最少次数是这段连续篱笆的长度n。按上述方式刷完之后,必然会产生高度为0的篱笆(被全部刷过了),我们把这样的篱笆作为分割点,分成左半部分,和右半部分,两部分各是一段连续的篱笆,依次类推。

一个错误的思路:每次刷的时候找所有篱笆高度的最大值h,和最长的连续篱笆的长度len,刷的时候取max(h,len),最多刷n次,算法复杂度O(n2)。这样做的话,可能会使得篱笆变得分散,导致最终粉刷的次数变多。

反例:

3
1 10 1

错误的代码:

  #include <cstdio>
    #include <algorithm>
    using namespace std;

    const int MAXN = 5010;
    int n, ans = 0, a[MAXN];

    int main()
    {
        scanf("%d", &n);
        for(int i = 0; i  maxh)
                        {
                            maxh = tmp;
                            s = ts;
                            t = tt;
                        }
                    }
                }
                else
                {
                    if(tmp > maxh)
                    {
                        maxh = tmp;
                        s = ts;
                        t = tt;
                    }
                    tmp = 0;
                    first = 1;
                }
            }
            if(maxv > maxh)
            {
                *max_element(a, a + n) = 0;
            }
            else
            {
                for(int i = s; i <br>
<br>

<p>代码:</p>
<pre class="brush:php;toolbar:false">#include <cstdio>
#include <algorithm>
using namespace std;

const int MAXN = 5010;
int n, a[MAXN];

int solve(int l, int r)
{
    if(l > r) return 0;
    int minh = *min_element(a + l, a + r + 1);
    int ret = r - l + 1, tot = minh;
    if(ret <br>

<h2>Problem D:<br>
</h2>

<p>
</p>
<p>
D. Multiplication Table</p>
<p>
</p>
<p>
time limit per test</p>
1 second
<p>
</p>
<p>
memory limit per test</p>
256 megabytes
<p>
</p>
<p>
input</p>
standard input
<p>
</p>
<p>
output</p>
standard output

<p>
</p>
<p>Bizon the Champion isn't just charming, he also is very smart.</p>
<p>While some of us were learning the multiplication table, Bizon the Champion had fun in his own manner. Bizon the Champion painted an<span><em>n</em>?×?<em>m</em></span><span> </span>multiplication
 table, where the element on the interdiv of the<span> </span><span><em>i</em></span>-th row and<span> </span><span><em>j</em></span>-th
 column equals<span> </span><span><em>i</em>·<em>j</em></span><span> </span>(the rows and columns of the table are numbered
 starting from 1). Then he was asked: what number in the table is the<span> </span><span><em>k</em></span>-th largest number? Bizon the Champion always
 answered correctly and immediately. Can you repeat his success?</p>
<p>Consider the given multiplication table. If you write out all<span> </span><span><em>n</em>·<em>m</em></span><span> </span>numbers
 from the table in the non-decreasing order, then the<span> </span><span><em>k</em></span>-th number you write out is called the<span> </span><span><em>k</em></span>-th
 largest number.</p>

<p>
</p>
<p>
Input</p>
<p>The single line contains integers<span> </span><span><em>n</em></span>,<span> </span><span><em>m</em></span><span> </span>and<span> </span><span><em>k</em></span><span> </span><span>(1?≤?<em>n</em>,?<em>m</em>?≤?5·10<sup>5</sup>; 1?≤?<em>k</em>?≤?<em>n</em>·<em>m</em>)</span>.</p>

<p>
</p>
<p>
Output</p>
<p>Print the<span> </span><span><em>k</em></span>-th largest number in a<span> </span><span><em>n</em>?×?<em>m</em></span><span> </span>multiplication
 table.</p>

<p>
</p>
<p>
Sample test(s)</p>
<p>
</p>
<p>
</p>
<p>
input</p>
<pre class="brush:php;toolbar:false">2 2 2

output

2

input

2 3 4

output

3

input

1 10 5

output

5
传送门:点击打开链接

解题思路:

二分。需要求的是n*m乘法表中第k大的数,我们可以对这个数ans进行二分查找,区间是[1, n * m],对于每一个可能的ans,我们求出比他小的数的个数sum += min((mid - 1) / i, m);(i = 1,2,3,..,n),记录下小于k的最大的mid,即为我们所求的ans。

代码:

#include <cstdio>

inline long long min(long long a, int b)
{
    if(a > 1;
        sum = 0;
        for(int i = 1; i <br>
<br>



</cstdio>
声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。