codeforces #578(Div.2)

A. Hotelier

Amugae has a hotel consisting of 1010 rooms. The rooms are numbered from 00 to 99 from left to right.

The hotel has two entrances — one from the left end, and another from the right end. When a customer arrives to the hotel through the left entrance, they are assigned to an empty room closest to the left entrance. Similarly, when a customer arrives at the hotel through the right entrance, they are assigned to an empty room closest to the right entrance.

One day, Amugae lost the room assignment list. Thankfully Amugae's memory is perfect, and he remembers all of the customers: when a customer arrived, from which entrance, and when they left the hotel. Initially the hotel was empty. Write a program that recovers the room assignment list from Amugae's memory.

Input

The first line consists of an integer nn (1≤n≤1051≤n≤105), the number of events in Amugae's memory.

The second line consists of a string of length nn describing the events in chronological order. Each character represents:

  • 'L': A customer arrives from the left entrance.
  • 'R': A customer arrives from the right entrance.
  • '0', '1', ..., '9': The customer in room xx (00, 11, ..., 99 respectively) leaves.

It is guaranteed that there is at least one empty room when a customer arrives, and there is a customer in the room xx when xx (00, 11, ..., 99) is given. Also, all the rooms are initially empty.

Output

In the only line, output the hotel room's assignment status, from room 00 to room 99. Represent an empty room as '0', and an occupied room as '1', without spaces.

Examples

input

  1. 8
  2. LLRL1RL1

output

  1. 1010000011

input

  1. 9
  2. L0L0LLRR9

output

  1. 1100000010

Note

In the first example, hotel room's assignment status after each action is as follows.

  • First of all, all rooms are empty. Assignment status is 0000000000.
  • L: a customer arrives to the hotel through the left entrance. Assignment status is 1000000000.
  • L: one more customer from the left entrance. Assignment status is 1100000000.
  • R: one more customer from the right entrance. Assignment status is 1100000001.
  • L: one more customer from the left entrance. Assignment status is 1110000001.
  • 1: the customer in room 11 leaves. Assignment status is 1010000001.
  • R: one more customer from the right entrance. Assignment status is 1010000011.
  • L: one more customer from the left entrance. Assignment status is 1110000011.
  • 1: the customer in room 11 leaves. Assignment status is 1010000011.

So after all, hotel room's final assignment status is 1010000011.

In the second example, hotel room's assignment status after each action is as follows.

  • L: a customer arrives to the hotel through the left entrance. Assignment status is 1000000000.
  • 0: the customer in room 00 leaves. Assignment status is 0000000000.
  • L: a customer arrives to the hotel through the left entrance. Assignment status is 1000000000 again.
  • 0: the customer in room 00 leaves. Assignment status is 0000000000.
  • L: a customer arrives to the hotel through the left entrance. Assignment status is 1000000000.
  • L: one more customer from the left entrance. Assignment status is 1100000000.
  • R: one more customer from the right entrance. Assignment status is 1100000001.
  • R: one more customer from the right entrance. Assignment status is 1100000011.
  • 9: the customer in room 99 leaves. Assignment status is 1100000010.

So after all, hotel room's final assignment status is 1100000010.

题意:10个房间两个门,在左右两端,从那边的门进优先安排进最近的房间,任意客人可以离开房间,n个事件从左进、从右进、客人离开房间。问最后的房间 分布情况。

思路:按照题意模拟即可。如果是哪个房间的客人离开了,利用Ascll码的到数组下标访问数组即可,反之就遍历数组找最近的。代码如下:

  1. #include <bits/stdc++.h>
  2. #define LL long long
  3. using namespace std;
  4. int n,a[10];
  5. string s;
  6. int main(){
  7. cin>>n>>s;
  8. for(int i=0;i<n;i++){
  9. if(s[i]=='L'){for(int j=0;j<10;j++)if(!a[j]){a[j]=1;break;}}
  10. else if(s[i]=='R'){for(int j=9;j>=0;j--)if(!a[j]){a[j]=1;break;}}
  11. else a[s[i]-'0']=0;
  12. }
  13. for(int i=0;i<10;i++)printf("%d",a[i]);
  14. return 0;
  15. }

B. Block Adventure

Gildong is playing a video game called Block Adventure. In Block Adventure, there are nn columns of blocks in a row, and the columns are numbered from 11 to nn. All blocks have equal heights. The height of the ii-th column is represented as hihi, which is the number of blocks stacked in the ii-th column.

Gildong plays the game as a character that can stand only on the top of the columns. At the beginning, the character is standing on the top of the 11-st column. The goal of the game is to move the character to the top of the nn-th column.

