http://codeforces.com/contest/831
A. Unimodal Array
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Array of integers is unimodal, if:

  • it is strictly increasing in the beginning;
  • after that it is constant;
  • after that it is strictly decreasing.

The first block (increasing) and the last block (decreasing) may be absent. It is allowed that both of this blocks are absent.

For example, the following three arrays are unimodal: [5, 7, 11, 11, 2, 1], [4, 4, 2], [7], but the following three are not unimodal:[5, 5, 6, 6, 1], [1, 2, 1, 2], [4, 5, 5, 6].

Write a program that checks if an array is unimodal.

Input

The first line contains integer n (1 ≤ n ≤ 100) — the number of elements in the array.

The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 1 000) — the elements of the array.

Output

Print "YES" if the given array is unimodal. Otherwise, print "NO".

You can output each letter in any case (upper or lower).

Examples
input
6
1 5 5 5 4 2
output
YES
input
5
10 20 30 20 10
output
YES
input
4
1 2 1 2
output
NO
input
7
3 3 3 3 3 3 3
output
YES
Note

In the first example the array is unimodal, because it is strictly increasing in the beginning (from position 1 to position 2, inclusively), that it is constant (from position 2 to position 4, inclusively) and then it is strictly decreasing (from position 4 to position 6, inclusively).

题意:给你一个序列是否是先严格递增有一个极大值然后递减;递增和递减部分可以没有;

题解:找到出数组的最大值,然后看是否符合条件。下面给出AC代码

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
#define LL long long
using namespace std;
const int maxn=1e2+;
int a[maxn],n;
int main()
{
scanf("%d ",&n); int maxl=,id=;
for(int i=;i<n;i++)
{
scanf("%d",&a[i]);
if(a[i]>maxl)
{
id=i;maxl=a[i];
}
}
bool flag=true,flag2=true;
if(a[]==a[]&&maxl>a[]||a[n-]==a[n-]&&maxl>a[n-])
{
cout<<"NO\n";
}
else
{
for(int i=;i<n-;i++)
{
if(a[i]<a[i+]&&flag2)
{
continue;
}
else if(a[i]==a[i+]&&flag2)
{
if(a[i]!=maxl)
{
flag=false;break;
}
continue;
}
else if(a[i]>a[i+]&&flag2)
{
if(a[i]!=maxl)
{
flag=false;break;
}
flag2=false;
}
if(!flag2&&a[i]>a[i+])
{
continue;
}
else if(!flag2&&a[i]==a[i+])
{
if(a[i]!=maxl)
{
flag=false;break;
}
continue;
}
else if(!flag2&&a[i]<a[i+])
{
flag=false;
//cout<<1<<endl;
break;
} }
if(flag)
{
cout<<"YES\n";
}
else
{
cout<<"NO\n";
}
} }
B. Keyboard Layouts
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

There are two popular keyboard layouts in Berland, they differ only in letters positions. All the other keys are the same. In Berland they use alphabet with 26 letters which coincides with English alphabet.

You are given two strings consisting of 26 distinct letters each: all keys of the first and the second layouts in the same order.

You are also given some text consisting of small and capital English letters and digits. It is known that it was typed in the first layout, but the writer intended to type it in the second layout. Print the text if the same keys were pressed in the second layout.

Since all keys but letters are the same in both layouts, the capitalization of the letters should remain the same, as well as all other characters.

Input

The first line contains a string of length 26 consisting of distinct lowercase English letters. This is the first layout.

The second line contains a string of length 26 consisting of distinct lowercase English letters. This is the second layout.

The third line contains a non-empty string s consisting of lowercase and uppercase English letters and digits. This is the text typed in the first layout. The length of s does not exceed 1000.

Output

Print the text if the same keys were pressed in the second layout.

Examples
input
qwertyuiopasdfghjklzxcvbnm
veamhjsgqocnrbfxdtwkylupzi
TwccpQZAvb2017
output
HelloVKCup2017
input
mnbvcxzlkjhgfdsapoiuytrewq
asdfghjklqwertyuiopzxcvbnm
7abaCABAABAcaba7
output
7uduGUDUUDUgudu7

题意:有两个键盘,不同位置对应不同字符,给出他们在相同位置的字符对应关系,求在第一块键盘打的一个字符串,在第二个键盘会打出什么。

