【题目链接】: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. Build rpm example:zram

    rpmbuild #ll zram-1.0.0 total 32 -rw-r--r-- 1 root root 948 Aug 21 16:44 Makefile -rw-r--r-- 1 root ...

  2. C语言基本语法——变量

    1.变量作用域 2.局部变量 3.全局变量 4.变量生命周期 5.auto关键字 6.static关键字 1.变量作用域 • 变量作用域是指变量的有效范围 • 变量作用域是定义变量从何处被创建,到何处 ...

  3. [读书笔记] Python数据分析 (三) IPython

    1. 什么是IPython IPyhton 本身没有提供任何的计算或者数据分析功能,在交互式计算和软件开发者两个方面最大化地提高生产力,execute-explore instead of edit- ...

  4. 解决tpcc_load 报错 error while loading shared libraries: libmysqlclient.so.20

    在刚开始导入tpcc数据仓库时,可能会遇到 error while loading shared libraries: libmysqlclient.so.20这个错误,找不到库文件. 但是,通过fi ...

  5. pytorch 6 batch_train 批训练

    import torch import torch.utils.data as Data torch.manual_seed(1) # reproducible # BATCH_SIZE = 5 BA ...

  6. Mybatis解决了JDBC编程哪些问题

    一:Mybatis简介 MyBatis是一个优秀的持久层框架,它对jdbc的操作数据库的过程进行封装,使开发者只需要关注 SQL 本身,而不需要花费精力去处理例如注册驱动.创建connection.创 ...

  7. 洛谷—— P1640 [SCOI2010]连续攻击游戏

    https://www.luogu.org/problem/show?pid=1640 题目描述 lxhgww最近迷上了一款游戏,在游戏里,他拥有很多的装备,每种装备都有2个属性,这些属性的值用[1, ...

  8. Android提高UI性能技巧

    提高UI性能的方法事实上有非常多在实际的开发中都已经用到了,在此做一下总结. 1.降低主线程的堵塞时间 若一个操作的耗时较长(超过5秒),我们应该将其放入后台线程中运行.仅仅在须要改动UI界面时通知主 ...

  9. OpenMp之reduction求和

    // OpenMP1.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include"omp.h" #include& ...

  10. Android sdCard路径问题

    一,获取Android设备的全部存储设备,这里边肯定有一个能用的 StorageManager sm = (StorageManager) context.getSystemService(Conte ...