Codeforces Gym 100203E bits-Equalizer 贪心
原题链接:http://codeforces.com/gym/100203/attachments/download/1702/statements.pdf
题解
考虑到交换可以减少一次操作,那么可以的话就尽量交换,设问号的个数是z,上面是1下面是0的个数是x,反过来的是y,那么最后的答案就是z+min(x,y)+abs(x-y)。代码是队友写的,我是嘴炮流选手。
代码
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <string.h>
#include <queue>
#include <ctime>
#include <cmath>
#include <set>
#include <stack>
#include <map>
#define eps 1e-10
#define MAXN 500010
#define INF 2*0x3f3f3f3f
using namespace std; int T;
char str1[], str2[]; int main() {
//freopen("in.in", "r", stdin);
//freopen("out.out", "w", stdout);
scanf("%d", &T);
for (int cas = ; cas <= T; cas++) {
scanf("%s %s", str1, str2);
int len = strlen(str1);
int x = , y = , z = ;
for (int i = ; i < len; i++) if (str1[i] != '') x++;
for (int i = ; i < len; i++) if (str2[i] != '') y++;
if (x < y) printf("Case %d: %d\n", cas, -);
else {
x = y = z = ;
for (int i = ; i < len; i++) {
if (str1[i] == '?') z++;
else if (str1[i] == '' && str2[i] == '') x++;
else if (str1[i] == '' && str2[i] == '') y++;
}
printf("Case %d: %d\n", cas, z + min(x, y) + abs(y - x));
}
}
return ;
}
Codeforces Gym 100203E bits-Equalizer 贪心的更多相关文章
- Codeforces Gym 100203E E - bits-Equalizer 贪心
E - bits-EqualizerTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest ...
- Codeforces Gym 100269E Energy Tycoon 贪心
题目链接:http://codeforces.com/gym/100269/attachments 题意: 有长度为n个格子,你有两种操作,1是放一个长度为1的东西上去,2是放一个长度为2的东西上去 ...
- codeforces Gym 100338E Numbers (贪心,实现)
题目:http://codeforces.com/gym/100338/attachments 贪心,每次枚举10的i次幂,除k后取余数r在用k-r补在10的幂上作为候选答案. #include< ...
- CodeForces Gym 100685I Innovative Business (贪心)
题意:给定一条路的长和宽,然后给你瓷砖的长和宽,你只能横着或者竖着铺,也可以切成片,但是每条边只能对应一条边,问你最少要多少瓷砖. 析:先整块整块的放,然后再考虑剩下部分,剩下的再分成3部分,先横着, ...
- Codeforces GYM 100876 J - Buying roads 题解
Codeforces GYM 100876 J - Buying roads 题解 才不是因为有了图床来测试一下呢,哼( 题意 给你\(N\)个点,\(M\)条带权边的无向图,选出\(K\)条边,使得 ...
- Codeforces Gym 101252D&&floyd判圈算法学习笔记
一句话题意:x0=1,xi+1=(Axi+xi%B)%C,如果x序列中存在最早的两个相同的元素,输出第二次出现的位置,若在2e7内无解则输出-1. 题解:都不到100天就AFO了才来学这floyd判圈 ...
- Codeforces gym 101343 J.Husam and the Broken Present 2【状压dp】
2017 JUST Programming Contest 2.0 题目链接:Codeforces gym 101343 J.Husam and the Broken Present 2 J. Hu ...
- CodeForces Gym 100213F Counterfeit Money
CodeForces Gym题目页面传送门 有\(1\)个\(n1\times m1\)的字符矩阵\(a\)和\(1\)个\(n2\times m2\)的字符矩阵\(b\),求\(a,b\)的最大公共 ...
- uva12545 Bits Equalizer
uva12545 Bits Equalizer You are given two non-empty strings S and T of equal lengths. S contains the ...
随机推荐
- matplotlib学习记录 五
# 绘制电影票房竖条形图 from matplotlib import pyplot as plt a = ["战狼2","速度与激情8","功夫瑜伽 ...
- 小谈python里 列表 的几种常用用法
在python中列表的常用方法主要包括增加,删除,查看和修改.下面以举例子的方法具体说明,首先我们创建两个列表,列表是用[ ]表示的,里面的元素用逗号隔开. a=[‘hello’,78,15.6,‘你 ...
- Python如何查看变量在内存中的地址
在python中可以用id()函数获取对象的内存地址. 用法: object = 1 + 2 object -- 对象
- build.xml: 21: Class not found: javac1.8
在eclipse里运用ant时经常碰到class not found的错误提示,从而编译失败,其实是eclipse中本身的ant版本太老造成该的,但我今天安装的ant是1.8.4,感觉已经很新了,但编 ...
- PHP GD库---之头像合成九宫格
public function createMosaicGroupAvatar($pic_list = array(), $bg_w = 396, $bg_h = 396) { if (!$pic_l ...
- Python动态属性和特性(一)
在Python中,数据的属性和处理数据的方法统称为属性.其实,方式只是可调用的属性.除了这二者之外,我们还可以创建特性(property),在不改变类接口的前提下,使用存取方法(即读取值和设置值方法) ...
- 初试webpack打包
第一次接触webpack,学习了如何用webpack打包,记录一下过程. 1.在项目根目录安装webpack $ npm install webpack --save-dev 2.新建一个webpac ...
- Selenium WebDriver-模拟鼠标双击某个元素
#encoding=utf-8 import unittest import time import chardet from selenium import webdriver class Visi ...
- python + selenium - selenium简介
1. 产品简介 selenium 是 基于 web网页的UI自动化测试框架. 1)支持多浏览器操作:ie.chrome.firefox.edge.safaria等 2)跨平台:windows.linu ...
- 【LeetCode】Balanced Binary Tree(平衡二叉树)
这道题是LeetCode里的第110道题. 题目要求: 给定一个二叉树,判断它是否是高度平衡的二叉树. 本题中,一棵高度平衡二叉树定义为: 一个二叉树每个节点 的左右两个子树的高度差的绝对值不超过1. ...