题解:用map进行映射,然后注意大小写的转化就可以。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#define LL long long
using namespace std;
const int maxn=1e3+;
int n;
char a[],b[],c[maxn];
int main()
{
map<char, int> map1;
for(int i=;i<;i++)
{
scanf("%c",&a[i]);
map1.insert(map<char, int>::value_type(a[i], i));
}
getchar();
for(int i=;i<;i++)
{
scanf("%c",&b[i]);
}
/* for(int i=0;i<26;i++)
{
cout<<b[map1[a[i]]];
}
cout<<endl;*/
getchar();
scanf("%s",c);
n=strlen(c);
for(int i=;i<n;i++)
{
if(c[i]>='a'&&c[i]<='z')
{
cout<<b[map1[c[i]]];
}
else if(c[i]>='A'&&c[i]<='Z')
{
cout<<char(b[map1[c[i]-('A'-'a')]]+('A'-'a'));
}
else
{
cout<<c[i];
}
}
cout<<endl; }
C. Jury Marks
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Polycarp watched TV-show where k jury members one by one rated a participant by adding him a certain number of points (may be negative, i. e. points were subtracted). Initially the participant had some score, and each the marks were one by one added to his score. It is known that the i-th jury member gave ai points.

Polycarp does not remember how many points the participant had before this k marks were given, but he remembers that among the scores announced after each of the k judges rated the participant there were n (n ≤ k) values b1, b2, ..., bn (it is guaranteed that all values bj are distinct). It is possible that Polycarp remembers not all of the scores announced, i. e. n < k. Note that the initial score wasn't announced.

Your task is to determine the number of options for the score the participant could have before the judges rated the participant.

Input

The first line contains two integers k and n (1 ≤ n ≤ k ≤ 2 000) — the number of jury members and the number of scores Polycarp remembers.

The second line contains k integers a1, a2, ..., ak ( - 2 000 ≤ ai ≤ 2 000) — jury's marks in chronological order.

The third line contains n distinct integers b1, b2, ..., bn ( - 4 000 000 ≤ bj ≤ 4 000 000) — the values of points Polycarp remembers. Note that these values are not necessarily given in chronological order.

Output

Print the number of options for the score the participant could have before the judges rated the participant. If Polycarp messes something up and there is no options, print "0" (without quotes).

Examples
input
4 1
-5 5 0 20
10
output
3
input
2 2
-2000 -2000
3998000 4000000
output
1
Note

The answer for the first example is 3 because initially the participant could have  - 10, 10 or 15 points.

In the second example there is only one correct initial score equaling to 4 002 000.

题意:给出评委的打分顺序(n个按时间顺序),然后一个人记住了一些打分之后出现的分数(k个),让你找到初始分数可能的个数。

题解:说实话当时,比赛时看了半天也没看懂题意(我英语太菜^_^),,,,,

先输入数组a时预处理储存前缀和,用vis数组来标记他出现过,加+N是因为a[i]有可能是负数,然后是数组B,再把b,sort一下,

t=b[1]-a[i]假定t就为初始分数,用一个循环来寻找所有的a[i]是否出现K次如果是ans++;下面是代码
#include<iostream>
#include<cstdio>
#include<set>
#include<algorithm>
using namespace std;
const int maxn=2e3+;
const int N = ;
int n,k,ans=;
bool vis[];
int a[maxn],b[maxn];
set<int>s;
int main()
{
scanf("%d %d",&n,&k);
a[]=;
for(int i=;i<=n;i++)
{
scanf("%d",&a[i]);
a[i]+=a[i-];
vis[a[i]+N]=true;
}
for(int j=;j<=k;j++)
{
scanf("%d",&b[j]);
}
sort(b+,b+k+);
for(int i=;i<=n;i++)
{
int t=b[]-a[i];int count=;
if(s.count(t))continue;
s.insert(t);
for(int j=;j<=k;j++)
{
count+=vis[b[j]-t+N];
}
if(count==k)ans++;
}
cout<<ans<<endl; }
D. Office Keys
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

There are n people and k keys on a straight line. Every person wants to get to the office which is located on the line as well. To do that, he needs to reach some point with a key, take the key and then go to the office. Once a key is taken by somebody, it couldn't be taken by anybody else.

