题目链接: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. discuz 系列产品 在ie9下注册成功后不跳转bug处理

    header.htm 把 <meta http-equiv="x-ua-compatible" content="ie=7" /> 改为 <m ...

  2. 长理ACM 14-星期几(谌海军)

    题目描述:编一个程序,已知今天是星期几,计算出n天后是星期几.要求使用枚举变量. 输入描述:输入为两个正整数,第一个数n(n<=6)表示今天是星期几,第二个数m(m<=1000),表示求m ...

  3. NOIP 2013 提高组 day1 T2 火柴排队 归并 逆序对

    描述 涵涵有两盒火柴,每盒装有 n 根火柴,每根火柴都有一个高度.现在将每盒中的火柴各自排成一列,同一列火柴的高度互不相同,两列火柴之间的距离定义为:∑i=1n(ai−bi)2∑i=1n(ai−bi) ...

  4. jQuery 其他操作

    1. 样式操作 1.1 获取 class 和设置 class : class 是元素的一个属性, 所以获取 class 和设置 class 都可以使用 attr() 方法来完成. 1.2 追加样式: ...

  5. S5PV210之添加缺少的-内核提供的'.h'文件 linux3.0.8驱动

    怎样解决编译时出现内核提供的函数或变量没有定义,使用source insight搜索功能找到声明的头文件,然后包含该头件就行了: 比如: error: implicit declaration of ...

  6. hdu 1950 最长上升子序列

    //Accepted 3540 KB 62 ms //dp 最长上升子序列 #include <cstdio> #include <cstring> #include < ...

  7. uart与usart

    字面意义:UART:universal asynchronous receiver and transmitter通用异步收发器:USART:universal synchronous asynchr ...

  8. 算法导论----VLSI芯片测试; n个手机中过半是好的,找出哪些是好手机

    对于分治(Divide and Conquer)的题目,最重要是 1.如何将原问题分解为若干个子问题, 2.子问题中是所有的都需要求解,还是选择一部分子问题即可. 还有一点其实非常关键,但是往往会被忽 ...

  9. ubuntu系统安装mongodb

    安装mongodb sudo apt-get install mongodb ... ... 设置客户端连接 打开文件/etc/mongodb.conf  注意权限 修改 bind_ip=127.0. ...

  10. Python - 学习经验分享

    执行方式: 直接输入python进入命令行,进行单行输入执行,退出后不保存. python filename.py或./filename.py 直接执行脚本文件 脚本格式: #!/usr/bin/py ...