The character also has a bag that can hold infinitely many blocks. When the character is on the top of the ii-th column, Gildong can take one of the following three actions as many times as he wants:

  • if there is at least one block on the column, remove one block from the top of the ii-th column and put it in the bag;
  • if there is at least one block in the bag, take one block out of the bag and place it on the top of the ii-th column;
  • if i<ni<n and |hi−hi+1|≤k|hi−hi+1|≤k, move the character to the top of the i+1i+1-st column. kk is a non-negative integer given at the beginning of the game. Note that it is only possible to move to the next column.

In actions of the first two types the character remains in the ii-th column, and the value hihi changes.

The character initially has mm blocks in the bag. Gildong wants to know if it is possible to win the game. Help Gildong find the answer to his question.

Input

Each test contains one or more test cases. The first line contains the number of test cases tt (1≤t≤10001≤t≤1000). Description of the test cases follows.

The first line of each test case contains three integers nn, mm, and kk (1≤n≤1001≤n≤100, 0≤m≤1060≤m≤106, 0≤k≤1060≤k≤106) — the number of columns in the game, the number of blocks in the character's bag at the beginning, and the non-negative integer kk described in the statement.

The second line of each test case contains nn integers. The ii-th integer is hihi (0≤hi≤1060≤hi≤106), the initial height of the ii-th column.

Output

For each test case, print "YES" if it is possible to win the game. Otherwise, print "NO".

You can print each letter in any case (upper or lower).

Example

input

  1. 5
  2. 3 0 1
  3. 4 3 5
  4. 3 1 2
  5. 1 4 7
  6. 4 10 0
  7. 10 20 10 20
  8. 2 5 5
  9. 0 11
  10. 1 9 9
  11. 99

output

  1. YES
  2. NO
  3. YES
  4. NO
  5. YES

Note

In the first case, Gildong can take one block from the 11-st column, move to the 22-nd column, put the block on the 22-nd column, then move to the 33-rd column.

In the second case, Gildong has to put the block in his bag on the 11-st column to get to the 22-nd column. But it is impossible to get to the 33-rd column because |h2−h3|=3>k|h2−h3|=3>k and there is no way to decrease the gap.

In the fifth case, the character is already on the nn-th column from the start so the game is won instantly.

题意: 小G在玩一款电子游戏。游戏规则是有n列柱子(每列柱子上有若干等高积木)并排放在一起,给定小G的跨越能力k(即他只能站在柱顶,自左向右地走,且两列柱子之间的差值不能大于k)。小G有一个袋子(袋子中的积木数为m,袋子的容量是无限大的),可以进行如下操作,拿起一个积木放进袋子里,从袋子里掏出一个积木置于柱顶。如果小G能走到最后一个柱子的顶端则算他赢,否则算他输。

思路:首先来考虑a[i]>=a[i+1]的情况,此时无论k、m为多少都能走到下一列,在结合k的作用;可以推出a[i]+k>=a[i+1]时也是一定可以走到下一列的,此时应该在保证能够走到下一列的情况下尽可能地把积木装进袋子,继而可以得到一个最低通过高度(a[i+1]-k);反过来的话,则要从袋子里拿出积木以达到最低通过高度。代码如下:

  1. #include <bits/stdc++.h>
  2. #define LL long long
  3. using namespace std;
  4. int const maxn=101;
  5. int n,m,k;
  6. struct node{
  7. int data;
  8. }q[maxn];
  9. bool text()
  10. {
  11. bool qaq=false;
  12. for(int i=0;i<n-1;i++){
  13. if(i==n-2){
  14. if(q[i].data+m+k>=q[i+1].data){//如果走到了最后一列返回真
  15. qaq=true;
  16. break;
  17. }
  18. }
  19. if(q[i].data+k>=q[i+1].data){//如果q[i].data大于当前最小通过高度,就尽可能往及袋子里装积木
  20. if(q[i+1].data>=k){
  21. m+=q[i].data-(q[i+1].data-k);
  22. }else{
  23. m+=q[i].data;
  24. }
  25. }
  26. else{//否则判断加上袋子里的积木能否达到当前最大高度
  27. if(q[i].data+m+k<q[i+1].data)break;
  28. else{
  29. m-=q[i+1].data-k-q[i].data;
  30. if(m<0)break;//这句不加也能过,保险起见还是留着吧
  31. }
  32. }
  33. }
  34. return qaq;
  35. }
  36. int main()
  37. {
  38. int t;
  39. scanf("%d",&t);//测试数据组数
  40. while(t--){
  41. scanf("%d %d %d",&n,&m,&k);
  42. for(int i=0;i<n;i++)scanf("%d",&q[i].data);
  43. if(n==1){//特判下只有1列的情况
  44. printf("YES\n");
  45. continue;
  46. }
  47. if(text())printf("YES\n");
  48. else printf("NO\n");
  49. }
  50. return 0;
  51. }

