题目链接: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. 使用ASP.Net WebAPI构建REST服务(五)——客户端

    WebAPI是标准的Http协议,支持Http协议的客户端(如浏览器)都可以访问.但是,有的时候我们如果想在自己的程序中使用WebAPI时,此时就要实现自己的客户端了.我之前介绍过在.Net 4.5中 ...

  2. ionic build --release android

    ionic bulid android ionic build --release android keytool -genkey -v -keystore demo.keystore -alias ...

  3. JDBC 连接池

    数据库连接池(connection pool) JDBC数据库连接池的必要性 在使用开发基于数据库的web程序时,传统的模式基本是按以下步骤: 在主程序(如servlet.beans)中建立数据库连接 ...

  4. MBProgressHUD.h file not found

    MBProgressHUD框架,怎么我导入MBProgressHUD+MJ.h会报错.(即MBProgressHUD+MJ根本不存在),我看其他人的视屏又可以导入 MBProgressHUD.h fi ...

  5. Cisco IOS Software Activation Command Reference

    clear license agent : to clear license agent statistics counters or connection statistics (in privil ...

  6. dhtmlxScheduler日历日程控件包括天视图,周视图,月视图,年视图和日程表视图

    dhtmlxScheduler 是一个基于Web的类似于Outlook的日历日程控件. 它完全由javascript/js/css编写, 提供类似于MS Outlook Calendar, Apple ...

  7. URAL 1671 Anansi's Cobweb (并查集)

    题意:给一个无向图.每次查询破坏一条边,每次输出查询后连通图的个数. 思路:并查集.逆向思维,删边变成加边. #include<cstdio> #include<cstring> ...

  8. asp中cookie欺骗/注入原理与防范

     一直以来sql注入被广泛关注,也有专门的防注系统代码.发现,如果代码不严谨也会有cookie欺骗/注入的情况.原来, 防注入系统没有注意到 Cookies 的问题!这里以ASP为例,分析一下cook ...

  9. (转) mysql的连接,创建账号,修改密码

    原文:http://blog.chinaunix.net/uid-20749043-id-1878306.html  mysql的连接,创建账号,修改密码 2008-10-13 15:31:29 分类 ...

  10. 正确的SVN导入代码命令

    sudo svn import -m "" /media/yang/10/ubuntuFiles/svnAbout/mypro/ svn://127.0.0.1/mypro/