zoukankan      html  css  js  c++  java
  • 【每日一题】Squares UVA

    题意 给你n*n的图,让你数正方形

    题解:暴力for每个点,对于每个点从它出发顺时针走一个正方形。走完就ans[i]++;

    坑:多输了一行******,然后在那里手摸样例,无限debug orz

    #define _CRT_SECURE_NO_WARNINGS
    #include<cmath>
    #include<iostream>
    #include<stdio.h>
    #include<algorithm>
    #include<cstring>
    #include<ctime>
    using namespace std;
    #define rep(i,t,n)  for(int i =(t);i<=(n);++i)
    #define per(i,n,t)  for(int i =(n);i>=(t);--i)
    #define mmm(a,b) memset(a,b,sizeof(a))
    typedef long long ll;
    const int maxn = 2e6 + 10;
    const ll mod = 1e9 + 7;
    void smain();
    #define ONLINE_JUDGE
    int main() {
        //ios::sync_with_stdio(false);
    #ifndef ONLINE_JUDGE
        FILE *myfile;
        myfile = freopen("C:\Users\acm-14\Desktop\test\b.in", "r", stdin);
        if (myfile == NULL)
            fprintf(stdout, "error on input freopen
    ");
        FILE *outfile;
        outfile = freopen("C:\Users\acm-14\Desktop\test\out.txt", "w", stdout);
        if (outfile == NULL)
            fprintf(stdout, "error on output freopen
    ");
        long _begin_time = clock();
    #endif
        smain();
    #ifndef ONLINE_JUDGE
        long _end_time = clock();
        printf("time = %ld ms.", _end_time - _begin_time);
    #endif
        return 0;
    }
    
    
    int n, m, k;
    int h[10][10], v[10][10];
    int ans[10];
    int tot;
    int check(int x) {
        int ret = 0;
        rep(i,1,n-x)
            rep(j, 1, n-x) {
            int nr = i, nc = j;
            int ok = 1;
            if (ok)rep(k, 1, x) { if (h[nr][nc])nc++; else ok = 0; }
            if (ok)rep(k, 1, x) { if (v[nr][nc])nr++; else ok = 0; }
            if (ok)rep(k, 1, x) { if (h[nr][nc-1])nc--; else ok = 0; }
            if (ok)rep(k, 1, x) { if (v[nr-1][nc])nr--; else ok = 0; }
            if (ok)ret++;
    
        }
        return ret;
    }
    
    void smain() {
        int kase = 0;
        int first = 1;
        while (cin >> n >> m) {
            if (first == 1)first = 0;
            else { cout << endl; puts("**********************************"); cout << endl; }
            mmm(h, 0); mmm(v, 0); mmm(ans, 0);
            while (m--) {
    
                char op;
                int r, c;
                cin >> op >> r >> c;
                if (op == 'H') {
                    h[r][c] = 1;
                }
                else v[c][r] = 1;
                rep(i, 1, n) {
                    ans[i]=check(i);
                }
            }
            printf("Problem #%d
    
    ", ++kase);
            int fl = 0;
            rep(i, 1, n)if (ans[i])fl++;
            if (!fl)printf("No completed squares can be found.
    ");
            else rep(i, 1, n)if (ans[i])printf("%d square (s) of size %d
    ", ans[i], i);
            
            
        }
    }
    /*
    
    */
    成功的路并不拥挤,因为大部分人都在颓(笑)
  • 相关阅读:
    Linux中配置别名
    Linux下的IO监控与分析
    RHEL6 Systemtap 安装笔记
    记一次多事件绑定中自己给自己设置的坑——click,dblclick,mousedown,mousemove,mouseup
    springboot打jar获取不到static静态资源文件问题
    关于springboot默认日志框架Slf4j+logback,自定义Appender问题
    spring 时间格式问题
    springboot 部署到tomcat,获取根路径问题。空格变为%20
    前后端分离 vue+springboot 跨域 session+cookie失效问题
    springboot 部署到tomcat中,项目总是重新部署
  • 原文地址:https://www.cnblogs.com/SuuT/p/9477815.html
Copyright © 2011-2022 走看看