You are to determine the minimum time needed for all n people to get to the office with keys. Assume that people move a unit distance per 1 second. If two people reach a key at the same time, only one of them can take the key. A person can pass through a point with a key without taking it.

Input

The first line contains three integers nk and p (1 ≤ n ≤ 1 000, n ≤ k ≤ 2 000, 1 ≤ p ≤ 109) — the number of people, the number of keys and the office location.

The second line contains n distinct integers a1, a2, ..., an (1 ≤ ai ≤ 109) — positions in which people are located initially. The positions are given in arbitrary order.

The third line contains k distinct integers b1, b2, ..., bk (1 ≤ bj ≤ 109) — positions of the keys. The positions are given in arbitrary order.

Note that there can't be more than one person or more than one key in the same point. A person and a key can be located in the same point.

Output

Print the minimum time (in seconds) needed for all n to reach the office with keys.

Examples
input
2 4 50
20 100
60 10 40 80
output
50
input
1 2 10
11
15 7
output
7
Note

In the first example the person located at point 20 should take the key located at point 40 and go with it to the office located at point 50. He spends 30 seconds. The person located at point 100 can take the key located at point 80 and go to the office with it. He spends 50seconds. Thus, after 50 seconds everybody is in office with keys.

题意:一条线上有N个人K个钥匙,以及一扇门的位置P,给出人和钥匙的位置,求所有的人拿不同钥匙然后通过这扇门最短的时间(好不合理的逻辑--人可以先通过门到另一边拿钥匙在过门)无语中,,。

题解:贪心,n个人肯定是拿连续的n个钥匙才能最小然后枚举每次更新最小值;

#include<iostream>
#include<cstdio>
#include<set>
#include<algorithm>
#include<cmath>
using namespace std;
const int maxn=1e3+;
const int inf=0x3f3f3f3f3f;
const int N = ;
int n,k,p,ans=;
bool vis[];
int a[maxn],b[*maxn];
int main()
{
int l=,r=;
scanf("%d %d %d",&n,&k,&p);
for(int i=;i<n;i++)
{
scanf("%d",&a[i]);
}
sort(a,a+n);
for(int i=;i<k;i++)
{
scanf("%d",&b[i]);
}
sort(b,b+k);
int ans=inf*;
for(int j=;j<=k-n;j++)
{
int mt=;
for(int i=;i<n;i++)
{ mt=max(mt,abs(a[i]-b[j+i])+abs(p-b[j+i]));
}
ans=min(ans,mt);
}
//cout<<ans<<endl;
printf("%d\n",ans); }
E. Cards Sorting
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Vasily has a deck of cards consisting of n cards. There is an integer on each of the cards, this integer is between 1 and 100 000, inclusive. It is possible that some cards have the same integers on them.

Vasily decided to sort the cards. To do this, he repeatedly takes the top card from the deck, and if the number on it equals the minimum number written on the cards in the deck, then he places the card away. Otherwise, he puts it under the deck and takes the next card from the top, and so on. The process ends as soon as there are no cards in the deck. You can assume that Vasily always knows the minimum number written on some card in the remaining deck, but doesn't know where this card (or these cards) is.

You are to determine the total number of times Vasily takes the top card from the deck.

Input

The first line contains single integer n (1 ≤ n ≤ 100 000) — the number of cards in the deck.

The second line contains a sequence of n integers a1, a2, ..., an (1 ≤ ai ≤ 100 000), where ai is the number written on the i-th from top card in the deck.

Output

Print the total number of times Vasily takes the top card from the deck.

Examples
input
4
6 3 1 2
output
7
input
1
1000
output
1
input
7
3 3 3 3 3 3 3
output
7
Note

In the first example Vasily at first looks at the card with number 6 on it, puts it under the deck, then on the card with number 3, puts it under the deck, and then on the card with number 1. He places away the card with 1, because the number written on it is the minimum among the remaining cards. After that the cards from top to bottom are [2, 6, 3]. Then Vasily looks at the top card with number 2 and puts it away. After that the cards from top to bottom are [6, 3]. Then Vasily looks at card 6, puts it under the deck, then at card 3 and puts it away. Then there is only one card with number 6 on it, and Vasily looks at it and puts it away. Thus, in total Vasily looks at 7 cards.

