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

?昨晚的沒來得及打,最近錯過好幾場CF了,這場應該不算太難

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).

這個A可能比B還要難一點,給你一個序列,滿足左側嚴格遞增,中間相等,右側嚴格遞減,左右也可以為空,你判定下

#include <bits/stdc++.h>
using namespace std;
int main() {int n;int a[105];cin>>n;for(int i=1; i<=n; i++)cin>>a[i];int f1=1;a[n+1]=a[0]=1<<30;int f=2;while(a[f]>a[f-1]) f++;while(a[f]==a[f-1]) f++;while(a[f]<a[f-1]) f++;if(f<=n) cout<<"NO"<<endl;else cout<<"YES"<<endl;return 0;
}
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

?這個B比較簡單,兩個鍵盤順序不一樣,按同樣的鍵位在B上顯示什么,注意大小寫轉換還有數字

#include <bits/stdc++.h>
using namespace std;
int main() {map<char,char>mp;string s1,s2,c;cin>>s1>>s2>>c;for(int i=0;s1[i];i++)mp[s1[i]]=s2[i];for(int i=0;c[i];i++){char s;if(c[i]>='0'&&c[i]<='9')s=c[i];else if(c[i]>='a'&&c[i]<='z')s=mp[c[i]];else s=mp[c[i]+32]-32;cout<<s;}return 0;
}

?

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個評委的得分,原始分數有多少種可能

關鍵就是我在枚舉分數的過程中,怎么知道這個是可以的,我選擇前綴和然后查找

