【题目链接】: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



【完整代码】

#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ms(x,y) memset(x,y,sizeof x)
#define Open() freopen("F:\\rush.txt","r",stdin)
#define Close() ios::sync_with_stdio(0),cin.tie(0) typedef pair<int,int> pii;
typedef pair<LL,LL> pll; const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0);
const int N = 1100; int f[N],n;
char s[N]; int main(){
//Open();
Close();//scanf,puts,printf not use
//init??????
cin >> n;
cin >> (s+1);
f[1] = 1;
rep1(i,1,n-1){
if (s[i]=='='){
f[i+1] = f[i];
}
else
if (s[i]=='R'){
f[i+1] = f[i]+1;
}
else{
//s[i]=='L'
f[i+1] = 1;
if (f[i]>f[i+1])
continue;
else
{
f[i]++;
rep2(j,i-1,1){
if (s[j]=='R') break;
if (s[j]=='L'){
if (f[j]==f[j+1])
f[j]++;
else
break;
}
else
f[j] = f[j+1];
}
}
}
} rep1(i,1,n)
cout << f[i] << (i==n?'\n':' ');
return 0;
}

【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. django patch 解决 ["'15428560000' value has an invalid format. It must be in YYYY-MM-DD HH:MM[:ss[.uuuuuu]][TZ] format."]

    __init__.py import datetime from django.apps import AppConfig from django.db.models.fields import Da ...

  2. Vue双向绑定原理(源码解析)---getter setter

       Vue双向绑定原理      大部分都知道Vue是采用的是对象的get 和set方法来实现数据的双向绑定的过程,本章将讨论他是怎么利用他实现的. vue双向绑定其实是采用的观察者模式,get和s ...

  3. django-3-模板变量,过滤器,静态文件的引用

    <<<模板变量>>> (1)定义视图函数 通过context传递参数来渲染模板,context要是个字典 当模板变量为可调用对象的时候,函数不传递参数 (2)配置模 ...

  4. Having用法

    HAVING 子句对 GROUP BY 子句设置条件的方式与 WHERE 和 SELECT 的交互方式类似.WHERE 搜索条件在进行分组操作之前应用:而 HAVING 搜索条件在进行分组操作之后应用 ...

  5. 【codeforces 746G】New Roads

    [题目链接]:http://codeforces.com/problemset/problem/746/G [题意] 给你3个数字n,t,k; 分别表示一棵树有n个点; 这棵树的深度t,以及叶子节点的 ...

  6. PatentTips – Java native function calling

    BACKGROUND OF INVENTION This invention relates to a system and method for providing a native functio ...

  7. ASP.NET-表单验证-DataAnnotations

    DataAnnotations  [数据注解,数据注释] 需要引入两个脚本文件 <script src="@Url.Content("~/Scripts/jquery.val ...

  8. java ee服务器/应用服务器的理解

    42.由Apache.Sun 和其他一些公司及个人共同开发而成.由于有了Sun 的参与和支持,最新的Servlet 和JSP 规范总是能在Tomcat 中得到体现.43.可以这样认为,当在一台机器上配 ...

  9. Qt之二维码扫描

    简述 二维码(QR Code)是用某种特定的几何图形按一定规律在平面(二维方向)分布的黑白相间的图形记录数据符号信息的.是所有信息数据的一把钥匙.应用十分广泛,如:产品防伪/溯源.广告推送.网站链接. ...

  10. 保留全部Android crash信息

    保留全部Android crash信息 framework/base/core/java/com/android/internal/os/RuntimeInit.java 又一次以下这个函数,增加自己 ...