考完复变之后沉迷联盟不能自拔...明天就开始抢救计组 ...

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的更多相关文章

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

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

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

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

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

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

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

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

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

随机推荐

  1. python多线程学习记录

    1.多线程的创建 import threading t = t.theading.Thread(target, args--) t.SetDeamon(True)//设置为守护进程 t.start() ...

  2. cf595d

    题意:给出一个轮子,上面有一个随着它转动的传感器在圆周上,给出一个指定距离m,和轮子向前行进的速度v以及轮子的半径r.问让传感器通过该距离最少需要多少时间. 分析:首先我们列出传感器行进距离与时间的轮 ...

  3. SQL优化

    1.对查询进行优化,应尽量避免全表扫描,首先应考虑在 where 及 order by 涉及的列上建立索引. 2.应尽量避免在 where 子句中对字段进行 null 值判断,否则将导致引擎放弃使用索 ...

  4. python merry -- error handling in the real world

    参考: https://www.youtube.com/watch?v=8kTlzR4HhWo https://github.com/miguelgrinberg/merry 背景 本文实际就是把 d ...

  5. ASM:《X86汇编语言-从实模式到保护模式》第17章:保护模式下中断和异常的处理与抢占式多任务

    ★PART1:中断和异常概述 1. 中断(Interrupt) 中断包括硬件中断和软中断.硬件中断是由外围设备发出的中断信号引发的,以请求处理器提供服务.当I/O接口发出中断请求的时候,会被像8259 ...

  6. .NET 程序集与命名空间

    程序集 程序集(assembly)是一个或多个托管模块,以及一些资源文件的逻辑组合. 组成部分 Windows文件首部 CLR文件首部 程序集清单 类型元数据 MSIL(CIL)代码 嵌入资源集 作用 ...

  7. 三言两语之js事件、事件流以及target、currentTarget、this那些事

    厉害了我的哥--你是如此简单我却将你给遗忘   放假前再看某文档,里边提到两个我既熟悉又陌生的概念target.currentTarget,说他熟悉我曾经看到过这两个事件对象的异同处,说他陌生吧?很不 ...

  8. 简单的SQL联表更新

    UPDATE dbo.bankinfo1 SET bankinfo1.BankName=BankInfo.BankName FROM BankInfo where bankinfo1.banknumb ...

  9. ZXing生成二维码

    dll:http://files.cnblogs.com/files/jake-ge/ZXing.rar 引入命名空间 using System.Drawing;using System.IO;usi ...

  10. Objective-C 中self.与_访问方式的区别

    Objective-C中属性self.a与_a访问的区别: 在OC中我们可以通过指令@property定义属性. OC对属性封装了许多方法,同时也会自动实现一些方法,相比实例变量,感觉更加面向对象些. ...