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

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. 12个非常实用的JavaScript小技巧

    在这篇文章中将给大家分享12个有关于JavaScript的小技巧.这些小技巧可能在你的实际工作中或许能帮助你解决一些问题. 使用!!操作符转换布尔值 有时候我们需要对一个变量查检其是否存在或者检查值是 ...

  2. 使用jvisualvm.exe 的Btrace插件介绍/使用教程

    一.背景        在生产环境中可能经常遇到各种问题,定位问题需要获取程序运行时的数据信息,如方法参数.返回值.全局变量.堆栈信息等.为了获取这些数据信息,我们可以 通过改写代码,增加日志信息的打 ...

  3. mysql状态取反(0变1,1变0)

    如果要改变status状态 update   table_name   status=ABS(status-1);   //取绝对值 则0-->1   1-->0

  4. (转)EClipse插件推荐

    http://www.importnew.com/4707.html 来自非营利性Eclipse基金会的Eclipse IDE以其插件生态系统著称.Eclipse市场拥有海量插件可供下载,你可以通过插 ...

  5. windows 8下配置PLSQLDeveloper

    Win 8 64位系统上安装64 位Oracle,但是没有64位的PL/SQL,不能连接Oracle数据库,怎么办呢?方法是有的:我们可以通过安装32位的Oracle客户端来实现连接. 工具/原料 P ...

  6. AngularJS Select(选择框)

    AngularJS 可以使用数组或对象创建一个下拉列表选项. 使用 ng-option 创建选择框 在 AngularJS 中我们可以使用 ng-option 指令来创建一个下拉列表,列表项通过对象和 ...

  7. Css Sprites 多张图片整合在一张图片上

    CSS Sprites原理: CSS Sprites其实就是把网页中一些背景图片整合到一张图片文件中,再利用CSS的"background-image","backgro ...

  8. 【JavaScript中的正则表达式】

    原文地址:http://blog.csdn.net/xh16319/article/details/9987847 1. 正则表达式规则 1.1 普通字符 字母.数字.汉字.下划线.以及后边章节中没有 ...

  9. C# 执行文件的根目录 (转)

    1.取得控制台应用程序的根目录方法 方法1.Environment.CurrentDirectory 取得或设置当前工作目录的完整限定路径方法2.AppDomain.CurrentDomain.Bas ...

  10. Epub基础知识介绍

    转载自:http://www.cnblogs.com/linlf03/archive/2011/12/13/2286218.html 一.什么是epub epub是一个完全开放和免费的电子书标准.它可 ...