题意:就是抽牌从最小开始抽出,如果不是最小放后面,继续抽,问抽完所有牌的的抽牌次数

题解:用线段数,0表示此牌已经抽出,1表示此牌还未抽出,这样抽牌次数的话可以用线段树快速求的,所以我在输入的时候先用结构体储存牌的位置和值,

然后每次抽出最小的牌,第一张是特判,然后每一张考虑与前一张的位置关系如果后一张在前一张的后面就只要求区间前一张到后一张位置的和,前一张在后面的话就求区间前一张到N,和后一张到1的(不理解的话可以画画图)。但这样还是不够得因为还有相同值的牌由于前的位置关系,会造另一种大小关系,比如说这组数据

5

12 2 2 12 1;

我们正常抽只会用十次,但用刚才的方法要用11次至于为什么,抽到最后是12 12 的时候其实后面那个是先输入的,所以会多抽一次(我在这wa了一年),所以在后面我们还得加一个优化,相同的直接抽。下面代码,我把错的那部分注释掉。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
using namespace std;
const int maxn=4e5+;
int tree[maxn],n;
struct node
{
int i,pos;
}a[(maxn>>)+];
void push(int rt)
{
tree[rt]=tree[rt<<]+tree[rt<<|];
return;
}
bool cmp(const node a,const node b)
{
if(a.i==b.i)
return a.pos<b.pos;
return a.i<b.i;
}
void built(int l,int r,int rt)
{
if(l==r)
{
tree[rt]=;
return ;
}
int mid=(l+r)>>;
built(l,mid,rt<<);
built(mid+,r,rt<<|);
push(rt);
return;
}
int query(int l,int r,int L,int R,int rt)
{
if(r<L||l>R)
{
return ;
}
else if(r<=R&&l>=L)
{
return tree[rt];
}
int mid=(r+l)>>;
return query(l,mid,L,R,rt<<)+query(mid+,r,L,R,rt<<|);
}
void update(int l,int r,int loc,int rt)
{
if(l==r)
{
tree[rt]=;
return;
}
int mid=(r+l)>>;
if(loc<=mid)
update(l,mid,loc,rt<<);
else
update(mid+,r,loc,rt<<|);
push(rt);
return;
}
int main()
{
scanf("%d",&n);
for(int i=;i<=n;i++)
{
scanf("%d",&a[i].i);
a[i].pos=i;
}
sort(a+,a+n+,cmp);
built(,n,);
//cout<<query(1,n,1,n,1)<<endl;
// int ans=0;
/* int index=0,now=1;
for(int i=1;i<=n;i++)
{
int last=i+1,mi=a[last].pos,mx=mi;
while(last<n&&a[last].i==a[last+1].i)
{
int p=a[++last].pos;
mx=p;
if(p<now)
{
mi=p;
}
}
if(i==1)
{
ans+=a[i].pos;
update(1,n,a[i].pos,1);
}
else
{
if(a[i-1].pos<a[i].pos)
{
ans+=query(1,n,a[i-1].pos,a[i].pos,1);
update(1,n,a[i].pos,1);
}
else
{
ans+=(query(1,n,a[i-1].pos,n,1)+query(1,n,1,a[i].pos,1));
update(1,n,a[i].pos,1);
}
}
}
printf("%d\n",ans);*/
long long ans=;
int index=,now=;
while(index<n){
int last=index+,mi=a[last].pos,mx=mi;
while(last<n&&a[last].i==a[last+].i)
{
int p=a[++last].pos;
mx=p;
if(p<now)
{
mi=p;
}
}
if(mi<now){
ans+=query(,n,now,n,)+query(,n,,mi,);
now =mi;
}
else
{
ans += query(,n,now,mx,) ;
now = mx;
}
while(++index<=last)
{
update(,n,a[index].pos,);
}
index--;
}
printf("%I64d\n",ans); }

Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals)的更多相关文章

  1. Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) Problem C (Codeforces 831C) - 暴力 - 二分法

    Polycarp watched TV-show where k jury members one by one rated a participant by adding him a certain ...

  2. Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals)A,B,C

    A:链接:http://codeforces.com/contest/831/problem/A 解题思路: 从前往后分别统计递增,相等,递减序列的长度,如果最后长度和原序列长度相等那么就输出yes: ...

  3. Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) Problem F (Codeforces 831F) - 数论 - 暴力

    题目传送门 传送门I 传送门II 传送门III 题目大意 求一个满足$d\sum_{i = 1}^{n} \left \lceil \frac{a_i}{d} \right \rceil - \sum ...

  4. Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) Problem D (Codeforces 831D) - 贪心 - 二分答案 - 动态规划

    There are n people and k keys on a straight line. Every person wants to get to the office which is l ...

  5. Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) Problem E (Codeforces 831E) - 线段树 - 树状数组

    Vasily has a deck of cards consisting of n cards. There is an integer on each of the cards, this int ...

  6. Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) Problem A - B

    Array of integers is unimodal, if: it is strictly increasing in the beginning; after that it is cons ...

  7. Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) A 水 B stl C stl D 暴力 E 树状数组

    A. Unimodal Array time limit per test 1 second memory limit per test 256 megabytes input standard in ...

  8. Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) - D

    题目链接:http://codeforces.com/contest/831/problem/D 题意:在一个一维坐标里,有n个人,k把钥匙(钥匙出现的位置不会重复并且对应位置只有一把钥匙),和一个终 ...

  9. Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) - C

    题目链接:http://codeforces.com/contest/831/problem/C 题意:给定k个评委,n个中间结果. 假设参赛者初始分数为x,按顺序累加这k个评委的给分后得到k个结果, ...

