题目链接:http://acm.sgu.ru/problem.php?contest=0&problem=546

这题还好,1Y,考虑情况周全,就没问题了,还好提交之前把想到的情况都测试了一遍..

 #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
char s[];
int n, a, b, a0[], b0[];
int main(void) {
//freopen("in.txt", "r", stdin);
while (~scanf("%d%d%d%s", &n, &a, &b, s)) {
int a1 = , b1 = ;
for (int i = ;i < n; ++i) {
if (s[i] == '') a0[a1] = i, a1++; else if (s[i] == '') b0[b1] = i, b1++;
}
if (a1 == a && b1 == b) printf("0\n%s\n", s);
else if (a+b>n) printf("-1\n");
else {
int cnt = , a2 = , b2 = ;
a2 = a1-a, b2 = b1-b;
if (a1 < a) {
for (int f = ; f < b2 && a1 < a; ++f) s[b0[f]] = '', cnt++, a1++, b1--;
if (a1 < a) {
for (int e = ; e < n && a1 < a; ++e) if (s[e] == '') s[e] = '', cnt++, a1++;
}
}
if (b1 < b) {
for (int f = ; f < a2 && b1 < b; ++f) s[a0[f]] = '', cnt++, b1++, a1--;
if (b1 < b) {
for (int e = ; e < n && b1<b; ++e) if (s[e] == '') s[e] = '', cnt++, b1++;
}
}
if (a1 > a) {
for (int f = ; f < n && a1 > a; ++f) if (s[f] == '') a1--, s[f] = '', cnt++;
}
if (b1 > b) {
for (int f = ; f < n && b1 > b; ++f) if (s[f] == '') b1--, s[f] = '', cnt++;
}
printf("%d\n%s\n", cnt, s);
}
} return ;
}

只是我的方法貌似比较笨==

sgu546 Ternary Password的更多相关文章

  1. 2013/7/17 HNU_训练赛5

    sgu 542 Gena vs Petya sgu 543 Cafe 题意:有N组人需要被分配到某些固定了人数的桌子上,其中ai表示第i组有多少个人,安排作为需要符合如下安排:某一组的人员不能够单独在 ...

  2. NEERC Southern Subregional 2012

    NEERC Southern Subregional 2012 Problem B. Chess Championship 题目描述:有两个序列\(a, b\),两个序列都有\(n\)个数,并且这\( ...

  3. 打开程序总是会提示“Enter password to unlock your login keyring” ,如何成功关掉?

    p { margin-bottom: 0.1in; line-height: 120% } 一.一开始我是按照网友所说的 : rm -f ~/.gnome2/keyrings/login.keyrin ...

  4. your password has expired.to log in you must change it

    今天应用挂了,log提示密码过期.客户端连接不上. 打开mysql,执行sql语句提示密码过期 执行set password=new password('123456'); 提示成功,但客户端仍然连接 ...

  5. MySql Access denied for user 'root'@'localhost' (using password:YES) 解决方案

    关于昨天下午说的MySQL服务无法启动的问题,解决之后没有进入数据库,就直接关闭了电脑. 今早打开电脑,开始-运行 输入"mysql -uroot -pmyadmin"后出现以下错 ...

  6. [上架] iOS "app-specific password" 上架问题

    当你的 Apple ID 改用双重认证密码时,上架 iOS App 需要去建立一个专用密码来登入 Apple ID 才能上架. 如果使用 Application Loader 上传时,得到这个讯息: ...

  7. [LeetCode] Ternary Expression Parser 三元表达式解析器

    Given a string representing arbitrarily nested ternary expressions, calculate the result of the expr ...

  8. [LeetCode] Strong Password Checker 密码强度检查器

    A password is considered strong if below conditions are all met: It has at least 6 characters and at ...

  9. mysql 错误 ERROR 1372 (HY000): Password hash should be a 41-digit hexadecimal number 解决办法

    MySQL创建用户(包括密码)时,会提示ERROR 1372 (HY000): Password hash should be a 41-digit hexadecimal number: 问题原因: ...

随机推荐

  1. C#解析Json(多方法解析Json 一)

    解析:{'id':'4028d80858053bed0158053ef7a50001','sl':0.0,'sfyfz':'0','zwjyzsbh':'1000001600000018'} 1.新建 ...

  2. select2 插件

    官网:http://select2.github.io/ Select2是基于jQuery的一个插件,没有引用jQuery,是没有效果的   1.在实现给select2添加placeholder效果的 ...

  3. WinForm 中 VScrollBar Maximum 问题

    最近在做一个鼠标经过弹出 TreeView  面板功能 , 要求鼠标离开TreeView区域,隐藏面板. 功能如期开发,其中当TreeView 出现滚动条时,鼠标经过TreeView中的滚动条时,提前 ...

  4. SharePoint 2013 开发——工作流架构

    博客地址:http://blog.csdn.net/FoxDave SharePoint 2013的工作流较之前有了不同,第一次真正地作为独立的服务的概念推出了.这意味着SharePoint工作流不再 ...

  5. C# HttpBrowser 跨进程访问,解决内存泄露问题

    #undef DEBUG using Microsoft.Win32; using Newtonsoft.Json; using System; using System.Collections.Ge ...

  6. 数据库范式(1NF 2NF 3NF BCNF)详解一

    数据结构设计模式编程制造 数据库的设计范式是数据库设计所需要满足的规范,满足这些规范的数据库是简洁的.结构明晰的,同时,不会发生插入(insert).删除(delete)和更新(update)操作异常 ...

  7. 为自己的系统定制openstack ceilometer

    一.目的 最近研究了一下ceilometer,目的做一个监控系统,对系统中发生的事件进行处理.ceilometer对openstack各个组件信息的收集方式主要由 推 和  拉 两种. “推”: 就是 ...

  8. ISO c++11 does not allow conversion from string literal to 'char*'

    http://stackoverflow.com/questions/9650058/deprecated-conversion-from-string-literal-to-char

  9. 自定义UIPageControl圆点的图片

    iphone的UIPageControl控件可以显示用户huan'dong滑动到的页码.但是里面的小点的颜色时默认的白色.如果背景也是白色的hu话,你就悲剧了.于是乎上网找了一些资料,找到了改变UIP ...

  10. MySQL内置函数

    MySQL中的内置系统函数 用在SELECT语句,以及字句where  order by   having 中UPDTE   DELETE 函数中可以将字段名作为变量来用,变量的值就是这个列对应的每一 ...