UVa 201 Squares (习题4-2)

时隔一年之后继续搞这些东西

 

然后开始复习以前的内容,把以前高中没写的题好好的搞一下。。

紫书第四章的习题以前就直接没写过,然后昨天调象棋调了一天还是疯狂WA,看到网上正解有400行。。真jier可怕

然后先把那题放一放,主要还是调用函数比较多,改天再重新写一下

 

Squares这个题以前还是想的太复杂了。今天上去教室的途中突然想到这么一个n^3的算法

然后看了一下数据范围2<=n<=9,简直就是纯暴力啊,以前我搞什么鬼。。

 

下早自习回寝室开始写,然后发现长度为2的检测不了,仔细一看是V的储存问题

紫书上说V x y 表示(x,y)(x+1,y)的直线

但是原题样例中出现了V 4 1,且n = 4,是不会有点(5,1)的,而在图中表示出了V 1 4

那么只要把V的x和y交换一下就行了

检测的时候用一个函数检测两个点之间的线段是否是连通的即可,依次检测4条边,全部连通的话就是一个正方形,返回true进行计数 

题目地址(vjudge):https://vjudge.net/problem/UVA-201

代码:

//Decision's template
#include<cstdio>
#include<cstring>
#include<iostream>
#include<cstdlib>
#include<vector>
#include<queue>
#include<stack>
#include<algorithm>
#include<string>
#include<cmath>
#include<map>
#include<set>
using namespace std;

#define DP_maxn 16
#define maxn 1000000+10
#define INF 1000000007
#define mod 1000000007
#define mst(s,k) memset(s,k,sizeof(s))

typedef long long ll;

struct Edge{
    int from,to,dist;
    Edge(int u,int v,int d):from(u),to(v),dist(d){}
};

/*-------------------------------template End--------------------------------*/

int m,n;
int h[10][10],v[10][10],ans=0,now = 0;
char c;

bool check_v(int x_1,int x_2,int y){          //检测x方向两点是否连通
	for(int i = x_1;i<x_2;i++){
		if(v[i][y]) continue;
		else return false;
	}
	return true;
}

bool check_h(int y_1,int y_2,int x){          //检测y方向两点是否连通
	for(int i = y_1;i<y_2;i++){
		if(h[x][i]) continue;
		else return false;
	}
	return true;
}

bool check(int x,int y,int l)
{
	if(x+l<=n&&y+l<=n){
		if(check_v(x,x+l,y)&&check_v(x,x+l,y+l)&&check_h(y,y+l,x)&&check_h(y,y+l,x+l)) return true;
		else return false;
	}
	else return false;
}

int main()
{
	while(cin>>m>>n){
		mst(h,0);
		mst(v,0);
		int flag = 0;
		int t_x,t_y;
		now++;
		if(now!=1) cout<<endl<<"**********************************"<<endl<<endl;
		cout<<"Problem #"<<now<<endl<<endl;
		for(int i = 1;i<=n;i++){
			cin>>c>>t_x>>t_y;;
			if(c=='H') h[t_x][t_y] = 1;
			else v[t_y][t_x] = 1; 
		}
		for(int i = 1;i<=m;i++){
			ans = 0;
			for(int j = 1;j<=m;j++){
				for(int k = 1;k<=m;k++){
					if(check(j,k,i)) ans++;
				}
			}
			if(ans>0&&flag == 0) flag = 1;
			if(ans>0) cout<<ans<<" square (s) of size "<<i<<endl;
		}
		if(!flag) cout<<"No completed squares can be found."<<endl;
	}
	return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
引用\[1\]: Curves and Surfaces A Bidirectional Generating Algorithm for Rational Parametric Curves(Z. Li, L. Ma)Fast Detection of the Geometric Form of Two-Dimensional Cubic Bézier Curves(S. Vincent)Exact Evaluation of Subdivision Surfaces(eigenstructures for Catmull-Clark and Loop schemes) (J. Stam)Exact Evaluation of Catmull-Clark Subdivision Surfaces near B-Spline Boundaries(D. Lacewell, B. Burley)Smooth Two-Dimensional Interpolations: A Recipe for All Polygons(E. Malsch, J. Lin, G. Dasgupta) Normal Patches / PN-Triangles(R. Stimpson)Marching Cubes(.vol files) (R. Stimpson)Coons Patches(R. Stimpson)Exact Catmull-Clark Subdivision evaluation(and mean-curvature minimization) (F. Hecht)Laplacian Surface Editing(2D curve deformation) (O. Sorkine, D. Cohen-Or, Y. Lipman, M. Alexa, C. Roessl, H.-P. Seidel)Elasticurves: Exploiting Stroke Dynamics and Inertia for the Real-time Neatening of Sketched 2D Curves(Y. Thiel, K. Singh, R. Balakrishnan) 。 引用\[2\]: Segmentation efpisoft: hierarchical mesh segmentation based on fitting primitives(M. Attene)mesh segmentation benchmark database and viewer(X. Chen, A. Golovinskiy, T. Funkhouser)Graphite(variational shape approximation,image vectorization) \[documentation wiki\] (Authors)SegMatch: Shape Segmentation and Shape Matching from Point Cloud(T. Dey, S. Goswami)ShapeAnnotatorsegmentation tool (fitting primitives, barycentric/height/integral geodesic Morse, Plumber, Lloyd clustering)(Authors)Shape Diameter Function (SDF) segmentation tool(L. Shapira) 。 引用\[3\]:DP。对于每个'#'来说,要使图美丽就要保证每个'#'的正下方到正右下都填满'#' ....#. ....#. ...... ....## .#.... -> .#..## (题解里CV过来的) ...... .##.## ...... .##### 。 问题: Defect-free Squares是什么意思? 回答: Defect-free Squares是指在一个图形中,每个'#'的正下方到正右下方都填满了'#',从而使整个图形看起来没有缺陷。这个概念可以通过动态规划(DP)来实现,对于每个'#',需要保证其正下方到正右下方都填满了'#',从而形成一个完整的正方形。\[3\] #### 引用[.reference_title] - *1* *2* [图形学领域的关键算法及源码链接](https://blog.csdn.net/u013476464/article/details/40857873)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [ABC311 A-F](https://blog.csdn.net/Muelsyse_/article/details/131873631)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值