【题目链接】:http://codeforces.com/problemset/problem/67/A

【题意】



给一个长度为n-1的字符串;

每个字符串是’L’,’R’,’=’这3种字符中的一个;

分别表示第i个元素比第i+1个元素大,小,相等;

让你构造出这么一个长度为n的序列;

使得每个位置上的数字的和最小;

(每个数字最少为1);

【题解】



ans[1]=1;

然后对于每一个位置;

“相等”->ans[i+1]=ans[i];

“R”->ans[i+1] = ans[i]+1;

“L”->

则先让ans[i+1]最小=1

然后看看ans[i]是不是比ans[i+1]来得大;

是的话就继续;

否则的话进行调整;

调整的步骤是;

先令ans[i]+1;

从前一步往前扫描;

如果s[j]==’=’则ans[j]=ans[j+1];

如果s[j]==’l’则如果ans[j]>ans[j+1] 则结束,否则ans[j]++;

如果s[j]==’R”则结束;(因为可以看到,我们在调整的时候都是至少让ans[j]递增的;所以s[j]==’R’的是肯定满足的;



【Number Of WA】



1



【完整代码】

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define lson l,m,rt<<1
  4. #define rson m+1,r,rt<<1|1
  5. #define LL long long
  6. #define rep1(i,a,b) for (int i = a;i <= b;i++)
  7. #define rep2(i,a,b) for (int i = a;i >= b;i--)
  8. #define mp make_pair
  9. #define pb push_back
  10. #define fi first
  11. #define se second
  12. #define ms(x,y) memset(x,y,sizeof x)
  13. #define Open() freopen("F:\\rush.txt","r",stdin)
  14. #define Close() ios::sync_with_stdio(0),cin.tie(0)
  15. typedef pair<int,int> pii;
  16. typedef pair<LL,LL> pll;
  17. const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
  18. const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
  19. const double pi = acos(-1.0);
  20. const int N = 1100;
  21. int f[N],n;
  22. char s[N];
  23. int main(){
  24. //Open();
  25. Close();//scanf,puts,printf not use
  26. //init??????
  27. cin >> n;
  28. cin >> (s+1);
  29. f[1] = 1;
  30. rep1(i,1,n-1){
  31. if (s[i]=='='){
  32. f[i+1] = f[i];
  33. }
  34. else
  35. if (s[i]=='R'){
  36. f[i+1] = f[i]+1;
  37. }
  38. else{
  39. //s[i]=='L'
  40. f[i+1] = 1;
  41. if (f[i]>f[i+1])
  42. continue;
  43. else
  44. {
  45. f[i]++;
  46. rep2(j,i-1,1){
  47. if (s[j]=='R') break;
  48. if (s[j]=='L'){
  49. if (f[j]==f[j+1])
  50. f[j]++;
  51. else
  52. break;
  53. }
  54. else
  55. f[j] = f[j+1];
  56. }
  57. }
  58. }
  59. }
  60. rep1(i,1,n)
  61. cout << f[i] << (i==n?'\n':' ');
  62. return 0;
  63. }

【codeforces 67A】Partial Teacher的更多相关文章

  1. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  2. 【24.34%】【codeforces 560D】Equivalent Strings

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  3. 【codeforces 758C】Unfair Poll

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  4. 【22.73%】【codeforces 606D】Lazy Student

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  5. 【codeforces 707E】Garlands

    [题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...

  6. 【codeforces 707C】Pythagorean Triples

    [题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...

  7. 【codeforces 709D】Recover the String

    [题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...

  8. 【codeforces 709B】Checkpoints

    [题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...

  9. 【codeforces 709C】Letters Cyclic Shift

    [题目链接]:http://codeforces.com/contest/709/problem/C [题意] 让你改变一个字符串的子集(连续的一段); ->这一段的每个字符的字母都变成之前的一 ...

随机推荐

  1. [CodeForces]500B New Year Permutation

    刷水题做几道入门贪心题预热... 找联通块里字典序最小的放到最前面即可.记得写传递闭包 #include <iostream> #include <cstdio> #inclu ...

  2. Linux学习01

    Linux学习第一天 1.使用VM安装RHEL7.0 具体参见刘遄老师的<Linux就该怎么学>https://www.linuxprobe.com/chapter-01.html 2.R ...

  3. 2019-02-25 SQL:cast(itemvalue as decimal(19,4))

    1.Operand data type nvarchar(max) is invalid for sum operator 要转换格式 2.Conversion failed when convert ...

  4. 紫书 例题8-1 UVa 120(构造法)

    #include<cstdio> #include<iostream> #include<sstream> #include<algorithm> #d ...

  5. JQuery封装ajax的方法

    1.$.post方法 $.post(url[,data][,callback][,type]) url:请求的后台程序地址 data:发送到后台的数据 callback:载入成功时回调函数,该函数参数 ...

  6. div,span等标签支持focus/blur事件

    <div tabindex="0" hidefocus="true" onfocus='alert("得到焦点");' onblur= ...

  7. 如何在 Linux 上安装 Nginx (源码安装)

    如何在 Linux( CentOS ) 上安装 Nginx 1.下载 nginx 链接 : https://pan.baidu.com/s/1sll0Hrf 密码 : xnem 2.安装 gcc ( ...

  8. 编写html经常使用而又easy忘记的语句

    设置文件字符编码: <meta charset="utf-8"> 内部样式表: <style type="text/css"> hr { ...

  9. leetcode第一刷_Subsets II

    要求子集,有很现成的方法.N个数.子集的个数是2^N.每一个元素都有在集合中和不在集合中两种状态,这些状态用[0,pow(2,N)]中每一个数来穷举,假设这个数中的第i位为1,说明当前集合中包括源数组 ...

  10. Oracle Study之--Oracle 单实例11.2.0.1.0升级到11.2.0.3.0

    Oracle Study之--Oracle 单实例11.2.0.1.0升级到11.2.0.3.0 系统环境: 操作系统:RedHat EL6(64位) Oracle:    Oracle 11gR2 ...