Gym 101047M Removing coins in Kem Kadrãn
给定一个序列,只能拿走D,隔壁的会翻转,问能否全部拿走。
注意到如果能拿走的话,拿D的顺序是没关系的。模拟即可
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL; #include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
const int maxn = 1e5+;
char str[maxn];
char sub[maxn]; void work ()
{
char book[];
book['B']='D';
book['D']='B';
int n;
scanf("%d",&n);
scanf("%s",str+);
strcpy(sub+,str+); int did=;
int cnt=;
vector<int>ans;
int begin=;
int flag=;
for (int i=;i<=n;++i)
{
if (str[i]=='D')
{
flag=;
cnt++;
did += cnt;
cnt=;
str[i+]=book[str[i+]];
for (int j=i;j>=begin;--j)
{
ans.push_back(j);
}
begin=i+;
}
else cnt++;
} if (did==n)
{
printf ("Y\n");
for (int i=;i<ans.size();++i)
{
printf ("%d ",ans[i]);
}
printf ("\n");
}
else printf ("N\n");
return ;
} int main()
{
#ifdef local
freopen("data.txt","r",stdin);
#endif
int t;
scanf ("%d",&t);
while(t--) work();
return ;
}
Gym 101047M Removing coins in Kem Kadrãn的更多相关文章
- ACM: Gym 101047M Removing coins in Kem Kadrãn - 暴力
Gym 101047M Removing coins in Kem Kadrãn Time Limit:2000MS Memory Limit:65536KB 64bit IO Fo ...
- Gym 101606F - Flipping Coins - [概率DP]
题目链接:https://codeforc.es/gym/101606/problem/F 题解: 假设 $f[i][j]$ 表示抛 $i$ 次硬币,有 $j$ 个硬币正面朝上的概率. 所以只有两种挑 ...
- Gym - 100712G Heavy Coins(二进制枚举)
https://vjudge.net/problem/Gym-100712G 题意:给出n枚不同价值的硬币和一个总价S,现在要选择尽量多的硬币来大于等于S,要求是比如说现在选择的硬币的总和为sum,那 ...
- Gym 101606 F-Flipping Coins(概率dp)
参考博客:http://www.cnblogs.com/kang000/p/8571071.html (这篇博客写的真的走心,ORZ) 题意有n个硬币排成一排,开始的时候所有的硬币都是正面朝下,你必 ...
- 18春季训练01-3/11 2015 ACM Amman Collegiate Programming Contest
Solved A Gym 100712A Who Is The Winner Solved B Gym 100712B Rock-Paper-Scissors Solved C Gym 100712C ...
- AGC 033
目录 A. Darker and Darker B. LRUD Game 题面 题解 代码 C. Removing Coins 题面 题解 代码 D. Complexity 题面 题解 代码 E. G ...
- AtCoder刷题记录
构造题都是神仙题 /kk ARC066C Addition and Subtraction Hard 首先要发现两个性质: 加号右边不会有括号:显然,有括号也可以被删去,答案不变. \(op_i\)和 ...
- Codeforces & Atcoder神仙题做题记录
鉴于Codeforces和atcoder上有很多神题,即使发呆了一整节数学课也是肝不出来,所以就记录一下. AGC033B LRUD Game 只要横坐标或者纵坐标超出范围就可以,所以我们只用看其中一 ...
- 【AtCoder】AGC033(A-F)
AGC033 A - Darker and Darker 直接BFS #include <bits/stdc++.h> #define fi first #define se second ...
随机推荐
- Poj 3903 Stock Exchange(LIS)
一.Description The world financial crisis is quite a subject. Some people are more relaxed while othe ...
- 【转】 Pro Android学习笔记(二九):用户界面和控制(17):include和merge
目录(?)[-] xml控件代码重用include xml控件代码重用merge 横屏和竖屏landsacpe portrait xml控件代码重用:include 如果我们定义一个控件,需要在不同的 ...
- javascript之系统对话框
浏览器通过alert(),confirm()和prompt()方法调用系统对话框,向用户显示信息. alert()接受一个字符串并显示给用户,结果是显示一个对话框,其中包括指定的文本和一个OK(“确定 ...
- 面试题: mysql数据库 已看1 简单的sql练习
数据库总结--MySQL常见面试题 2015年03月24日 17:56:06 阅读数:7787 1.根据部门号从高到低,工资从低到高列出员工的信息 select * from employee ord ...
- Spring 框架学习整理
JDBC操作数据库的基本入门中存在什么问题? * 导致驱动注册两次是个问题,但不是严重的. * 严重的问题:是当前类和mysql的驱动类有很强的依赖关系. * 当我们没有驱动类的时候 ...
- Spring入门第二十八课
事务的传播行为 当事务方法被另一个事务方法调用时,必须指定事务应该如何传播,例如:方法可能继续在现有事务中运行,也可能开启一个新的事务,并在自己的事务中运行. 事务的传播行为可以由传播属性指定.Spr ...
- Python短小精悍的Orator查询构造器
查询构造器 介绍 这个数据库查询构造器,提供便利的接口可以创建和执行查询操作,可以在大多数数据库中使用. 查询select操作 查询表中所有的数据. users = db.table('users') ...
- js注册
ScriptManager.RegisterStartupScript(this, GetType(), "", "alert('修改失败!')", true) ...
- 微信小程序-获取当前城市位置
CSDN链接 https://blog.csdn.net/weixin_42262436/article/details/80458430
- VS Code 缩小
一.问题描述 当我们在使用 Visual Studio Code 时,放大,我们可以使用 “ CTRL + ” 快捷键来实现.在使用 “ CRRL - ” 快捷键,缩小不了,我们怎么办? 二.解决方案 ...