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 a1a2 and a3 (0 ≤ a1, a2, a3 ≤ 100).
The second line contains integers b1b2 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 <= n ? "YES" : "NO");
return 0;
}

Problem B:

B. Suffix Structures
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Bizon the Champion isn't just a bison. He also is a favorite of the "Bizons" team.

At a competition the "Bizons" got the following problem: "You are given two distinct words (strings of English letters), s and t.
You need to transform word s into word t".
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.

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.

Input

The first line contains a non-empty word s.
The second line contains a non-empty word t. Words s and t are
different. Each word consists only of lowercase English letters. Each word contains at most 100 letters.

Output

In the single line print the answer to the problem. Print "need tree" (without
the quotes) if word s cannot be transformed into word teven
with use of both suffix array and suffix automaton. Print "automaton" (without the quotes) if you need only the suffix automaton to solve the problem. Print
"array" (without the quotes) if you need only the suffix array to solve the problem. Print "both"
(without the quotes), if you need both data structures to solve the problem.

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.

Sample test(s)
input
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 < lenb; i++)
{
bool flag = true;
for(int j = k; j < lena; j++)
{
if(!vis[j] && strb[i] == stra[j])
{
vis[j] = 1;
k = j + 1;
flag = false;
break;
}
}
if(flag) return false;
}
return true;
} bool cmpb(string stra, string strb)
{
memset(vis, 0, sizeof(vis));
int lena = stra.length();
int lenb = strb.length();
for(int i = 0; i < lenb; i++)
{
bool flag = true;
for(int j = 0; j < lena; j++)
{
if(!vis[j] && strb[i] == stra[j])
{
vis[j] = 1;
flag = false;
break;
}
}
if(flag) return false;
}
return true;
} int main()
{
string stra, strb;
cin >> stra >> strb;
int lena = stra.length();
int lenb = strb.length();
if(cmpa(stra, strb))
{
cout << "automaton" << endl;
}
else if(cmpb(stra, strb))
{
if(lena == lenb)
{
cout << "array" << endl;
}
else if(lena > lenb)
{
cout << "both" << endl;
}
else
{
cout << "need tree" << endl;
}
}
else
{
cout << "need tree" << endl;
}
return 0;
}

Problem C:

C. Painting Fence
time limit per test

1 second

memory limit per test

512 megabytes

input

standard input

output

standard output

Bizon the Champion isn't just attentive, he also is very hardworking.

Bizon the Champion decided to paint his old fence his favorite color, orange. The fence is represented as n 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 i-th
plank has the width of 1 meter and the height of ai meters.

Bizon the Champion bought a brush in the shop, the brush's width is 1 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.

Input

The first line contains integer n (1 ≤ n ≤ 5000) —
the number of fence planks. The second line contains n space-separated integersa1, a2, ..., an (1 ≤ ai ≤ 109).

Output

Print a single integer — the minimum number of strokes needed to paint the whole fence.

Sample test(s)
input
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 < n; i++)
{
scanf("%d", &a[i]);
}
while(true)
{
int maxv = *max_element(a, a + n);
int maxh = -1, tmp = 0, first = 1;
int s = 0, t = 0, ts = 0, tt = 0;
for(int i = 0; i < n; i++)
{
if(a[i])
{
if(first)
{
ts = i;
first = 0;
}
tt = i;
tmp++;
if(i == n - 1)
{
if(tmp > 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 <= t; i++)
{
a[i]--;
}
}
ans++;
if(0 == *max_element(a, a + n)) break;
}
printf("%d\n", ans);
return 0;
}

代码:

#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 < minh)
{
for(int i = l; i <= r; i++)
a[i] = 0;
return ret;
}
else
{
for(int i = l; i <= r; i++)
a[i] -= minh;
int t = min_element(a + l, a + r + 1) - a;
tot += solve(l, t - 1) + solve(t + 1, r);
}
return min(ret, tot);
} int main()
{
scanf("%d", &n);
for(int i = 0; i < n; i++)
scanf("%d", &a[i]);
printf("%d\n", solve(0, n - 1));
return 0;
}

Problem D:

D. Multiplication Table
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Bizon the Champion isn't just charming, he also is very smart.

While some of us were learning the multiplication table, Bizon the Champion had fun in his own manner. Bizon the Champion painted ann × m multiplication
table, where the element on the intersection of the i-th row and j-th
column equals i·j (the rows and columns of the table are numbered
starting from 1). Then he was asked: what number in the table is the k-th largest number? Bizon the Champion always
answered correctly and immediately. Can you repeat his success?

Consider the given multiplication table. If you write out all n·m numbers
from the table in the non-decreasing order, then the k-th number you write out is called the k-th
largest number.

Input

The single line contains integers nm and k (1 ≤ n, m ≤ 5·105; 1 ≤ k ≤ n·m).

Output

Print the k-th largest number in a n × m multiplication
table.

Sample test(s)
input
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 < b) return a;
return b;
} int main()
{
int n, m;
long long k, ans, l, r, sum, mid;
scanf("%d%d%I64d", &n, &m, &k);
l = 1, r = 1ll * n * m;//r = (long long)n * m;
while(l <= r)
{
mid = (l + r) >> 1;
sum = 0;
for(int i = 1; i <= n; i++)
sum += min((mid - 1) / i, m);
if(sum < k)
l = mid + 1, ans = mid;
else
r = mid - 1;
}
printf("%I64d\n", ans);
return 0;
}

