0015 Squares UVA - 201

Squares UVA - 201

问题

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

代码

// 算法竞赛入门经典习题与解答 P26
// 算法竞赛入门经典第2版 P
/*
    Dreams never shine!
    It's you that shine while chasing your dreams :)
    JAYO!!
*/
#include <iostream>
#include <cstring>
#define _for(i, a, b) for(int i = (a); i < (b); ++i)
#define _rep(i, a, b) for(int i = (a); i <= (b); ++i)
using namespace std;

const int MAXN = 16;
int n, m, vExp[MAXN][MAXN], hExp[MAXN][MAXN], H[MAXN][MAXN], V[MAXN][MAXN], Squares[MAXN];

int main() {
	char buf[4]; int x, y;
    for(int t = 1; scanf("%d", &n) == 1; t++) {
        if(t > 1) printf("\n**********************************\n\n");
        memset(vExp, 0, sizeof(vExp)), memset(hExp, 0, sizeof(hExp));
        memset(H, 0, sizeof(H)), memset(V, 0, sizeof(V)), memset(Squares, 0, sizeof(Squares));

        scanf("%d", &m);
        _for(i, 0, m) {
            scanf("%s%d%d", buf, &x, &y);
            if(buf[0] == 'H') H[x][y] = 1;
            else V[y][x] = 1; // 注意H与V中x, y的顺序
        }

        for(int i = n; i >= 1; i--) for(int j = n; j >= 1; j--) {
            if(H[i][j]) hExp[i][j] = hExp[i][j + 1] + 1;
            if(V[i][j]) vExp[i][j] = vExp[i + 1][j] + 1;
        }

        
        _rep(i, 1, n) _rep(j, 1, n) {
            int maxS = min(hExp[i][j], vExp[i][j]);
            _rep(s, 1, maxS) if(hExp[i + s][j] >= s && vExp[i][j + s] >= s) Squares[s]++;
        }

        printf("Problem #%d\n\n", t);
        bool found = false;
        _rep(i, 1, n) if(Squares[i]) {
            found = true;
            printf("%d square (s) of size %d\n", Squares[i], i);
        }
        if(!found) puts("No completed squares can be found.");
    }
    return 0;
}


总结

细心敲代码 i ? 1

  • 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、付费专栏及课程。

余额充值