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 ...
随机推荐
- FZU 2112 并查集、欧拉通路
原题:http://acm.fzu.edu.cn/problem.php?pid=2112 首先是,票上没有提到的点是不需要去的. 然后我们先考虑这个图有几个连通分量,我们可以用一个并查集来维护,假设 ...
- parse_str怎么用php
1.需求 了解parse_str的用法 2.作用 parse_str接受2个参数,把第一个参数查询字符串解析到第二个参数数组当中,会覆盖数组中原来的值 parse_str($_SERVER['QUER ...
- CSS3——transform学习
CSS动画效果可以使用transform和Animation,前者较简单,先学习前者. transform有几个基本变换,平移.旋转.缩放.扭曲 一.translate平移 有translate2d和 ...
- bootstrap 笔记
导航条: div.navbar.navbar-default > ul.nav.navbar 无非两层: 父div: navbar {相对位置.最低高度50px.下部margin:20px.透明 ...
- poj 并查集
http://poj.org/problem?id=1611 水题 题意:就是找一共有多少个人感染了,0是感染学生的编号. #include <stdio.h> #include < ...
- MySQL学习笔记(2/2)
SQL种类 DDL/DML/DQL/DCL 中括号[]里面的表示可选,大括号{}里面的表示必须从里面选一个,FEILED表示字段. 数据定义语言(DDL):CREATE.DROP.ALTER 用于定义 ...
- ubuntu下安装nodejs,无node情况
Updating nodejs solved the issue: npm cache clean -f npm install -g n n stable node --version node ...
- C Primer Plus_第8章_字符输入输出和输入确认_编程练习
1.题略 #include <stdio.h> int main(void) { ; printf("Please enter text here(end with Ctrl + ...
- Ubuntu下三个实用的录屏软件
Ubuntu下三个实用的录屏软件 Kazam 优点: 易安装 可选择区域录制,也可全屏录制 有录屏和截图功能 安装: sudo apt-get install kazam 展示: Simple Scr ...
- 继承Thread类
Thread类在包java.lang中,从这个类中实例化的对象代表线程,启动一个新线程需要建立Thread实例,Thread类中常用的两个构造方法如下: (1)public Thread(String ...