• [USACO5.1]夜空繁星Starry Night


    这个世界上怎么会有这么多恶心人的搜索啊

    做法...

    找联通块,找完之后尝试赋颜色

    判重很玄学,算联通块上点的两两距离,求和。如果和一样,那么图形一定一样

    然后就苦逼搜索就行了

    1.0h

    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    #include<queue>
    #include<cmath> 
    #include<iostream>
    #include<map>
    using namespace std;
    #define O(x) cout << #x << " " << x << endl;
    #define O_(x) cout << #x << " " << x << "  ";
    #define B cout << "breakpoint" << endl;
    #define clr(a) memset(a,0,sizeof(a));
    #define pii pair<int,int>
    #define mp make_pair
    typedef double db;
    typedef long long ll;
    inline int read()
    {
        int ans = 0,op = 1;
        char ch = getchar();
        while(ch < '0' || ch > '9')
        {
            if(ch == '-') op = -1;
            ch = getchar();
        }
        while(ch >= '0' && ch <= '9')
        {
            (ans *= 10) += ch - '0';
            ch  = getchar();
        }
        return ans * op;
    }
    const int maxn = 505;
    const db eps = 0.00000001;
    int w,h;
    int g[maxn][maxn];
    int mark[maxn][maxn];
    int dx[maxn][maxn],dy[maxn][maxn],n2,n1;
    db dist[maxn];
    int ch = 0;
    int c[maxn];
    db calc(int x1,int y1,int x2,int y2)
    {
      return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
    }
    int judge(int k)
    {
      for(int i = 1;i <= n2;i++)
        for(int j = 1;j <= n2;j++)
        dist[k] += calc(dx[n1][i],dy[n1][i],dx[n1][j],dy[n1][j]);
      for(int i = 1;i < n1;i++) if(fabs(dist[i] - dist[k]) <= eps) return i;
      return 0;
    }
    void dfs(int x,int y)
    {
      for(int i = -1;i <= 1;i++)
        for(int j = -1;j <= 1;j++)
          {
        int nx = x + i,ny = y + j;
        if(nx < 1 || nx > w || ny < 1 || ny > h || mark[nx][ny] || !g[nx][ny]) continue;
        mark[nx][ny] = ch;
        dx[n1][++n2] = nx,dy[n1][n2] = ny;
        dfs(nx,ny);
          }
    }
    int main()
    {
      h = read(),w = read();
      for(int i = 1;i <= w;i++)
        for(int j = 1;j <= h;j++)
        {
            char cha = getchar();
            while(cha != '0' && cha != '1') cha = getchar();
            g[i][j] = cha - '0';
        }
      for(int i = 1;i <= w;i++)
        for(int j = 1;j <= h;j++)
          {
        if(!mark[i][j] && g[i][j])
          {
              ch++;
            n2 = 1,n1++;
            mark[i][j] = ch;
            dx[n1][n2] = i,dy[n1][n2] = j;
            c[n1] = ch;
            dfs(i,j);
            int k = judge(n1);
            if(k)
              {
            ch--;
            for(int i = 1;i <= n2;i++) mark[dx[n1][i]][dy[n1][i]] = c[k];
              }
          }
          }
        for(int i = 1;i <= w;i++)
        {
            for(int j = 1;j <= h;j++)
                mark[i][j] > 0 ? printf("%c",mark[i][j] + 'a' - 1) : printf("0");
            printf("
    ");
        }
    }
      
  • 相关阅读:
    IIS/如何查看IIS上部署网站的实时连接数
    在文件系统中无法访问其他服务器共享的文件夹,如何解决
    SQL sever2008 r2 安装闪退的解决办法
    加密字符串传值时把+号过滤掉了的解决办法
    C# WinForm点击Radio判断是否选中,监控TextBox输入动作
    【转】Entity Framework 数据库初始化的三种方法
    Kubernetes RESTMapper源码分析
    Golang中下划线的使用
    测试开发该如何在团队中推广新工具、新技术(深度好文)
    Java 在Word指定段落/文本位置插入分页符 E
  • 原文地址:https://www.cnblogs.com/LM-LBG/p/10940012.html
Copyright © 2020-2023  润新知