#include <bits/stdc++.h>
using namespace std;
int b[2010];
set<int>s;
int main() {int k,n,p=0;cin>>n>>k;for(int i=1; i<=n; i++) {int q;cin>>q;p+=q;s.insert(p);}for(int i=1; i<=k; i++) {cin>>b[i];}sort(b+1,b+k+1);int ans=0;for(auto &node:s) {int f=1;for(int j=1; j<=k; j++) {if(!s.count(node-b[1]+b[j])) {f=0;break;}}if(f)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?n,?k?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.

?

這個其實就是dp啊

先將排序,假設第i個人拿到的鑰匙是第k[i]個,那么顯然k[i]<k[i+1]。dp[i][j]表示第i個人拿第j個鑰匙,前i個人走的最大距離的最小值
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e3+10;
int a[N],b[N],d[N][N];
int main()
{int n,k,p;cin>>n>>k>>p;for(int i=0;i<n;i++)scanf("%d",a+i);for(int i=0;i<k;i++)scanf("%d",b+i);sort(a,a+n);sort(b,b+k);d[0][0]=abs(a[0]-b[0])+abs(b[0]-p);for(int i=1;i<=k-n;i++)d[0][i]=min(d[0][i-1],abs(a[0]-b[i])+abs(b[i]-p));for(int i=1;i<n;i++){d[i][i-1]=2e9+10;for(int j=i;j<=k-n+i;j++)d[i][j]=min(d[i][j-1],max(d[i-1][j-1],abs(a[i]-b[j])+abs(b[j]-p)));}cout<<d[n-1][k-1];return 0;
}

?

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.

E是個線段樹維護區間最小值,可是我一臉懵bi

?

?

?

?

轉載于:https://www.cnblogs.com/BobHuang/p/7173079.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/394918.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/394918.shtml
英文地址,請注明出處:http://en.pswp.cn/news/394918.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

python能print中文嗎_python怎么print漢字

今天就為大家分享一篇python中使用print輸出中文的方法&#xff0c;具有很好的參考價值&#xff0c;希望對大家有所幫助。看Python簡明教程&#xff0c;學習使用print打印字符串&#xff0c;試了下打印中文&#xff0c;不行。&#xff08;推薦學習&#xff1a;Python視頻教程&a…

ajax的一些相關

1、AJAX Asynchronous&#xff08;異步的&#xff09; JavaScript and XML AJAX是能不刷新整個網頁的前提下&#xff0c;更新內容。通過少量的數據交換&#xff0c;達成局部頁面刷新的效果。 而form表單提交經常是刷新整個頁面&#xff0c;很繁瑣 2、AJAX是基于現有的Internet…

select ...as_一起使用.select .map和.reduce方法可充分利用Ruby

select ...asby Declan Meehan由Declan Meehan 一起使用.select .map和.reduce方法可充分利用Ruby (Get the most out of Ruby by using the .select .map and .reduce methods together) You should absolutely never ever repeat yourself when writing code. In other word…

一些書單

僅對近來的學習做些回顧吧 學習永無止境--> 2015年已完成書單&#xff1a; 文學&#xff1a; 硅谷之火浪潮之巔天才在左瘋子在右從0到1生命咖啡館黑客與畫家奇思妙想&#xff1a;15位計算機天才及其重大發現喬布斯傳平凡的世界&#xff08;三部全&#xff09;一只iphone的全…

oracle 11gogg,【OGG】Oracle GoldenGate 11g (二) GoldenGate 11g 單向同步配置 上

Oracle GoldenGate 11g (二)GoldenGate 11g 單向同步配置 上ItemSource SystemTarget SystemPlatformRHEL6.4 - 64bitRHEL6.4 - 64bitHostnamerhel64.oracle.comora11g.oracle.comDatabaseOracle 11.2.0.3Oracle 11.2.0.3Character SetAL32UTF8AL32UTF8ORACLE_SIDPRODEMREPList…

今天聽說了一個壓縮解壓整型的方式-group-varint

group varint https://github.com/facebook/folly/blob/master/folly/docs/GroupVarint.md 這個是facebook的實現 https://www.slideshare.net/parallellabs/building-software-systems-at-google-and-lessons-learned/48-Group_Varint_Encoding_Idea_encode

Centos7-卸載自帶的jdk 安裝jdk8

卸載JDK Centos7一般都會帶有自己的openjdk,我們一般都回用oracle的jdk,所以要卸載 步驟一&#xff1a;查詢系統是否以安裝jdk #rpm -qa|grep java 或 #rpm -qa|grep jdk 或 #rpm -qa|grep gcj 步驟二&#xff1a;卸載已安裝的jdk #rpm -e --nodeps java-1.8.0-openjdk…

小豬佩奇python_python畫個小豬佩奇

#!/usr/bin/python #-*- coding: utf-8 -*-import turtleast def nose(x,y):#鼻子 t.pu() t.goto(x,y) t.pd() t.seth(-30) t.begin_fill() a0.4 for i in range(120):if 0<i<30 or 60<i<90: aa0.08t.lt(3) #向左轉3度 t.fd(a) #向前走a的步長else: aa-0.08t.lt(3)…

javascript 符號_理解JavaScript中“ =”符號的直觀指南

javascript 符號by Kevin Kononenko凱文科諾年科(Kevin Kononenko) 理解JavaScript中“ ”符號的直觀指南 (A Visual Guide to Understanding the “” Sign in JavaScript) 實際上&#xff0c;對于第一次學習編碼的人來說&#xff0c;賦值運算符(或“ ”符號)實際上會產生誤導…

iOS開發UIScrollView的底層實現

起始 做開發也有一段時間了&#xff0c;經歷了第一次完成項目的激動&#xff0c;也經歷了天天調用系統的API的枯燥&#xff0c;于是就有了探索底層實現的想法。 關于scrollView的思考 在iOS開發中我們會大量用到scrollView這個控件&#xff0c;我們使用的tableView/collectionv…

oracle查看登錄時間黑屏,oracle 11g默認用戶名、密碼解鎖 以及安裝后重啟黑屏問題.doc...

oracle 11g默認用戶名、密碼解鎖 以及安裝后重啟黑屏問題.doc還剩3頁未讀&#xff0c;繼續閱讀下載文檔到電腦&#xff0c;馬上遠離加班熬夜&#xff01;親&#xff0c;喜歡就下載吧&#xff0c;價低環保&#xff01;內容要點&#xff1a;遇的同學&#xff0c;參考一下解決辦法…

第六十二節,html分組元素

html分組元素 學習要點&#xff1a; 1.分組元素總匯 2.分組元素解析 本章主要探討HTML5中分組元素的用法。所謂分組&#xff0c;就是用來組織相關內容的HTML5元素&#xff0c;清晰有效的進行歸類。 一&#xff0e;分組元素總匯 為了頁面的排版需要&#xff0c;HTML5提供了幾種語…

WebSocket 實戰--轉

原文地址&#xff1a;http://www.ibm.com/developerworks/cn/java/j-lo-WebSocket/ WebSocket 前世今生 眾所周知&#xff0c;Web 應用的交互過程通常是客戶端通過瀏覽器發出一個請求&#xff0c;服務器端接收請求后進行處理并返回結果給客戶端&#xff0c;客戶端瀏覽器將信息呈…

python圖形化編程更改內部參數_python-參數化-(3)(替換數據)

一.在讀取excel文件、其他數據來源會遇到一些無法轉換或者特殊標記的字符串等&#xff0c;不能直接使用。這時候需要對數據進行處理&#xff0c;替換為自己需要的數據進行下一步操作&#xff0c;如下&#xff1a; 替換 1.replace() str.replace(old,new[,max]) old -- 將被替換…

css grid布局_如何使用CSS Grid重新創建Medium的文章布局

css grid布局When people think of CSS Grid they normally envision image grid layouts and full web pages. However, CSS Grid is actually a superb technology for laying out articles as well, as it allows you to do things which previously was tricky to achieve.…

2017視頻監控行業應用趨勢與市場發展分析

安防行業的發展&#xff0c;從傳統單一的業務形態到業務多元化與國際化的轉變&#xff0c;是社會安全需求變化與視頻監控技術雙向驅動的結果。在新的行業生態體系下&#xff0c;傳統監控技術與新興技術的融合&#xff0c;跨行業的業務協同&#xff0c;以及以客戶為中心的產業形…

oracle 11.2.4聯機文檔,ORACLE 11G 聯機文檔partition_extended_name的一個錯誤

在看11G聯機文檔的PARTITION EXTENDED NAME限制的時候&#xff0c;測試發現與書上描述不符。Restrictions on Extended Names Currently, the use of partition-extended and subpartition-extended table names has the following restrictions:No remote tables: A partition…

mongodb 安裝、啟動

MongoDB 之 你得知道MongoDB是個什么鬼 MongoDB - 1 最近有太多的同學向我提起MongoDB,想要學習MongoDB,還不知道MongoDB到底是什么鬼,或者說,知道是數據庫,知道是文件型數據庫,但是不知道怎么來用 那么好,所謂千呼萬喚始出來,現在我就拉給你們看: 一.初識MongoDB 之 什么東西都…

python os path_python os.path模塊

os.path.abspath(path) #返回絕對路徑 os.path.basename(path) #返回文件名 os.path.commonprefix(list) #返回list(多個路徑)中&#xff0c;所有path共有的最長的路徑。 os.path.dirname(path) #返回文件路徑 os.path.exists(path) #路徑存在則返回True,路徑損壞返回False os.…

[轉載]PSCAD調用MATLAB/SIMULINK之接口元件設計

原文地址&#xff1a;PSCAD調用MATLAB/SIMULINK之接口元件設計作者&#xff1a;luckyhappier1)接口元件 接口元件包括Graphics&#xff0c;Parameters和Script。注意&#xff1a;變量要與DSDYN要一致&#xff08;PSCAD根據變量名區別變量&#xff09;。 2&#xff09;Circuit 定…