题目链接: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. 其他窗体赋值给comboBox实现值的回显,并使赋的值处于选中状态(根据text获取selectedindex)

    Form1 发货单位的这个下拉框comboBox1已经绑定数据库test表的name字段,里面有很多单位名称 比如有:甲公司.乙公司... 1.Form1的comboBox1首先绑定数据库的数据表te ...

  2. Python中的sorted函数以及operator.itemgetter函数 【转载】

    operator.itemgetter函数operator模块提供的itemgetter函数用于获取对象的哪些维的数据,参数为一些序号(即需要获取的数据在对象中的序号),下面看例子. a = [1,2 ...

  3. Android 之 数据存储

    在Android操作系统中,提供了5种数据存储方式:SharedPreferences存储,文件存储,SQLite数据库存储,ContentProvider存储和网络存储. 一.SharedPrefe ...

  4. LOGISTIC REGRESSION

    In logistic regression we learn a family of functions

  5. IOS UTF8中文字母数字 组合时长度截取

    //计算总共字数和限制字数的Index位置 -(NSMutableArray *) unicodeLengthOfString: (NSString *) text { NSMutableArray ...

  6. Listview没有优化之前

    MainActivity.java package com.example.listviewdemo4; import java.util.ArrayList; import java.util.Ha ...

  7. JSON.parse()和JSON.stringify() 的用法区别

    parse用于从一个字符串中解析出json对象,如 var str = '{"name":"huangxiaojian","age":&qu ...

  8. 中文Ubuntu系统根目录文件夹名称变为英文

    Ubuntu中文安装后,家目录均为中文,如“下载” “文档”等等,在使用Shell时很不方便,可用如下方法将这些文件夹名称改回英文 1.使用命令 export LANG=en_US xdg-user- ...

  9. IOS使用Asyncsocket进行socket编程

    iphone的标准推荐CFNetwork C库编程.但是编程比较烦躁.在其它OS往往用类来封装的对Socket函数的处理.比如MFC的CAsysncSocket.在iphone也有类似于开源项目.co ...

  10. UIKit框架之UIlabel

    1.继承链:UIview:UIresponder:NSObject 2.如果你想要使UIlabel能够和用户进行互动,需要把它实例变量的属性 userInteractionEnabled改为yes 3 ...