Codeforces 803E - Roma and Poker
2 seconds
256 megabytes
standard input
standard output
Each evening Roma plays online poker on his favourite website. The rules of poker on this website are a bit strange: there are always two players in a hand, there are no bets, and the winner takes 1 virtual bourle from the loser.
Last evening Roma started to play poker. He decided to spend no more than k virtual bourles — he will stop immediately if the number of his loses exceeds the number of his wins by k. Also Roma will leave the game if he wins enough money for the evening, i.e. if the number of wins exceeds the number of loses by k.
Next morning Roma found a piece of paper with a sequence on it representing his results. Roma doesn't remember the results exactly, and some characters in the sequence are written in a way such that it's impossible to recognize this character, so Roma can't recall whether he won k bourles or he lost.
The sequence written by Roma is a string s consisting of characters W (Roma won the corresponding hand), L (Roma lost), D (draw) and? (unknown result). Roma wants to restore any valid sequence by changing all ? characters to W, L or D. The sequence is called valid if all these conditions are met:
- In the end the absolute difference between the number of wins and loses is equal to k;
- There is no hand such that the absolute difference before this hand was equal to k.
Help Roma to restore any such sequence.
The first line contains two numbers n (the length of Roma's sequence) and k (1 ≤ n, k ≤ 1000).
The second line contains the sequence s consisting of characters W, L, D and ?. There are exactly n characters in this sequence.
If there is no valid sequence that can be obtained from s by replacing all ? characters by W, L or D, print NO.
Otherwise print this sequence. If there are multiple answers, print any of them.
3 2
L??
LDL
3 1
W??
NO
20 5
?LLLLLWWWWW?????????
WLLLLLWWWWWWWWLWLWDW 题意:
有n场比赛,给出一个k值,每场比赛的结果用W表示胜,L表示败,D表示平, ? 表示未知
?处可以自定义 胜负平
问是否有一个序列满足以下2个要求,有则输出序列,无则输出NO
设前i场胜W【i】,负L【i】
1、前n-1场中,不能有|W[i]-L[i]|>=k
2、最后一场,|W[n]-L[n]|=k
f[i][j]表示前i场W[i]-L[i]的差为j
差可能为负,整体后移n位
#include<cstdio>
#include<iostream>
using namespace std;
int n,m;
char ch[];
bool f[][];
int main()
{
scanf("%d%d",&n,&m);
scanf("%s",ch+);
f[][n+]=true;
for(int i=;i<=n;i++)
for(int j=n-i+;j<=n+i+;j++)
if(i!=n&&(j<=n-m+||j>=n+m+)) continue;
else if(ch[i]=='L'&&f[i-][j+]) f[i][j]=true;
else if(ch[i]=='W'&&f[i-][j-]) f[i][j]=true;
else if(ch[i]=='D'&&f[i-][j]) f[i][j]=true;
else if(ch[i]=='?'&&(f[i-][j-]||f[i-][j+]||f[i-][j])) f[i][j]=true;
if(!f[n][n-m+]&&!f[n][n+m+]) puts("NO");
else
{
int now;
if(f[n][n+m+]) now=n+m+;
else now=n-m+;
for(int i=n;i>;i--)
if(ch[i]=='L') now++;
else if(ch[i]=='W') now--;
else if(ch[i]=='?')
{
if(f[i-][now-]) ch[i]='W',now--;
else if(f[i-][now+]) ch[i]='L',now++;
else ch[i]='D';
}
if(now==n+) ch[]='D';
else if(now==n) ch[]='L';
else ch[]='W';
printf("%s",ch+);
}
}
Codeforces 803E - Roma and Poker的更多相关文章
- AC日记——Roma and Poker codeforces 803e
803E - Roma and Poker 思路: 赢或输或者平的序列: 赢和平的差的绝对值不得超过k: 结束时差的绝对值必须为k: 当“?”时可以自己决定为什么状态: 输出最终序列或者NO: dp( ...
- 【codeforces 803E】Roma and Poker
[题目链接]:http://codeforces.com/contest/803/problem/E [题意] 给你一个不完整的胜负平序列(不完整是指中间有些地方为问号,让你自己选择胜负平) 让你复原 ...
- Educational Codeforces Round 20 E - Roma and Poker(dp)
传送门 题意 Roma在玩一个游戏,一共玩了n局,赢则bourle+1,输则bourle-1,Roma将会在以下情况中退出 1.他赢了k个bourle 2.他输了k个bourle 现在给出一个字符串 ...
- CodeForces 573A Bear and Poker
题目链接:http://codeforces.com/problemset/problem/573/A 题目大意:此题要求一组数中的元素乘以2或者乘以3后得到的数都一样,其实就是判断这些数除去2和3这 ...
- codeforces B. Roma and Changing Signs 解题报告
题目链接:http://codeforces.com/problemset/problem/262/B 题目意思:给出 n 个数和恰好一共要做的操作总数k.通过对n个数进行k次操作,每次操作可以把a[ ...
- Educational Codeforces Round 20
Educational Codeforces Round 20 A. Maximal Binary Matrix 直接从上到下从左到右填,注意只剩一个要填的位置的情况 view code //#pr ...
- Codeforces Round #318 [RussianCodeCup Thanks-Round] (Div. 1) A. Bear and Poker 分解
A. Bear and Poker Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/573/pro ...
- Codeforces Round #318 [RussianCodeCup Thanks-Round] (Div. 2)C. Bear and Poker
C. Bear and Poker ...
- Codeforces Round #160 (Div. 2)---A. Roma and Lucky Numbers
Roma and Lucky Numbers time limit per test 1 second memory limit per test 256 megabytes input standa ...
随机推荐
- Alpha发布_文案+美工
团队名称:探路者 1蔺依铭:http://www.cnblogs.com/linym762/ 2张恩聚:http://www.cnblogs.com/zej87/ 3米赫:http://www.cnb ...
- C++ Primer Plus学习:第十三章
第十三章 类继承 继承的基本概念 类继承是指从已有的类派生出新的类.例: 表 0-1 player.h class player { private: string firstname; string ...
- n元一维向量向左循环移位i的几种算法
1.最简单的算法借助于一个n元的中间向量在n步时间内完成 时间复杂度:O(n) 空间复杂度O(n) void shift_easy(int arr[], int _arr[], int n, int ...
- Servlet处理表单
- (十一)Jmeter另一种调试工具 HTTP Mirror Server
之前我介绍过Jmeter的一种调试工具Debug Sampler,它可以输出Jmeter的变量.属性甚至是系统属性而不用发送真实的请求到服务器.既然这样,那么HTTP Mirror Server又是做 ...
- django amdin页面下拉列表的外键增加条件过滤
class MenuList(admin.ModelAdmin): list_display = ('menuId', 'menuName', 'menuDesc', 'menuType', 'sor ...
- ASP.NET存储Session的StateServer
由于公司要对服务器做个负载均衡,所以Web项目在两台前端服务器(web1.web2)各部署了一份.但是在项目中会用到session.当一开始在web1上登陆后,由于web1之后负载可能会变大,就有可能 ...
- java之静态代理与动态代理
先看看静态代理是如何操作的 定义接口: public interface Person { public void sayHello(String content, int age); public ...
- Web前端面试宝典(最新)
第一部分:HTML问答题 1.简述一下你对HTML语义化的理解? 用正确的标签做正确的事情. html语义化让页面的内容结构化,结构更清晰,便于对浏览器.搜索引擎解析;即使在没有样式CSS情况下也 ...
- 【Java】JAVA开发人员常见环境工具安装
1.安装配置JDK1.7:jdk-7u45-windows-x64.exe,环境变量配置:JAVA_HOME---[F:\1024\jdk1.7],CLASSPATH---[.;%JAVA_HOME% ...