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 ...
随机推荐
- Java:有关自定数组的学习
Java:有关==自定数组==的学习 在 ==<Java程序设计与数据结构教程>== 里我在==P212~P213==页看到一个GradeRange的程序,它用的数组是自定设定的Grade ...
- ubuntu关闭系统自动检测错误
sudo gedit /etc/default/apport 将enabled=1 改成 enabled=0
- jdbc 2.0
1.Statement接口不能接受参数 2.PreparedStatement接口在运行时接受输入参数 3.CallableStatement接口也可以接受运行时输入参数,当想要访问数据库存储过程时使 ...
- 201621123037 《Java程序设计》第6周学习总结
作业06-接口.内部类 1. 本周学习总结 1.1 面向对象学习暂告一段落,请使用思维导图,以封装.继承.多态为核心概念画一张思维导图或相关笔记,对面向对象思想进行一个总结. 注1:关键词与内容不求多 ...
- 更改HTTP头信息
http信息分三部分 1.请求行 GET lizi.php HTTP/1.1 2.HTTP头信 Host: localhost Connection: keep-alive Cache-Contr ...
- gridview 第一行编辑
<%@ Page Language="C#" AutoEventWireup="true" Codebehind="Default.aspx.c ...
- ADO之connection
connection 主要成员 connectionstring 属性 连接字符串 open() 打开数据库连接 close() ...
- SpringMVC Ajax两种传参方式
1.采用@RequestParam或Request对象获取参数的方法 注:contentType必须指定为:application/x-www-form-urlencoded @ResponseBod ...
- mvc4中使用angularjs实现一个投票系统
数据库是用EF操作,数据表都很简单中,从代码中也能猜出表的结构,所以关于数据库表就不列出了 投票系统实现还是比较简单,投票部分使用ajax实现,评论部分是使用angularjs实现,并且页面每隔几秒( ...
- luogu 1360 阵容均衡(前缀和+差分+hash)
要求一段最大的区间里每个能力的增长值是一样的. 我们首先求一遍前缀和,发现,如果区间内[l,r]每个能力的增长值是一样的话,那么前缀和[r]和[l-1]的差分也应该是一样的. 那么我们把前缀和的差分h ...