UVA-4.2-正方形-201
来源:互联网 发布:35互联域名证书查询 编辑:程序博客网 时间:2024/05/21 11:37
UVA-4.2-正方形-201
题目描述:
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&category=833&problem=137&mosmsg=Submission+received+with+ID+18630747
这题大体就是通过两种输入表示输入横线或者竖线,然后判断是否能组成正方形。
大体就是这样。
输出能组成多少个多少长度的正方形。
题目分析:
这题=。=弄俩数组,一个用来标记横线,一个用来标记竖线,然后用循环枚举查找就好了。
给出代码:
#include <stdio.h>#include <stdlib.h>#include <string.h>int as(int heng[][12],int lie[][12],int a,int n);int main(){ int hang[12][12]; int lie[12][12]; memset(hang,0,sizeof(hang)); memset(lie,0,sizeof(lie)); int count=0; int n; while(scanf("%d",&n)!=EOF) { count++; char space; space=getchar(); //char ch; int N; scanf("%d%*C",&N); while(N--) { char ch; ch=getchar(); int a,b; scanf("%d%d%*c",&a,&b); if(ch=='H') { hang[a][b]=1; } else { lie[b][a]=1; } } if(count!=1) { printf("\n**********************************\n\n"); } printf("Problem #%d\n\n",count); int i,j; int mark=1; for(i=1;i<=n;i++) { int sum=as(hang,lie,i,n); if(sum!=0) { mark=0; printf("%d square (s) of size %d\n",sum,i); } } if(mark) printf("No completed squares can be found.\n"); memset(hang,0,sizeof(hang)); memset(lie,0,sizeof(lie)); }}int as(int hang[][12],int lie[][12],int a,int n){ int i,j,x,y; int count=0; for(i=1;i+a<=n;i++) { for(j=1;j+a<=n;j++) { int mark=1; int x,y; for(x=i;x<i+a;x++) { if(lie[x][j]!=1) mark=0; } for(y=j;y<j+a;y++) { if(hang[i][y]!=1) mark=0; } for(x=i;x<i+a;x++) { if(lie[x][j+a]!=1) mark=0; } for(y=j;y<j+a;y++) { if(hang[i+a][y]!=1) mark=0; } if(mark) count++; } } return count;}
0 0
- UVA-4.2-正方形-201
- UVA-201-正方形
- UVa 201 Squares(正方形)
- UVa 201 Squares(正方形)
- Uva 11520填充正方形
- UVa 11520 填充正方形
- UVa 11520 Fill the Square 填充正方形
- 水题(填充正方形,uva 11520)
- 正方形
- 正方形
- 正方形
- 正方形
- 正方形
- 正方形
- 正方形
- 正方形;
- 正方形
- 正方形
- Web Service 的工作原理
- eclipse安装JAVA反编译插件
- spring_5_自动装配
- 容器化实践的经验分享
- Liunx 搭建NDK开发环境
- UVA-4.2-正方形-201
- 【Android 基础】ViewPager&TabLayout使用简例
- 想做蒲公英就不要依赖土壤
- MySQL中使用sql语句插入日期时间类型的写法
- 多进程/线程的取和舍
- 小岛学编程:ptyhon编程道路
- TSP_旅行商问题 - 模拟退火算法(三)
- js中in操作符
- LeetCode - 121. Best Time to Buy and Sell Stock - 思路详解 - C++