Codeforces Round #256 (Div. 2) 题解的更多相关文章

  1. Codeforces Round #182 (Div. 1)题解【ABCD】

    Codeforces Round #182 (Div. 1)题解 A题:Yaroslav and Sequence1 题意: 给你\(2*n+1\)个元素,你每次可以进行无数种操作,每次操作必须选择其 ...

  2. Codeforces Round #608 (Div. 2) 题解

    目录 Codeforces Round #608 (Div. 2) 题解 前言 A. Suits 题意 做法 程序 B. Blocks 题意 做法 程序 C. Shawarma Tent 题意 做法 ...

  3. Codeforces Round #525 (Div. 2)题解

    Codeforces Round #525 (Div. 2)题解 题解 CF1088A [Ehab and another construction problem] 依据题意枚举即可 # inclu ...

  4. Codeforces Round #528 (Div. 2)题解

    Codeforces Round #528 (Div. 2)题解 A. Right-Left Cipher 很明显这道题按题意逆序解码即可 Code: # include <bits/stdc+ ...

  5. Codeforces Round #466 (Div. 2) 题解940A 940B 940C 940D 940E 940F

    Codeforces Round #466 (Div. 2) 题解 A.Points on the line 题目大意: 给你一个数列,定义数列的权值为最大值减去最小值,问最少删除几个数,使得数列的权 ...

  6. Codeforces Round #677 (Div. 3) 题解

    Codeforces Round #677 (Div. 3) 题解 A. Boring Apartments 题目 题解 简单签到题,直接数,小于这个数的\(+10\). 代码 #include &l ...

  7. Codeforces Round #665 (Div. 2) 题解

    Codeforces Round #665 (Div. 2) 题解 写得有点晚了,估计都官方题解看完切掉了,没人看我的了qaq. 目录 Codeforces Round #665 (Div. 2) 题 ...

  8. Codeforces Round #160 (Div. 1) 题解【ABCD】

    Codeforces Round #160 (Div. 1) A - Maxim and Discounts 题意 给你n个折扣,m个物品,每个折扣都可以使用无限次,每次你使用第i个折扣的时候,你必须 ...

  9. Codeforces Round #383 (Div. 2) 题解【ABCDE】

    Codeforces Round #383 (Div. 2) A. Arpa's hard exam and Mehrdad's naive cheat 题意 求1378^n mod 10 题解 直接 ...

随机推荐

  1. HDU2191:悼念512汶川大地震遇难同胞——珍惜现在,感恩生活(多重背包)

    Problem Description 急!灾区的食物依然短缺! 为了挽救灾区同胞的生命,心系灾区同胞的你准备自己采购一些粮食支援灾区,现在假设你一共有资金n元,而市场有m种大米,每种大米都是袋装产品 ...

  2. UVA 10905 Children's Game 孩子的游戏 贪心

    题意:给出N个数,要求把它们拼凑起来,让得到的数值是最大的. 只要分别比较两个数放前与放后的值的大小,排序后输出就可以了. 比如123和56,就比较12356和56123的大小就行了. 写一个比较函数 ...

  3. 举例android项目中的string.xml出现这个The character reference must end with the ';' delimiter.错误提示的原因及解决办法

    今天在一个android项目中的string.xml中写这样一个字符串时出现了下面这个错误提示: The reference to entity "说明" must end wit ...

  4. 演练5-4:Contoso大学校园管理系统4

    在之前的教程中,我们已经完成了学校的数据模型.现在我们将读取和显示相关数据,请理解EF加载导航属性的方式. 一.Lazy.Eager.Explicit数据加载 使用EF为实体中的导航属性加载相关数据, ...

  5. 判断程序是否在VMWare内运行

    现在有许多用户都喜欢用虚拟机来测试他们的软件,以避免对真实机器环境造成损害.但是在虚拟机中,有些功能是受限,甚至不可能完成的,因此,需要在程序中判断虚拟机的环境,如果程序在虚拟机内运行,则就要把虚拟机 ...

  6. 青云B轮获2000万美元VC的背后逻辑:用技术超越巨头

    http://www.lagou.com/gongsi/31164.html http://capital.chinaventure.com.cn/11/7/1389263145.shtml

  7. 分享非常有用的Java程序 (关键代码)(五)---把 Array 转换成 Map

    原文:分享非常有用的Java程序 (关键代码)(五)---把 Array 转换成 Map import java.util.Map; import org.apache.commons.lang.Ar ...

  8. PHP - 判断php是否对表单数据内的特殊字符自动转义

    get_magic_quotes_gpc 有两个返回值: 0:在php.ini文件中已经关闭自动转移. 1:在php.ini文件中已经开启自动转移. 由此函数进行判断表单是否转移: /** * * m ...

  9. Ch05 视图模型

    5.1  什么是视图模型 5.1.1  在线商店示例 5.1.2  建立视图模型 5.1.3  交付表现模型 5.1.4  ViewData.Model 5.2  表现用户输入 5.2.1  设计(输 ...

  10. WM_PAINT消息在窗口重绘的时候产生,那什么时候窗口会重绘(异步工作方式效率高、灵活性强,还有UpdateWindow和RedrawWindow帮忙)

    Q:wm_paint消息在窗口重绘的时候产生,那什么时候窗口会重绘?? A: 严格地说,只有当收到WM_PAINT消息后窗口会重绘 但是引起这个消息的事件有很多, 比如:1.首次创建 2.移动 3.改 ...