[Codeforces Round #237 (Div. 2)] A. Valera and X
A. Valera and X
1 second
256 megabytes
standard input
standard output
Valera is a little boy. Yesterday he got a huge Math hometask at school, so Valera didn't have enough time to properly learn the English alphabet for his English lesson. Unfortunately, the English teacher decided to have a test on alphabet today. At the test Valera got a square piece of squared paper. The length of the side equals n squares (n is an odd number) and each unit square contains some small letter of the English alphabet.
Valera needs to know if the letters written on the square piece of paper form letter "X". Valera's teacher thinks that the letters on the piece of paper form an "X", if:
- on both diagonals of the square paper all letters are the same;
- all other squares of the paper (they are not on the diagonals) contain the same letter that is different from the letters on the diagonals.
Help Valera, write the program that completes the described task for him.
The first line contains integer n (3 ≤ n < 300; n is odd). Each of the next n lines contains n small English letters — the description of Valera's paper.
Print string "YES", if the letters on the paper form letter "X". Otherwise, print string "NO". Print the strings without quotes.
5
xooox
oxoxo
soxoo
oxoxo
xooox
NO
3
wsw
sws
wsw
YES
3
xpx
pxp
xpe
NO 题解:模拟。注意所有测试数据都是一个字母的情况。
例如:
3
aaa
aaa
aaa
answer:NO
代码:
#include<stdio.h>
#include<stdbool.h>
#include<string.h>
#include<limits.h>
int i,j,n,m;
char a[][];
bool can[][]; int
pre()
{
memset(can,true,sizeof(can));
return ;
} int
main()
{
int f;
f=; pre();
scanf("%d",&n);
for(i=;i<=n;i++)
scanf("%s",&a[i]); for(i=;i<=(n >> );i++)
{
if(a[i][i-]!=a[][])
{
f=;
break;
}
if(a[n-i+][i-]!=a[][])
{
f=;
break;
}
if(a[i][n-i]!=a[][])
{
f=;
break;
}
if(a[n-i+][n-i]!=a[][])
{
f=;
break;
}
}
if(a[(n/)+][n/]!=a[][]) f=; if (f==) printf("NO\n");
else
{
f=;
for(i=;i<=(n/);i++)
{
can[i][i-]=false;
can[n-i+][i-]=false;
can[i][n-i]=false;
can[n-i+][n-i]=false;
}
can[(n/)+][n/]=false; for(i=;i<=n;i++)
for(j=;j<n;j++)
if (can[i][j])
{
if(a[i][j]!=a[][])
{
f=;
break;
}
}
if((f==)&&(a[][]!=a[][])) printf("YES\n");
else printf("NO\n"); } return ;
}
[Codeforces Round #237 (Div. 2)] A. Valera and X的更多相关文章
- Codeforces Round #237 (Div. 2) B题模拟题
链接:http://codeforces.com/contest/404/problem/B B. Marathon time limit per test 1 second memory limit ...
- Codeforces Round #237 (Div. 2) A
链接:http://codeforces.com/contest/404/problem/A A. Valera and X time limit per test 1 second memory l ...
- Codeforces Round #252 (Div. 2) B. Valera and Fruits(模拟)
B. Valera and Fruits time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Codeforces Round #237 (Div. 2) B. Marathon(卡long long)
题目:http://codeforces.com/contest/404/problem/B #include <iostream> #include <cstring> #i ...
- Codeforces Round #237 (Div. 2)
链接 A. Valera and X time limit per test:1 secondmemory limit per test:256 megabytesinput:standard inp ...
- Codeforces Round #216 (Div. 2) D. Valera and Fools
题目链接:http://codeforces.com/contest/369/problem/D 注意题意:所有fools都向编号最小的fool开枪:但每个fool都不会笨到想自己开枪,所以编号最小的 ...
- codeforces Round #252 (Div. 2) C - Valera and Tubes
贪心算法,每条路径最短2格,故前k-1步每次走2格,最后一步全走完 由于数据比较小,可以先打表 #include <iostream> #include <vector> #i ...
- Codeforces Round #252 (Div. 2) B. Valera and Fruits
#include <iostream> #include <vector> #include <algorithm> #include <map> us ...
- Codeforces Round #252 (Div. 2) A - Valera and Antique Items
水题 #include <iostream> #include <set> #include <vector> #include <algorithm> ...
随机推荐
- MySql 学习笔记 (派生表)
派生表也是一种子查询那么它出现在 select * from ( select * from b <--这个就是派生表啦 )派生表其实不是个好东西,在生产的时候他是可以通过索引来过滤的,但是一但 ...
- 这样就算会了PHP么?-1
公司有用到这些业务,多了解一下总是没错的. 现在开始一系列的PHP学习啦... <?php $boo=true; if($boo==true) echo '变量$boo为真!'; else ec ...
- LeetCode_Combination Sum
Given a set of candidate numbers (C) and a target number (T), find all unique combinations in C wher ...
- Keil C调试经验
我们使用Keil C调试某系统时积累的一些经验: 1.由于Keil C对中文支持不太好,因而会出现显示的光标与光标实际所在不一致的现象,这会对修改中文注释造成影响.在Windows2000下面 ...
- JAVA中的时间操作
java中的时间操作不外乎这四种情况: 1.获取当前时间 2.获取某个时间的某种格式 3.设置时间 4.时间的运算 好,下面就针对这四种情况,一个一个搞定. 一.获取当前时间 有两种方式可以获得,第一 ...
- leetcode: sortlist之四种方法
原题链接:https://oj.leetcode.com/problems/sort-list/ 题目:空间复杂度为常数,时间复杂度为O(nlogn)的排序链表实现 方法一:第一想法是模拟数组的快速排 ...
- android Service简介及启动关闭方式
(1)Service是Android系统中的四大组件之一,和Activity是同一层次的组件:它是一种生命周期较长,没有可视化界面,运行于后台的一种服务:例如,我们听音乐可以使用Service,下载东 ...
- jQuery旋转插件jqueryrotate 图片旋转
"jquery.rotate.min.js"是jQuery旋转rotate插件,支持Internet Explorer 6.0+ .Firefox 2.0 .Safari 3 .O ...
- 自定义checkbox样式
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- 编写jeb插件打印目标方法的交叉引用
jeb插件的编写,文档在文件夹\jeb_1.5\doc\apidoc. 我这里的目的是回溯sendTextMessage等敏感api的调用路径,实现代码如下: from jeb.api import ...