链接:

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;
}

最新文章

  1. MyBatis学习总结(三)&mdash;&mdash;优化MyBatis配置文件中的配置
  2. sql 解析字符串添加到临时表中 sql存储过程in 参数输入
  3. JAVA条件语句
  4. WWF3自定义活动&lt;第八篇&gt;
  5. HDOJ 1050 Moving Tables
  6. [Java] SSH框架笔记_S2SH整合步骤
  7. linux_机器信息查询
  8. Maven属性、profile和资源过滤
  9. 了解JVM
  10. localhost 与 127.0.0.1 的区别
  11. python打包成exe
  12. java实现字符串匹配问题之求两个字符串的最大公共子串
  13. SVN的CheckOut操作和Export操作的区别
  14. CodeForces 705B Spider Man
  15. iOS- 解决iOS10 App启动时放大铺满App Icon的问题
  16. Leetcode解题-链表(2.2.2)ReverseLinkedList
  17. SVD/SVD++实现推荐算法
  18. 【linux】/dev/null作用和/dev/random
  19. Redis详解(七)------ AOF 持久化
  20. #mxnet# 权值共享

热门文章

  1. pytorch1.0神经网络保存、提取、加载
  2. todo---java中的json探讨
  3. C++开发新版本vs使用旧版本vs编译的静态库动态库
  4. python数据库基础
  5. Python socket编程 (2)--实现文件验证登入
  6. 监控SQL:通过SQL Server的DML触发器来监控哪些IP对表的数据进行了修改(2)
  7. dll库生成和使用
  8. iOS - starckView 类似Android线性布局
  9. stm32 触摸屏 XPT2046
  10. Source Insight用法