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 ...
随机推荐
- 字符串匹配:KMP算法
一.原理: KMP算法是由Knuth,Morris,Pratt共同提出的模式匹配算法,其对于任何模式和目标序列,都可以在线性时间内完成匹配查找,而不会发生退化,是一个非常优秀的模式匹配算法.朴素算法( ...
- opencv二值化处理
#include "stdafx.h"//对一张图片进行二值化处理 IplImage *pSrclmg =NULL;//载入的图片IplImage *pDeclmg =NULL;/ ...
- xss小试
javascript:alert(document.cookie)javascript:alert(document.domain) 预防: HTTP cookie设置为readOnly 豆瓣 coo ...
- go:匿名函数与闭包
一.匿名函数 定义:没有函数名的函数. 作用:在go语言中目前了解的作用就是用于构成闭包. *注:由于javascript不存在块级作用域,故匿名函数常用来包含代码以不污染全局命名空间,运行后销毁环境 ...
- ajax返回数据类型为JSON数据的处理
JSON数据处理: 1.编码格式必须为utf8 2.echo json_encode($db->GuanQuery($sql)); 返回的是关联数组.json_encode返回的是json数 ...
- SQL入门语句之SELECT和WHERE
一.SQL入门语句之SELECT SELECT语句用于从数据库表中获取数据,结果表的形式返回数据.这些结果表也被称为结果集 1.从数据库表中取部分字段 select 字段A,字段B from tabl ...
- html+css做的丝带标签
先上效果: HTML: <div class="tag"> <div class="tag-box"> <div class=&q ...
- HTTP错误500.19-定义了重复的节点
打开服务器的asp.net页面时出现这个错误: HTTP 错误 500.19 - Internal Server Error 无法访问请求的页面,因为该页的相关配置数据无效. 解决办法: 打开II ...
- 2015ACM/ICPC亚洲区上海站
5573 Binary Tree(构造) 题意:给你一个二叉树,根节点为1,子节点为父节点的2倍和2倍+1,从根节点开始依次向下走k层,问如何走使得将路径上的数进行加减最终结果得到n. 联想到二进制. ...
- iOS--NSBundle理解
NSBundle:官方文档解释:An NSBundle object represents a location in the file system that groups code and r ...