CODE FESTIVAL 2017 qual A C
来源:互联网 发布:淘宝店铺过户新规 编辑:程序博客网 时间:2024/06/08 04:10
C - Palindromic Matrix
Time limit : 2sec / Memory limit : 256MB
Score : 400 points
Problem Statement
We have an H-by-W matrix. Let aij be the element at the i-th row from the top and j-th column from the left. In this matrix, each aij is a lowercase English letter.
Snuke is creating another H-by-W matrix, A’, by freely rearranging the elements in A. Here, he wants to satisfy the following condition:
Every row and column in A’ can be read as a palindrome.
Determine whether he can create a matrix satisfying the condition.
Note
A palindrome is a string that reads the same forward and backward. For example, a, aa, abba and abcba are all palindromes, while ab, abab and abcda are not.
Constraints
1≤H,W≤100
aij is a lowercase English letter.
Input
Input is given from Standard Input in the following format:
H W
a11a12…a1W
:
aH1aH2…aHW
Output
If Snuke can create a matrix satisfying the condition, print Yes; otherwise, print No.
Sample Input 1
Copy
3 4
aabb
aabb
aacc
Sample Output 1
Copy
Yes
For example, the following matrix satisfies the condition.
abba
acca
abba
Sample Input 2
Copy
2 2
aa
bb
Sample Output 2
Copy
No
It is not possible to create a matrix satisfying the condition, no matter how we rearrange the elements in A.
Sample Input 3
Copy
5 1
t
w
e
e
t
Sample Output 3
Copy
Yes
For example, the following matrix satisfies the condition.
t
e
w
e
t
Sample Input 4
Copy
2 5
abxba
abyba
Sample Output 4
Copy
No
Sample Input 5
Copy
1 1
z
Sample Output 5
Copy
Yes
思维,数学
#include <iostream>#include <stdio.h>#include <string.h>#include <algorithm>#include <vector>#include <string>using namespace std;char str[111][111];int a[30];int main(){ int h,w; scanf("%d %d",&h,&w); for(int i=0;i<h;i++){ scanf("%s",str[i]); for(int j=0;j<w;j++){ a[str[i][j]-'a'+1]++; } } int g1=(h%2)*(w%2); int g2=(h/2)*(w%2)+(w/2)*(h%2); int g3=(h/2)*(w/2); for(int i=1;i<=26;i++){ g3-=(a[i]/4); a[i]%=4; g2-=(a[i]/2); a[i]%=2; g1-=a[i]; } g2+=(g3*2); if(g3>0||g2>0||g1>0){ puts("No"); return 0; } puts("Yes"); return 0;}
- CODE FESTIVAL 2017 qual A C
- CODE FESTIVAL 2017 qual A
- CODE FESTIVAL 2017 qual C
- CODE FESTIVAL 2017 qual C- A-B-C 总结
- CODE FESTIVAL 2017 qual C C
- Atcoder CODE FESTIVAL 2017 qual C D
- [Atcoder CODE FESTIVAL 2017 qual C]D
- 【AtCoder CODE FESTIVAL 2017 qual C】D
- CODE FESTIVAL 2017 qual B:C
- CODE FESTIVAL 2017 qual B
- CODE FESTIVAL 2017 qual B
- AGC CODE FESTIVAL 2017 qual A(部分题解)
- Atcoder CODE FESTIVAL 2017 qual C 总结+ABCD题解
- Atcoder Code Festival 2016 Qual A D
- atcoder CODE FESTIVAL 2017 qual A 手速(雾)赛
- 【二分图染色】AtCoder CODE FESTIVAL 2017(qual B)C[3 Steps]题解
- [待补完]CODE FESTIVAL 2017 Final (Parallel) A,B,C(搜索)
- Code Festival 2017 qualA E-Modern Painting
- 基于LAMP架构的主流论坛和博客搭建过程详解
- Hadoop之--flume基础知识
- 七夕礼物:Spring Boot MyBatis系列视频(XML+注解+分页+动态SQL)
- 创建cron定时压缩日志的脚本级find指令
- RabbitMQ三种Exchange模式(fanout,direct,topic)的性能比较
- CODE FESTIVAL 2017 qual A C
- backBone 入门指南
- 机器学习总结之第二章模型评估与选择
- js获取url传递参数
- hadoop2.6.0分布式集群搭建(详细),搭建es-hadoop
- 【算法】斐波那契数列--C++源代码(VS2015)
- STF的快速搭建以及使用
- mysql本地可以访问 网络不能访问
- Java常见集合框架