Educational Codeforces Round 75 (Rated for Div. 2) B. Binary Palindromes
链接:
https://codeforces.com/contest/1251/problem/B
题意:
A palindrome is a string t which reads the same backward as forward (formally, t[i]=t[|t|+1−i] for all i∈[1,|t|]). Here |t| denotes the length of a string t. For example, the strings 010, 1001 and 0 are palindromes.
You have n binary strings s1,s2,…,sn (each si consists of zeroes and/or ones). You can swap any pair of characters any number of times (possibly, zero). Characters can be either from the same string or from different strings — there are no restrictions.
Formally, in one move you:
choose four integer numbers x,a,y,b such that 1≤x,y≤n and 1≤a≤|sx| and 1≤b≤|sy| (where x and y are string indices and a and b are positions in strings sx and sy respectively),
swap (exchange) the characters sx[a] and sy[b].
What is the maximum number of strings you can make palindromic simultaneously?
思路:
考虑所有串的长度,当有奇数长度存在时,保证可以交换出全部,当没有时, 可能存在0或1为奇数,不能配对,有奇数可以将奇数减位,同时保证剩下的偶数相等。
代码:
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
int n;
string s;
int main()
{
int t;
scanf("%d", &t);
while(t--)
{
int one = 0, zer = 0;
int q = 0;
scanf("%d", &n);
for (int i = 1;i <= n;i++)
{
cin >> s;
int len = (int)s.length();
if (len%2)
q++;
for (int j = 0;j < len;j++)
{
if (s[j] == '0')
zer++;
else
one++;
}
}
if (q > 0)
printf("%d\n", n);
else
{
if (one%2 || zer%2)
printf("%d\n", n-1);
else
printf("%d\n", n);
}
}
return 0;
}
Educational Codeforces Round 75 (Rated for Div. 2) B. Binary Palindromes的更多相关文章
- Educational Codeforces Round 75 (Rated for Div. 2)
知识普及: Educational使用拓展ACM赛制,没有现场hack,比赛后有12h的全网hack时间. rank按通过题数排名,若通过题数相等则按罚时排名. (罚时计算方式:第一次通过每题的时间之 ...
- Educational Codeforces Round 75 (Rated for Div. 2) D. Salary Changing
链接: https://codeforces.com/contest/1251/problem/D 题意: You are the head of a large enterprise. n peop ...
- Educational Codeforces Round 75 (Rated for Div. 2) C. Minimize The Integer
链接: https://codeforces.com/contest/1251/problem/C 题意: You are given a huge integer a consisting of n ...
- Educational Codeforces Round 75 (Rated for Div. 2) A. Broken Keyboard
链接: https://codeforces.com/contest/1251/problem/A 题意: Recently Polycarp noticed that some of the but ...
- Educational Codeforces Round 75 (Rated for Div. 2)D(二分)
#define HAVE_STRUCT_TIMESPEC#include<bits/stdc++.h>using namespace std;pair<int,int>a[20 ...
- Educational Codeforces Round 94 (Rated for Div. 2) C. Binary String Reconstruction (构造)
题意:给你一个字符串\(s\),原字符串为\(w\),如果\(i>x\)且\(w_{i-x}=1\),那么\(s_{i}=1\),如果\(i+x\le n\)且\(w_{i+x}=1\),那么\ ...
- Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship
Problem Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship Time Limit: 2000 mSec P ...
- Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems(动态规划+矩阵快速幂)
Problem Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems Time Limit: 3000 mSec P ...
- Educational Codeforces Round 43 (Rated for Div. 2)
Educational Codeforces Round 43 (Rated for Div. 2) https://codeforces.com/contest/976 A #include< ...
随机推荐
- zblog安装环境介绍?zblog安装需要什么环境
最近在群里看到很的多人有在问:“安装zblog需要什么环境?”,其实这个问题在zblog官网的程序下载页面有说明,但是不太详细,那么本文的目的就是来给大家介绍下zblog安装环境详细说明. zblog ...
- WUSTOJ 1315: 杜学霸和谭女神(Java)
题目链接:
- 二十四、V4L2框架主要结构体分析和虚拟摄像头驱动编写
一.V4L2框架主要结构体分析 V4L2(video for linux version 2),是内核中视频设备的驱动框架,为上层访问视频设备提供统一接口. V4L2整体框架如下图: 图中主要包括两层 ...
- iTunes向ipad传影片
iTunes向ipad传影片(方法一) 在电脑上用itunes传视频到ipad-百度经验 iTunes向ipad传影片(方法二)
- k8s安装ingress
1. 环境准备 安装nginx-ingress-controller和backend cd /etc/yum.repos.d/mainfests 下载镜像的脚本 vi ingressnginx.sh ...
- 线程一(lock)
对于线程同步操作最简单的一种方式就是使用 lock 关键字,通过 lock 关键字能保证加锁的线程只有在执行完成后才能执行其他线程. lock 的语法形式如下. lock(object) { ...
- vue的data里面的值是数组时,在更改其某一项的时候,怎么触发视图的重新渲染?
1. 设置对象或数组的值:Vue.set(target,key,value) :2.删除对象或数组中元素: Vue.delete ( target,key) ;3. 数组对象直接修改属性,可以触发视图 ...
- python识别文字tesseract
Ubuntu版本: .tesseract-ocr安装 sudo apt-get install tesseract-ocr .pytesseract安装 sudo pip install pytess ...
- java web 监控cpu、内存等。hyperic-sigar
用到一个插件hyperic-sigar 1:下载hyperic-sigar后解压,把sigar-amd64-winnt.dll(64位机器,32位用sigar-x86-winnt.dll)放到你本机的 ...
- RestFramework之权限组件
一.权限组件的使用 1.首先需要导入包 from rest_framework.permissions import BasePermission 2.编写权限类 class VipPermissio ...