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

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处

  1. #include<stdio.h>
  2. #include<string.h>
  3. #include<algorithm>
  4. #include<math.h>
  5. #include<map>
  6. #include<string>
  7. #include<vector>
  8. #include<queue>
  9. #include<iostream>
  10. using namespace std;
  11. #define L long long
  12. char s[200050];
  13. int n ;
  14. int su[200050];
  15. int sd[200050];
  16. int sr[200050];
  17. int sl[200050];
  18. int ef(int a[],int ll,int rr,int val){
  19. int res = n + 1;
  20. int l = ll ;
  21. int r = rr ;
  22. while(l <= r){
  23. int mid = (l + r) / 2;
  24. if(a[mid]>val){
  25. res = mid ;
  26. r = mid - 1;
  27. }
  28. else {
  29. l = mid + 1;
  30. }
  31. }
  32. return res ;
  33. }
  34. int main(){
  35. scanf("%d",&n);
  36. scanf("%s",s+1);
  37. su[0] = sl[0] = sr[0] = sd[0] = 0;
  38. for(int i=1;i<=n;i++){
  39. su[i] = su[i-1];
  40. sr[i] = sr[i-1];
  41. sd[i] = sd[i-1];
  42. sl[i] = sl[i-1];
  43. if(s[i] =='U')su[i]++;
  44. if(s[i] =='D')sd[i]++;
  45. if(s[i] =='R')sr[i]++;
  46. if(s[i] =='L')sl[i]++;
  47. }
  48. int w = 0;
  49. int ans = 0;
  50. while(w < n){
  51. char c = s[w+1];
  52. int uu = ef(su,w+1,n,su[w]);
  53. int dd = ef(sd,w+1,n,sd[w]);
  54. int rr = ef(sr,w+1,n,sr[w]);
  55. int ll = ef(sl,w+1,n,sl[w]);
  56. int ky1 = max(uu,dd)-1;
  57. int ky2 = max(rr,ll)-1;
  58. int res = min(ky1,ky2);
  59. ans ++ ;
  60. w = res ;
  61. }
  62. printf("%d\n",ans);
  63. }

  

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. 字符串匹配:KMP算法

    一.原理: KMP算法是由Knuth,Morris,Pratt共同提出的模式匹配算法,其对于任何模式和目标序列,都可以在线性时间内完成匹配查找,而不会发生退化,是一个非常优秀的模式匹配算法.朴素算法( ...

  2. opencv二值化处理

    #include "stdafx.h"//对一张图片进行二值化处理 IplImage *pSrclmg =NULL;//载入的图片IplImage *pDeclmg =NULL;/ ...

  3. xss小试

    javascript:alert(document.cookie)javascript:alert(document.domain) 预防: HTTP cookie设置为readOnly 豆瓣 coo ...

  4. go:匿名函数与闭包

    一.匿名函数 定义:没有函数名的函数. 作用:在go语言中目前了解的作用就是用于构成闭包. *注:由于javascript不存在块级作用域,故匿名函数常用来包含代码以不污染全局命名空间,运行后销毁环境 ...

  5. ajax返回数据类型为JSON数据的处理

    JSON数据处理: 1.编码格式必须为utf8 2.echo json_encode($db->GuanQuery($sql));   返回的是关联数组.json_encode返回的是json数 ...

  6. SQL入门语句之SELECT和WHERE

    一.SQL入门语句之SELECT SELECT语句用于从数据库表中获取数据,结果表的形式返回数据.这些结果表也被称为结果集 1.从数据库表中取部分字段 select 字段A,字段B from tabl ...

  7. html+css做的丝带标签

    先上效果: HTML: <div class="tag"> <div class="tag-box"> <div class=&q ...

  8. HTTP错误500.19-定义了重复的节点

    打开服务器的asp.net页面时出现这个错误: HTTP 错误 500.19 - Internal Server Error 无法访问请求的页面,因为该页的相关配置数据无效.   解决办法: 打开II ...

  9. 2015ACM/ICPC亚洲区上海站

    5573 Binary Tree(构造) 题意:给你一个二叉树,根节点为1,子节点为父节点的2倍和2倍+1,从根节点开始依次向下走k层,问如何走使得将路径上的数进行加减最终结果得到n. 联想到二进制. ...

  10. iOS--NSBundle理解

    NSBundle:官方文档解释:An NSBundle object represents a location in the file system that groups code   and r ...