zoukankan      html  css  js  c++  java
  • UVA 10593 Kites DP

    The season of flying kites is well ahead. So what? Let us make an inventory for kites. We are given
    a square shaped sheet of paper. But many parts of this are already porous. Your challenge here is to
    count the total number of ways to cut a kite of any size from this sheet. By the way, the kite itself
    can’t be porous :-) AND . . . it must be either square shaped or diamond shaped.
    x
    x xxx xxx xxx
    xxx xxxxx xxx x.x x
    x xxx xxx xxx
    x
    In the above figure first three are valid kites but not next two.
    Input
    Input contains an integer n (n ≤ 500), which is the size of the sheet. Then follows n lines each of which
    has n characters (‘x’ or ‘.’). Here the dotted parts resemble the porous parts of the sheet. Input is
    terminated by end of file.
    Output
    Output is very simple. Only print an integer according to the problem statement for each test case in
    a new line.
    Sample Input
    4
    .xx.
    xxxx
    .xx.
    .x..
    3
    xxx
    xxx
    xxx
    Sample Output
    4
    6

    题意:给你一个 n*n的图,让你在图中找出x组成的边长大于等于2的菱形或正方

    题解:DP ,这个博客的图比较好

          http://blog.csdn.net/u012596172/article/details/41171815

    //meek
    #include<bits/stdc++.h>
    #include <iostream>
    #include <cstdio>
    #include <cmath>
    #include <string>
    #include <cstring>
    #include <algorithm>
    #include<map>
    #include<queue>
    using namespace std ;
    typedef long long ll;
    #define mem(a) memset(a,0,sizeof(a))
    #define pb push_back
    #define fi first
    #define se second
    #define MP make_pair
    
    const int N=550;
    const ll INF = 1ll<<61;
    const int inf = 1000000007;
    const int MOD =   2000000011;
    
    char mp[N][N];
    int dp[N][N],n;
    int solve() {
        int ans = 0;
        mem(dp);
        for(int i=1;i<=n;i++) {
            for(int j=1;j<=n;j++) {
                if(mp[i][j] == 'x') {
                    int tmp = min(dp[i-1][j],dp[i][j-1]);
                    dp[i][j] = tmp + (mp[i-tmp][j-tmp] == 'x');
                    if(dp[i][j] > 1) ans +=dp[i][j] - 1;
                }
            }
        }
        mem(dp);
        for(int i=1;i<=n;i++) {
            for(int j=1;j<=n;j++) {
                if(mp[i][j] == 'x') {
                    int tmp = min (dp[i-1][j-1],dp[i-1][j+1]);
                    if(tmp == 0 || mp[i-1][j] != 'x')  dp[i][j] = 1;
                    else if(mp[i- 2*tmp][j]=='x' && mp[i-tmp*2+1][j] == 'x') dp[i][j] = tmp + 1;
                    else dp[i][j] = tmp;
                    if(dp[i][j] > 1) ans +=dp[i][j] - 1;
                }
            }
        }
        return ans;
    }
    int main() {
        while(scanf("%d",&n)!=EOF) {
            for(int i=1;i<=n;i++) {
                getchar();
                for(int j=1;j<=n;j++) scanf("%c",&mp[i][j]);
            }
            printf("%d
    ",solve());
        }
        return 0;
    }
    代码
  • 相关阅读:
    金额转换问题
    进制转换(十进制->二进制、八进制、十六进制)
    Linux下Tomcat的安装
    Linux下安装jdk配置java环境变量
    Linux下安装Mysql
    在Linux下安装Redis
    Redis常用操作
    阿里云服务器部署tomcat服务器无法访问
    mysql 创建数据库 编码
    docker 安装oracle
  • 原文地址:https://www.cnblogs.com/zxhl/p/5102933.html
Copyright © 2011-2022 走看看