链接:

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的更多相关文章

  1. Educational Codeforces Round 75 (Rated for Div. 2)

    知识普及: Educational使用拓展ACM赛制,没有现场hack,比赛后有12h的全网hack时间. rank按通过题数排名,若通过题数相等则按罚时排名. (罚时计算方式:第一次通过每题的时间之 ...

  2. 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 ...

  3. 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 ...

  4. 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 ...

  5. 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 ...

  6. 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\),那么\ ...

  7. 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 ...

  8. 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 ...

  9. Educational Codeforces Round 43 (Rated for Div. 2)

    Educational Codeforces Round 43 (Rated for Div. 2) https://codeforces.com/contest/976 A #include< ...

随机推荐

  1. 有助提升编程的几个Python 技巧

    一行代码定义List 定义某种列表时,写For 循环过于麻烦,幸运的是,Python有一种内置的方法可以在一行代码中解决这个问题. 下面是使用For循环创建列表和用一行代码创建列表的对比. x = [ ...

  2. [转帖]MySQL的又一神器-锁,MySQL面试必备

    MySQL的又一神器-锁,MySQL面试必备 https://segmentfault.com/a/1190000020762791 lock 低一级的是 latch   原文链接:blog.ouya ...

  3. 随机数种子random.seed()理解

    总结: 若采用random.random(),每次都按照一定的序列(默认的某一个参数)生成不同的随机数. 若采用随机数种子random.seed(100),它将在所设置的种子100范围内调用rando ...

  4. 从零开始学Flask框架-005

    表单 Flask-WTF 项目结构 pip install flask-wtf 为了实现CSRF 保护,Flask-WTF 需要程序设置一个密钥.Flask-WTF 使用这个密钥生成加密令牌,再用令牌 ...

  5. WSL部署记录

    1. 管理员打开PowerShell,开启WSL功能: Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Sub ...

  6. linux 列出本文件下的目录

    `ls /etc` 和$(ls /etc) 是两种获取命令执行结果的方式. for file in List 的语法里面的List 就是使用使用ls /etc 的命令执行结果作为List(https: ...

  7. iview前台端口设置,跨域端口设置

    前台启动默认端口: 跨域端口: 完毕

  8. Vue使用指南(一)

    Vue Vue:前台框架 渐进式JavaScript框架 渐进式:vue可以控制页面的一个局部,vue也可以控制整个页面,vue也能控制整个前端项目     -- 根据项目需求,来决定vue控制项目的 ...

  9. 海思HI35xx平台软件开发快速入门之H264解码实例学习

    ref :https://blog.csdn.net/wytzsjzly/article/details/82500277   前言 H264视频编码技术诞生于2003年,至今已有十余载,技术相当成熟 ...

  10. VMWare打开centos,提示内部错误

    如题,VMWare打开centos,提示内部错误.该原因是因为服务被停止了之后没有将其启动,将其启动就解决了. CMD客户端输入命令 services.msc 将关于VM的服务启动就可以了