博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Codeforces Round #466 (Div. 2)
阅读量:6565 次
发布时间:2019-06-24

本文共 8142 字,大约阅读时间需要 27 分钟。

A. Points on the line
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

We've got no test cases. A big olympiad is coming up. But the problemsetters' number one priority should be adding another problem to the round.

The diameter of a multiset of points on the line is the largest distance between two points from this set. For example, the diameter of the multiset {1, 3, 2, 1} is 2.

Diameter of multiset consisting of one point is 0.

You are given n points on the line. What is the minimum number of points you have to remove, so that the diameter of the multiset of the remaining points will not exceed d?

Input

The first line contains two integers n and d (1 ≤ n ≤ 100, 0 ≤ d ≤ 100) — the amount of points and the maximum allowed diameter respectively.

The second line contains n space separated integers (1 ≤ xi ≤ 100) — the coordinates of the points.

Output

Output a single integer — the minimum number of points you have to remove.

Examples
input
Copy
3 1 2 1 4
output
1
input
Copy
3 0 7 7 7
output
0
input
Copy
6 3 1 3 4 6 9 10
output
3
Note

In the first test case the optimal strategy is to remove the point with coordinate 4. The remaining points will have coordinates 1 and 2, so the diameter will be equal to 2 - 1 = 1.

In the second test case the diameter is equal to 0, so its is unnecessary to remove any points.

In the third test case the optimal strategy is to remove points with coordinates 1, 9 and 10. The remaining points will have coordinates 3, 4and 6, so the diameter will be equal to 6 - 3 = 3.

你可以移动最少的点,这个区间差不大于d,直接模拟啊