随机推荐

  1. 获取ip地址及城市信息

    大家好,今天给大家分享的是一个简单的知识获取登录用户的ip地址及城市信息,lz是一个小白,如果有哪些错误的地方  欢迎大家指出 东西很简单,直接上代码 [HttpPost] public string ...

  2. 多路复用(select、epoll)实现tcp服务

    -------------------------------多路复用的服务器(select)------------------------------- 网络通信被Unix系统抽象为文件的读写,通 ...

  3. zbrush曲面增加厚度

    把曲面增加厚度方便雕刻机雕刻. 可以使用zbrush中的边循环功能. 1.准备好需要增加厚度的曲面,把曲面的边缘调整好,尽量的变得平滑. 2.将模型导入到zbrush中,开启双面显示,以方便观察模型的 ...

  4. xcode模拟器不显示键盘解决方案

    当我们使用Xcode进行开发的时候,并不是所有的时候都需要将代码运行在iPhone,有时候模拟器就可以解决这些问题, 但是当你使用模拟器的时候会发现,在TextFiled中输入信息时,如果你是用模拟器 ...

  5. 深度神经网络在量化交易里的应用 之二 -- 用深度网络(LSTM)预测5日收盘价格

        距离上一篇文章,正好两个星期. 这边文章9月15日 16:30 开始写. 可能几个小时后就写完了.用一句粗俗的话说, "当你怀孕的时候,别人都知道你怀孕了, 但不知道你被日了多少回 ...

  6. PHP初入,简易网页整理(布局&特效的使用)

    html><html> <head> <meta charset="UTF-8"> <title></title> ...

  7. 201521123083《Java程序设计》第11周学习总结

    1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结多线程相关内容. 上周这张图没理解完,继续 2. 书面作业 本次PTA作业题集多线程 1互斥访问与同步访问完成题集4-4(互斥访问) ...

  8. Swing-布局管理器之FlowLayout(流式布局)-入门

    FlowLayout应该是Swing布局管理器学习中最简单.最基础的一个.所谓流式,就是内部控件像水流一样,从前到后按顺序水平排列,直到达到容器的宽度时跳转到第二行.既然是水平排列,那么就存在三种基本 ...

  9. 201521123002《Java程序设计》第7周学习总结

    1. 本周学习总结 以你喜欢的方式(思维导图或其他)归纳总结集合相关内容. 2. 书面作业 1.ArrayList代码分析 1.1 解释ArrayList的contains源代码 先查看源代码 con ...

  10. 201521123115《Java程序设计》第6周学习总结

    1. 本周学习总结 1.1 面向对象学习暂告一段落,请使用思维导图,以封装.继承.多态为核心概念画一张思维导图,对面向对象思想进行一个总结. 注1:关键词与内容不求多,但概念之间的联系要清晰,内容覆盖 ...