codeforces #578(Div.2)的更多相关文章

  1. Codeforces Round #578 (Div. 2)

    Codeforces Round #578 (Div. 2) 传送门 A. Hotelier 暴力即可. Code #include <bits/stdc++.h> using names ...

  2. Codeforces #344 Div.2

    Codeforces #344 Div.2 Interview 题目描述:求两个序列的子序列或操作的和的最大值 solution 签到题 时间复杂度:\(O(n^2)\) Print Check 题目 ...

  3. Codeforces #345 Div.1

    Codeforces #345 Div.1 打CF有助于提高做题的正确率. Watchmen 题目描述:求欧拉距离等于曼哈顿距离的点对个数. solution 签到题,其实就是求有多少对点在同一行或同 ...

  4. Codeforces Beta Round #27 (Codeforces format, Div. 2)

    Codeforces Beta Round #27 (Codeforces format, Div. 2) http://codeforces.com/contest/27 A #include< ...

  5. Codeforces#441 Div.2 四小题

    Codeforces#441 Div.2 四小题 链接 A. Trip For Meal 小熊维尼喜欢吃蜂蜜.他每天要在朋友家享用N次蜂蜜 , 朋友A到B家的距离是 a ,A到C家的距离是b ,B到C ...

  6. codeforces #592(Div.2)

    codeforces #592(Div.2) A Pens and Pencils Tomorrow is a difficult day for Polycarp: he has to attend ...

  7. codeforces #577(Div.2)

    codeforces #577(Div.2) A  Important Exam A class of students wrote a multiple-choice test. There are ...

  8. codeforces #332 div 2 D. Spongebob and Squares

    http://codeforces.com/contest/599/problem/D 题意:给出总的方格数x,问有多少种不同尺寸的矩形满足题意,输出方案数和长宽(3,5和5,3算两种) 思路:比赛的 ...

  9. KMP(next数组的更新理解)Codeforces Round #578 (Div. 2)--Compress Words

    题目链接:https://codeforc.es/contest/1200/problem/E 题意: 有n串字符串,让你连起来:sample please ease in out   ---> ...

随机推荐

  1. Ubuntu环境下载程序到STM32

    1 JLink方式 1.0 下载JLink 传送门:SEGGER官网 图1.0 下载JLink 1.2 安装JLink 双击打开下载文件:JLink_Linux_V644i_x86_64.deb 1. ...

  2. Missing write access to /usr/local/lib/node_modules npm ERR! path /usr/local/lib/node_modules

    今天用npm下载yarn,出现Missing write access to /usr/local/lib/node_modules npm ERR! path /usr/local/lib/node ...

  3. 201871010117-石欣钰《面向对象程序设计(java)》第十三周学习总结

    项目 内容 这个作业属于哪个课程 https://www.cnblogs.com/nwnu-daizh/ 这个作业的要求在哪里 https://www.cnblogs.com/nwnu-daizh/p ...

  4. SpringBoot使用@Value来获取properties的值

    今天在项目中想使用@Value来获取Springboot中properties中属性值.场景:定义了一个工具类,想要获取一些配置参数,使用了@value来获取,但是死活也获取不到.如何解决:在使用这个 ...

  5. 【目标检测】SSD:

    slides 讲得是相当清楚了: http://www.cs.unc.edu/~wliu/papers/ssd_eccv2016_slide.pdf 配合中文翻译来看: https://www.cnb ...

  6. LeetCode 51. N-QueensN皇后 (C++)(八皇后问题)

    题目: The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two que ...

  7. LOJ 数列分块入门系列

    目录 1.区间加+单点查 每个块维护tag,散的暴力改. code: #include<bits/stdc++.h> using namespace std; const int maxn ...

  8. javascript中的e是什么意思?

    e 代表事件(event)对象,即所谓的事件驱动源,包含了许多属性和方法.下面以鼠标点击事件为例,作一个测试: (HTML) <!DOCTYPE html> <html> &l ...

  9. 2016年蓝桥别A组模拟训练

    1. 网友年龄 某君新认识一网友. 当问及年龄时,他的网友说: “我的年龄是个2位数,我比儿子大27岁, 如果把我的年龄的两位数字交换位置,刚好就是我儿子的年龄” 请你计算:网友的年龄一共有多少种可能 ...

  10. Web协议详解与抓包实战:HTTP1协议-详解请求行(2)

    一.请求行一 二.请求行二 三.请求行三 四.常见方法(RFC7231) 实际测试截图 五.用于文档管理的 WEBDAV 方法(RFC2518) 六.WEBDAV 验证环境  1.登录  2.Wire ...