zoukankan      html  css  js  c++  java
  • 7.12test

    There is three topics

    first is square

    the topic is a (dfs)

    we search the any point into any square

    the 'in' function is to judge the point whether in the square(we had celect)

    (we search the aim is point, so if the point over the 'n' we need return rather than over the 'm')

    the code is follow

    // square
    #include <bits/stdc++.h>
    using namespace std;
    
    const int N = 66;
    
    int n, m, ans = 2147483647;
    
    struct node {int x, y;} a[N];
    struct mtrx {int l, r, u, d; bool flag;} p[N];
    
    inline int in (mtrx dy, int one, int two) {
       if (dy.l <= one && dy.r >= one &&
          dy.d <= two && dy.u >= two)
          return true;
       return false;
    }
    
    inline int pd (mtrx s, mtrx t) {
       if (in(s, t.l, t.u)) return true;
       if (in(s, t.l, t.d)) return true;
       if (in(s, t.r, t.u)) return true;
       if (in(s, t.r, t.d)) return true;
       return false;
    }
    
    inline void dfs (int num) {
       int nows(0);
       for (int i = 1; i <= m; ++ i){
           if (p[i].flag) 
              for (int j = i+1; j <= m; ++ j)
                 if (p[j].flag && pd(p[i], p[j])) 
                    return;
           nows += (p[i].r-p[i].l)*(p[i].u-p[i].d);
       }
       if (nows >= ans) return;
       if (num > n) {
          ans = nows;
          return;
       }
       for (int i = 1; i <= m; ++ i) {
          mtrx tmp = p[i];
          if (p[i].flag == 0) {
             p[i].flag = 1;
             p[i].l = p[i].r = a[num].x;
             p[i].u = p[i].d = a[num].y;
             dfs (num+1);
             p[i] = tmp;
          } else {
             p[i].l = min (p[i].l, a[num].x);
             p[i].r = max (p[i].r, a[num].x);
             p[i].u = max (p[i].u, a[num].y);
             p[i].d = min (p[i].d, a[num].y);
             dfs (num+1);
             p[i] = tmp;
          }
       }
       return;
    }
    
    main () {
       cin >> n >> m;
       for (int i = 1; i <= n; ++ i) cin >> a[i].x >> a[i].y;
       dfs (1);
       cout << ans;
       return 0;
    }
    /*
    4 2
    1 1
    2 2
    3 6
    0 7
    */
    

    second is pat cows

    1.sieve

    2.violence

    the code is follow

    #include <bits/stdc++.h>
    using namespace std;
    						
    const int N = 1e5+10, N_y = 1e6+10;
    
    int n, dx;
    int a[N], v[N_y], ans[N_y];
    
    int main () {
       scanf ("%d", &n);
       for (int i = 1; i <= n; ++ i) {
          scanf ("%d", &a[i]);
          ++ v[a[i]];
          dx = max (dx, a[i]);
       }
       for (int i = 1; i <= dx; ++ i) {
          if (v[i])
          for (int j = i; j <= dx; j += i)
    	 ans[j] += v[i];
       }
       for (int i = 1; i <= n; ++ i) cout << ans[a[i]]-1 << '
    ';
       return 0;
    }
    

    third is zip

    PS:

    1.pd function 'res' must zero

    2.from l to r

    We will have two happening

    one is the block have the M

    the other is don't have

    we delimit the 'have M' is (f[i][j][1])

    the other is (f[i][j][0])

    the (f[i][j][0]) is more easy

    before we to do state

    we should list all of the state(double num). of coures we need pd

    and then....

    we find a 'k' to apply the epuation

    the equation is

    (f[i][j][0] = min(f[i][j][0], f[i][k][0]+j-k))

    for the (f[i][j][1])

    compared with the (f[i][j][0]) is more difficlt

    we can make the all block (i->j) into two block i->k, and k->j

    and the epuation is

    (the first = min(f[i][k][1], f[i][k][0]))

    (the second = min(f[k+1][j][1], f[k+1[j][0]))

    (f[i][j][1] = min (f[i][j][1], thefirst + thesecond + 1))

    (+ 1):because we must put a 'M' on the k

    the code is follow

    // zip
    #include <bits/stdc++.h>
    using namespace std;
    
    const int N = 66;
    
    int f[N][N][6];
    char ch[N];
    
    inline int pd (int s, int t) {
        int k = (t-s+1), res(0), jz;
        if (k&1) return false;
        jz = (t+s+1)>>1; k >>=1;
        for (int i = 0; i < k; ++ i)
            if (ch[s+i] == ch[jz+i])
                ++ res;
        return res == k;
    }
    
    main () {
       scanf ("%s", ch+1);
       int n = strlen(ch+1);
       for (int i = 1; i <= n; ++ i)
          for (int j = 1; j <= n; ++ j)
             f[i][j][0] = f[i][j][1] = (j-i+1);
       for (int len = 2; len <= n; ++ len) {
          for (int i = 1; i <= n-len+1; ++ i) {
             int j = i+len-1;
             if (pd(i, j)) {
                int m = (i+j)>>1;
                f[i][j][0] = min (f[i][j][0], f[i][m][0]+1);
             }
             for (int k = 1; k <= j-1; ++ k)
                f[i][j][0] = min (f[i][j][0], f[i][k][0]+j-k);
             for (int k = 1; k <= j-1; ++ k)
                f[i][j][1] = min (f[i][j][1],
                             min (f[i][k][0], f[i][k][1])+
                             min (f[k+1][j][0], f[k+1][j][1])+1);
          }
       }
       cout << min (f[1][n][0], f[1][n][1]);
       return 0;
    }
    

    (7.14update)

    PS

    1.pd funcition k or m must not '>>=1'

    because if the num first is a even

    after the '>>=1' the num maybe an odd

    so we must before the '>>=1' to check the even or odd

    2.initialization we must let the (i and j) 'for' from 1

    3.when we search the 'k'

    the 'k' is from 1 to j-1

  • 相关阅读:
    unknown: Are you trying to mount a directory onto a file (or vice-versa)? Check if the specified host path exists and is the expected type.
    Go的学习笔记之Channel发送和接收
    聊聊 PC 端自动化最佳方案
    一文彻底搞懂快速幂(原理实现、矩阵快速幂)
    一次core.<number> 文件占满磁盘空间的处理过程
    博文目录
    备忘录:C#获取微信小程序的云数据库中数据
    T-SQL——关于跨库连接查询
    .NET异步程序设计——给线程传递数据
    自研 Pulsar Starter:winfun-pulsar-spring-boot-starter
  • 原文地址:https://www.cnblogs.com/yszhyhm/p/13365612.html
Copyright © 2011-2022 走看看