#include 
using namespace std;#define ll long longconst int N=10005;int main(){ int a[105],d,n; cin>>n>>d; for(int i=0;i
>a[i]; sort(a,a+n); int ma=0; for(int i=0;i
B. Our Tanya is Crying Out Loud
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Right now she actually isn't. But she will be, if you don't solve this problem.

You are given integers nkA and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations:

  1. Subtract 1 from x. This operation costs you A coins.
  2. Divide x by k. Can be performed only if x is divisible by k. This operation costs you B coins.
What is the minimum amount of coins you have to pay to make 
x equal to 1?
Input

The first line contains a single integer n (1 ≤ n ≤ 2·109).

The second line contains a single integer k (1 ≤ k ≤ 2·109).

The third line contains a single integer A (1 ≤ A ≤ 2·109).

The fourth line contains a single integer B (1 ≤ B ≤ 2·109).

Output

Output a single integer — the minimum amount of coins you have to pay to make x equal to 1.

Examples
input
Copy
9 2 3 1
output
6
input
Copy
5 5 2 20
output
8
input
Copy
19 3 4 2
output
12
Note

In the first testcase, the optimal strategy is as follows:

  • Subtract 1 from x (9 → 8) paying 3 coins.
  • Divide x by 2 (8 → 4) paying 1 coin.
  • Divide x by 2 (4 → 2) paying 1 coin.
  • Divide x by 2 (2 → 1) paying 1 coin.

The total cost is 6 coins.

In the second test case the optimal strategy is to subtract 1 from x 4 times paying 8 coins in total.

 

 这个就是一个变换,直接递归就可以了。k>1的复杂度就相当于二分很快的

能被整除就看看怎么减少的多,不能就继续下去,不过既然/减少的多了,那么以后肯定还是-1,这是一个剪枝

#include 
using namespace std;typedef long long ll;int main(){ ll n,k,a,b,s=0; cin>>n>>k>>a>>b; if(k==1) cout<<(n-1)*a; else { while(n!=1) { if(n%k==0) s+=min((n-n/k)*a,b),n/=k; else if(n>k)s+=n%k*a,n-=n%k; else s+=(n-1)*a,n=1; } cout<

 

C. Phone Numbers
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

And where the are the phone numbers?

You are given a string s consisting of lowercase English letters and an integer k. Find the lexicographically smallest string t of length k, such that its set of letters is a subset of the set of letters of s and s is lexicographically smaller than t.

It's guaranteed that the answer exists.

Note that the set of letters is a set, not a multiset. For example, the set of letters of abadaba is {

a, b, d}.

String p is lexicographically smaller than string q, if p is a prefix of q, is not equal to q or there exists i, such that pi < qi and for all j < i it is satisfied that pj = qj. For example, abc is lexicographically smaller than abcd , abd is lexicographically smaller than abec, afa is notlexicographically smaller than ab and is not lexicographically smaller than a.

Input

The first line of input contains two space separated integers n and k (1 ≤ n, k ≤ 100 000) — the length of s and the required length of t.

The second line of input contains the string s consisting of n lowercase English letters.

Output

Output the string t conforming to the requirements above.

It's guaranteed that the answer exists.

Examples
input
Copy
3 3 abc
output
aca
input
Copy
3 2 abc
output
ac
input
Copy
3 3 ayy
output
yaa
input
Copy
2 3 ba
output
baa
Note

In the first example the list of strings t of length 3, such that the set of letters of t is a subset of letters of s is as follows: aaa, aab, aac, aba, abb, abc, aca, acb, .... Among them, those are lexicographically greater than abc: aca, acb, .... Out of those the lexicographically smallest is aca.

 

 这就是一个贪心的题,可以理解为找一个长度为k的26进制数大于当前值且数字为所给的字符

得到r直接sort unique吧,当时有点傻

#include 
using namespace std;typedef long long ll;int main(){ int n,k; string s; cin>>n>>k>>s; if(k>n) { char c='z'; for(int i=0; s[i]; i++)c=min(c,s[i]); for(int i=0; i
S; for(int i=0; s[i]; i++)S.insert(s[i]); for(auto X:S)r+=X; sort(r.begin(),r.end()); for(int i=k-1; i>=0; i--) { if(t[i]==*r.rbegin())t[i]=r[0]; else { t[i]=*upper_bound(r.begin(),r.end(),t[i]); break; } } cout<
D. Alena And The Heater
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

"We've tried solitary confinement, waterboarding and listening to Just In Beaver, to no avail. We need something extreme."

"Little Alena got an array as a birthday present..."

The array b of length n is obtained from the array a of length n and two integers l and r (l ≤ r) using the following procedure:

b1 = b2 = b3 = b4 = 0.

For all 5 ≤ i ≤ n:

  • bi = 0 if ai, ai - 1, ai - 2, ai - 3, ai - 4 > r and bi - 1 = bi - 2 = bi - 3 = bi - 4 = 1
  • bi = 1 if ai, ai - 1, ai - 2, ai - 3, ai - 4 < l and bi - 1 = bi - 2 = bi - 3 = bi - 4 = 0
  • bi = bi - 1 otherwise

You are given arrays a and b' of the same length. Find two integers l and r (l ≤ r), such that applying the algorithm described above will yield an array b equal to b'.

It's guaranteed that the answer exists.

Input

The first line of input contains a single integer n (5 ≤ n ≤ 105) — the length of a and b'.

The second line of input contains n space separated integers a1, ..., an ( - 109 ≤ ai ≤ 109) — the elements of a.

The third line of input contains a string of n characters, consisting of 0 and 1 — the elements of b'. Note that they are not separated by spaces.

Output

Output two integers l and r ( - 109 ≤ l ≤ r ≤ 109), conforming to the requirements described above.

If there are multiple solutions, output any of them.

It's guaranteed that the answer exists.

Examples
input
Copy
5 1 2 3 4 5 00001
output
6 15
input
Copy
10 -10 -9 -8 -7 -6 6 7 8 9 10 0000111110
output
-5 5
Note

In the first test case any pair of l and r pair is valid, if 6 ≤ l ≤ r ≤ 109, in that case b5 = 1, because a1, ..., a5 < l.

D大力模拟就可以了啊

#include
using namespace std;const int N=1e5+5,MD=1e9;int a[N];string s;int main(){ int n; cin>>n; for(int i=0; i
>a[i]; cin>>s; int l1=-MD,l2=MD,r1=-MD,r2=MD; for(int i=4; i

 

转载于:https://www.cnblogs.com/BobHuang/p/8468046.html

你可能感兴趣的文章
JavaScript学习笔记(二)
查看>>
C++中this的用法
查看>>
昨天看了一个大神的fix类,清晰了然
查看>>
剑指Offer:连续子数组的最大和
查看>>
LeetCode 117 Populating Next Right Pointers in Each Node II
查看>>
Russian Doll Envelopes
查看>>
深入理解javascript原型和闭包系列
查看>>
第1个实验:用汇编语言点亮一盏LED
查看>>
1 Maven简介
查看>>
mongodb的学习-5-概念解析
查看>>
go标准库的学习-database/sql/driver
查看>>
SDOI2013 保护出题人
查看>>
@RestController注解下返回到jsp视图页面
查看>>
CCF NOI1118 序列第K小
查看>>
【BZOJ2752】【Luogu P2221】 [HAOI2012]高速公路
查看>>
HDU1282 回文数猜想
查看>>
HDU1563 HDU2095 Find your present!
查看>>
UVALive5910 UVA1641 POJ4022 ASCII Area【趣味程序+输入输出】
查看>>
Python-定时爬取指定城市天气(二)-邮件提醒
查看>>
01- APP移动端测试怎么测试?APP测试方法大全。
查看>>