sgu546 Ternary Password
题目链接: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的更多相关文章
- 2013/7/17 HNU_训练赛5
sgu 542 Gena vs Petya sgu 543 Cafe 题意:有N组人需要被分配到某些固定了人数的桌子上,其中ai表示第i组有多少个人,安排作为需要符合如下安排:某一组的人员不能够单独在 ...
- NEERC Southern Subregional 2012
NEERC Southern Subregional 2012 Problem B. Chess Championship 题目描述:有两个序列\(a, b\),两个序列都有\(n\)个数,并且这\( ...
- 打开程序总是会提示“Enter password to unlock your login keyring” ,如何成功关掉?
p { margin-bottom: 0.1in; line-height: 120% } 一.一开始我是按照网友所说的 : rm -f ~/.gnome2/keyrings/login.keyrin ...
- your password has expired.to log in you must change it
今天应用挂了,log提示密码过期.客户端连接不上. 打开mysql,执行sql语句提示密码过期 执行set password=new password('123456'); 提示成功,但客户端仍然连接 ...
- MySql Access denied for user 'root'@'localhost' (using password:YES) 解决方案
关于昨天下午说的MySQL服务无法启动的问题,解决之后没有进入数据库,就直接关闭了电脑. 今早打开电脑,开始-运行 输入"mysql -uroot -pmyadmin"后出现以下错 ...
- [上架] iOS "app-specific password" 上架问题
当你的 Apple ID 改用双重认证密码时,上架 iOS App 需要去建立一个专用密码来登入 Apple ID 才能上架. 如果使用 Application Loader 上传时,得到这个讯息: ...
- [LeetCode] Ternary Expression Parser 三元表达式解析器
Given a string representing arbitrarily nested ternary expressions, calculate the result of the expr ...
- [LeetCode] Strong Password Checker 密码强度检查器
A password is considered strong if below conditions are all met: It has at least 6 characters and at ...
- 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: 问题原因: ...
随机推荐
- Service相关--读书笔记
2013-12-30 18:16:11 1. Service和Activty都是从Context里面派生出来的,因此都可以直接调用getResource(),getContentResolver()等 ...
- 神奇的NOIP模拟赛 T3 LGTB 玩THD
LGTB 玩THD LGTB 最近在玩一个类似DOTA 的游戏名叫THD有一天他在守一座塔,对面的N 个小兵排成一列从近到远站在塔前面每个小兵有一定的血量hi,杀死后有一定的金钱gi每一秒,他都可以攻 ...
- PHP和.NET通用的加密解密函数类,均使用3DES加解密 .
以下为php代码 <PRE class=PHP name="code"> </PRE><PRE class=PHP name="code&q ...
- 记一个有想法却没能力实现的硬件产品——mp3校时闹钟
枕头旁的闹钟,我想大家都用过,很便宜.用一节干电池供电.但其最大的缺点就是不太准,不能校时. 电池啥事用光,也不知道.钟是走的很慢,没按时闹,搞的自己迟了到. 于是就有了我的漫长思考过程... 先说手 ...
- 如何获取google可以访问的IP地址
由于某些原因,google的部分网站无法打开,导致我们的好些资源都无法找到,今天在网上看到一篇文件,教大家如何能找到可以访问的google. 假如我们需要访问的是:https://code.googl ...
- 最好的Java IDE之争:Eclipse PK IntelliJ IDEA
话说,好马配好鞍,一个好的工匠,必定要有一套好的工具才能打造出最好的工艺给大家.之前,Plumbr团队里的所有成员都使用Eclipse编辑器,而如今,大家都成为IntelliJ IDEA用户.那么,到 ...
- ios 8+ (xcode 6.0 +)应用程序Ad Hoc 发布前多设备测试流程详解
我们开发的程序在经过simulator以及自己的iOS设备测试后,也基本完成应用程序了,这时候我们就可以把它发布出去了更更多的人去测试,我们可以在iOS平台使用ad hoc实现. 你在苹果购买的开发者 ...
- Map的遍历
@Test public void test() { Map<String,String> usersmap = new HashMap<>(); usersmap.put(& ...
- Ubuntu 14.10 下安装Ganglia监控集群
关于 Ganglia 软件,Ganglia是一个跨平台可扩展的,高性能计算系统下的分布式监控系统,如集群和网格.它是基于分层设计,它使用广泛的技术,如XML数据代表,便携数据传输,RRDtool用于数 ...
- Ubuntu 14.10 下安装中文输入法
系统默认带的是IBUS,这个不怎么好用,我们需要安装一个新的框架FCITX 1 打开软件中心,输入fcitx,安装flexible input method framework 2 下载需要的输入法, ...