【codeforces 67A】Partial Teacher
【题目链接】: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的更多相关文章
- 【codeforces 415D】Mashmokh and ACM(普通dp)
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
- 【24.34%】【codeforces 560D】Equivalent Strings
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【codeforces 758C】Unfair Poll
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【22.73%】【codeforces 606D】Lazy Student
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【codeforces 707E】Garlands
[题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...
- 【codeforces 707C】Pythagorean Triples
[题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...
- 【codeforces 709D】Recover the String
[题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...
- 【codeforces 709B】Checkpoints
[题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...
- 【codeforces 709C】Letters Cyclic Shift
[题目链接]:http://codeforces.com/contest/709/problem/C [题意] 让你改变一个字符串的子集(连续的一段); ->这一段的每个字符的字母都变成之前的一 ...
随机推荐
- [CodeForces]500B New Year Permutation
刷水题做几道入门贪心题预热... 找联通块里字典序最小的放到最前面即可.记得写传递闭包 #include <iostream> #include <cstdio> #inclu ...
- Linux学习01
Linux学习第一天 1.使用VM安装RHEL7.0 具体参见刘遄老师的<Linux就该怎么学>https://www.linuxprobe.com/chapter-01.html 2.R ...
- 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 ...
- 紫书 例题8-1 UVa 120(构造法)
#include<cstdio> #include<iostream> #include<sstream> #include<algorithm> #d ...
- JQuery封装ajax的方法
1.$.post方法 $.post(url[,data][,callback][,type]) url:请求的后台程序地址 data:发送到后台的数据 callback:载入成功时回调函数,该函数参数 ...
- div,span等标签支持focus/blur事件
<div tabindex="0" hidefocus="true" onfocus='alert("得到焦点");' onblur= ...
- 如何在 Linux 上安装 Nginx (源码安装)
如何在 Linux( CentOS ) 上安装 Nginx 1.下载 nginx 链接 : https://pan.baidu.com/s/1sll0Hrf 密码 : xnem 2.安装 gcc ( ...
- 编写html经常使用而又easy忘记的语句
设置文件字符编码: <meta charset="utf-8"> 内部样式表: <style type="text/css"> hr { ...
- leetcode第一刷_Subsets II
要求子集,有很现成的方法.N个数.子集的个数是2^N.每一个元素都有在集合中和不在集合中两种状态,这些状态用[0,pow(2,N)]中每一个数来穷举,假设这个数中的第i位为1,说明当前集合中包括源数组 ...
- 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 ...