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

  • 相关阅读:
    java静态代码分析工具infer
    Go的安装和使用/卸载/升级、安装指定版本
    ldap服务器OpenLDAP安装使用
    python2 和 python3兼容写法
    ldap客户端以及jenkins的配置
    mac下java的安装和升级以及相关环境设置
    常见高危安全漏洞
    XFS: Cross Frame Script (跨框架脚本) 攻击。
    WEB渗透测试之三大漏扫神器
    编写自己的Acunetix WVS漏洞扫描脚本详细教程
  • 原文地址:https://www.cnblogs.com/yszhyhm/p/13365612.html
Copyright © 2011-2022 走看看