Codeforces Round #389 (Div. 2,) B C
考完复变之后沉迷联盟不能自拔...明天就开始抢救计组 ...
B 一个人装错了键帽 选择几个pair 把pair里面的键帽交换 并且每个键帽最多可以换一次 给出按键序列和输出序列 判断是否可以 如果可以输出pair
因为每个键帽最多可以换一次 所以如果错了 一定是一一对应的
于是设定一个表存每个键帽对应的实际字母
需要注意的是 ac cc 这种情况下是 -1 很多人wa在了test14
C 在一个格子图里给出一个路径 里面有UDLR四种移动方向 问 我在格子路径里面最少选几个点 可以让我沿着格子路径走 其实是在相邻的点与点之间走最短路
可以想到 如果一个图中同时出现了LR UD 肯定不是最短路
所以将移动方向视为1-n 初始自己在0处 每次二分查找出自己位置到最后的四种移动方式的最左的位置
可见 此时可移动到 min(max(L,R)-1,max(U,D)-1)
连续二分 直到走到n处
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<math.h>
#include<map>
#include<string>
#include<vector>
#include<queue>
#include<iostream>
using namespace std;
#define L long long
char s[200050];
int n ;
int su[200050];
int sd[200050];
int sr[200050];
int sl[200050];
int ef(int a[],int ll,int rr,int val){
int res = n + 1;
int l = ll ;
int r = rr ;
while(l <= r){
int mid = (l + r) / 2;
if(a[mid]>val){
res = mid ;
r = mid - 1;
}
else {
l = mid + 1;
}
}
return res ;
}
int main(){
scanf("%d",&n);
scanf("%s",s+1);
su[0] = sl[0] = sr[0] = sd[0] = 0;
for(int i=1;i<=n;i++){
su[i] = su[i-1];
sr[i] = sr[i-1];
sd[i] = sd[i-1];
sl[i] = sl[i-1];
if(s[i] =='U')su[i]++;
if(s[i] =='D')sd[i]++;
if(s[i] =='R')sr[i]++;
if(s[i] =='L')sl[i]++;
}
int w = 0;
int ans = 0;
while(w < n){
char c = s[w+1];
int uu = ef(su,w+1,n,su[w]);
int dd = ef(sd,w+1,n,sd[w]);
int rr = ef(sr,w+1,n,sr[w]);
int ll = ef(sl,w+1,n,sl[w]);
int ky1 = max(uu,dd)-1;
int ky2 = max(rr,ll)-1;
int res = min(ky1,ky2);
ans ++ ;
w = res ;
}
printf("%d\n",ans);
}
Codeforces Round #389 (Div. 2,) B C的更多相关文章
- Codeforces Round #389 Div.2 D. Santa Claus and a Palindrome
time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...
- Codeforces Round #389 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 3) C
Description Santa Claus has Robot which lives on the infinite grid and can move along its lines. He ...
- Codeforces Round #389 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 3) B
Description Santa Claus decided to disassemble his keyboard to clean it. After he returned all the k ...
- Codeforces Round #389 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 3) A
Description Santa Claus is the first who came to the Christmas Olympiad, and he is going to be the f ...
- Codeforces Round #389 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 3) D. Santa Claus and a Palindrome STL
D. Santa Claus and a Palindrome time limit per test 2 seconds memory limit per test 256 megabytes in ...
- Codeforces Round #389 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 3) E. Santa Claus and Tangerines
E. Santa Claus and Tangerines time limit per test 2 seconds memory limit per test 256 megabytes inpu ...
- Codeforces Round #389 Div.2 E. Santa Claus and Tangerines
time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...
- Codeforces Round #389 Div.2 C. Santa Claus and Robot
time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...
- Codeforces Round #389 Div.2 B. Santa Claus and Keyboard Check
time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...
随机推荐
- Site Not Found
http://moofx.it/ Site Not Found http://www. suchso.com /code/ace/gallery.html http://demo.rocketthem ...
- Segment set
题目大意: 在一个平面上,给定N根线段,若某条线段与另一条线段相交,则将它们归于同个集合,给定k,问第k条线段所在的集合中线段的数量. 题目分析: 问题主要考察计算几何和并查集. 首先我们要判断两条线 ...
- 初学者在ubuntu下安装使用git(上)
一 git的安装测试 在Ubuntu系统下的bash中输入git,如果提示没有安装的话,用命令 sudo apt-get install git 安装git,安装完成之后通过 git –versi ...
- 【Python基础学习六】函数
1.创建函数 Python中函数的关键字def来定义. def fibs(num): f=[0,1] for i in range(1,num): f.append(f[-1]+f[-2]) retu ...
- VS2013编译Qt5.6.0静态库
获取qt5.6.0源码包 直接去www.qt.io下载就好了,这里就不详细说了. 这里是我已经编译好的** 链接:http://pan.baidu.com/s/1pLb6wVT 密码: ak7y ** ...
- Python日志logging
logging 用于便捷记录日志且线程安全的模块 1.单文件日志 import logging logging.basicConfig(filename='log.log', format='%(as ...
- Power of Three
Given an integer, write a function to determine if it is a power of three. Follow up:Could you do it ...
- JQ图片轮播
<script src="{staticurl action="jquery.js" type="js"}"></scri ...
- mysql连结查询
2016年4月13日 18:08:22 星期三 union 会生成临时表, 然后一同取出合并 join 或子查询, 会生成临时表进行嵌套循环 临时表, 缺点就是没有索引
- 腾讯QQ形象18年变迁史,最早的QQ企鹅形象居然长这样!
1999年,腾讯创建之初,这是当时QQ的形象,现在看起来很滑稽,又高又瘦.当时公司并没有专职的设计师,所以这个形象就凑合着用了. 后来,腾讯也觉着上一个形象做的不是特别好,于是在2000年的时候,公司 ...