B. Vlad and Shapes
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Vladislav has a binary square grid of n×n�×� cells. A triangle or a square is drawn on the grid with symbols 11. As he is too busy being cool, he asks you to tell him which shape is drawn on the grid.
- A triangle is a shape consisting of k� (k>1�>1) consecutive rows, where the i�-th row has 2⋅i−12⋅�−1 consecutive characters 11, and the central 1s are located in one column. An upside down triangle is also considered a valid triangle (but not rotated by 90 degrees).
Two left pictures contain examples of triangles: k=4�=4, k=3�=3. The two right pictures don't contain triangles.
- A square is a shape consisting of k� (k>1�>1) consecutive rows, where the i�-th row has k� consecutive characters 11, which are positioned at an equal distance from the left edge of the grid.
Examples of two squares: k=2�=2, k=4�=4.
For the given grid, determine the type of shape that is drawn on it.
Input
The first line contains a single integer t� (1≤t≤1001≤�≤100) — the number of test cases.
The first line of each test case contains a single integer n� (2≤n≤102≤�≤10) — the size of the grid.
The next n� lines each contain n� characters 00 or 11.
The grid contains exactly one triangle or exactly one square that contains all the 11s in the grid. It is guaranteed that the size of the triangle or square is greater than 11 (i.e., the shape cannot consist of exactly one 1).
Output
For each test case, output "SQUARE" if all the 11s in the grid form a square, and "TRIANGLE" otherwise (without quotes).
Example
input
Copy
6
3
000
011
011
4
0000
0000
0100
1110
2
11
11
5
00111
00010
00000
00000
00000
10
0000000000
0000000000
0000000000
0000000000
0000000000
1111111110
0111111100
0011111000
0001110000
0000100000
3
111
111
111
output
Copy
SQUARE TRIANGLE SQUARE TRIANGLE TRIANGLE SQUARE
解题说明:此题是一道几何题,需要判断图形到底是三角形还是正方形,可以看相邻两行都是1的个数,相同的话就是矩形,否则就是三角形.
#include<stdio.h>
#include<string.h>
int main()
{
int t;
scanf("%d", &t);
while (t--)
{
int n, cnt, prev = 0, sq = 0, tr = 0;
scanf("%d", &n);
for (int i = 0; i < n; i++)
{
char a[n + 1];
scanf("%s", a);
cnt = 0;
for (int j = 0; j < n; j++)
{
if (a[j] == '1')
{
cnt++;
}
}
if (prev != 0)
{
if (cnt == prev)
{
sq = 1;
}
else
{
tr = 1;
}
}
if (cnt > 0)
{
prev = cnt;
}
}
if (sq)
{
printf("SQUARE\n");
}
else
{
printf("TRIANGLE\n");
}
}
return 0;
}
上一篇: 关于颜色的意义,前线工作者应该知道什么?
下一篇: k8s 管理员用户生成令牌
推荐阅读
-
微信 "扫一扫 "物联网,全面揭秘 "扫一扫 "背后的扫盲技术!-1.1 扫一扫感知物体是做什么的? 1.1 微信扫一扫是做什么的? 扫一扫识物是指以图片或视频(商品图片:鞋/包/美妆/服饰/家电/玩具/图书/食品/珠宝/家具/其他商品)为输入媒介,挖掘微信内容生态中的有价值信息(电商+百科+资讯,如图1所示),并展示给用户。这里的电商基本涵盖了微信小程序覆盖上亿SKU的全量优质电商,可以支持用户货比N家并直接下单购买,百科和资讯则聚合了微信内的头部自媒体如搜狗、搜搜、百度等,向用户展示和分享拍摄商品相关的内容资讯。 图 1 扫一扫识别功能示意图 欢迎大家更新iOS新版微信→扫一扫→识货,亲自体验,也欢迎大家通过识货界面的反馈按钮向我们提交反馈意见。 扫一扫识物实景图展示 1.2 扫一扫识物有哪些使用场景? 扫一扫识物的目的是为用户访问微信内部生态内容开辟一个新窗口,以用户扫图片为输入形式,为用户提供微信生态内容中的百科、资讯、电商等作为展示页面。除了用户熟悉的扫一扫操作外,我们还将进一步拓展长按操作,让用户更方便地进行扫一扫操作。"扫一扫知事 "的落地场景主要涵盖三大部分: a. 科普知识: a.科普知识。用户通过扫一扫,可以在微信生态圈中获取该对象的百科、资讯等常识或趣闻,帮助用户更好地了解该对象; b.购物场景。同样的搜索功能支持用户看到喜欢的商品立即检索到微信小程序电商中的同款商品,支持用户即扫即购; c.广告场景。扫一扫识别物体可以辅助公众号文章、视频更好地理解其中蕴含的图片信息,从而更好地投放匹配广告,提高点击率。 1.3 Sweep Sense 为 Sweep 家族带来了哪些新技术? 对于扫一扫来说,大家耳熟能详的应该就是扫一扫二维码、扫一扫小程序码、扫一扫条形码、扫一扫翻译了。无论是各种形式的编码还是文字字符,都可以看作是图片的一种特定编码形式,而物的识别则是对自然场景图片的识别,这对于扫一扫家族来说是一个质的飞跃,我们希望从物的识别入手,进一步拓展扫一扫对自然场景图片的理解能力,比如扫酒、扫车、扫植物、扫人脸等服务,如下图3所示。 图 3 Sweep 家族
-
2021 ICPC EC Final B. Beautiful String 题解
-
[ICPC] 2019 南京站 B. 棋盘 | 组合计数、阅读理解
-
matlab 等距采样,[单选题] 在 MATLAB 中,要求在封闭区间[0,5]上对一维数组 z 产生 50 个等距采样,以下哪条指令是正确的? A. z=0:1/50:5 B. z=0:5 C. z=...
-
B. Vlad and Shapes
-
错误:ValueError: shapes (4,4) and (1,4) not aligned:4 (dim 1) != 1 (dim 0)
-
ValueError: shapes (1,) and (10,1) not aligned: 1 (dim 0) = 10 (dim 0)
-
numpy 点积 ValueError: shapes (3,2) and (3,) not aligned: 2 (dim 1) != 3 (dim 0)
-
moment of inertia formula for different shapes
-
问题:从完整的问题解决过程来看,( )是首要环节。A.理解问题 B.提出假设C.发现问题 D.检验假设 #学习方法#学习方法