• [BJOI2006]狼抓兔子 暴力AC啦!


    直接暴力建边,在lougu上跑的飞快。(except the last test)

    总结一下也就是三句话:

    insert(id(i, j), id(i, j + 1), x)
    insert(id(i, j), id(i + 1, j), x)
    insert(id(i, j), id(i + 1, j + 1), x) 

    没了就,。。dinic什么的就看看本博客分享的总结爸。。。

    代码当然还是要发的,即使只是一个暴力。。

      1 #include <map>
      2 #include <set>
      3 #include <cmath>
      4 #include <ctime>
      5 #include <queue>
      6 #include <stack>
      7 #include <vector>
      8 #include <bitset>
      9 #include <cstdio>
     10 #include <cctype>
     11 #include <string>
     12 #include <cstring>
     13 #include <cassert>
     14 #include <climits>
     15 #include <cstdlib>
     16 #include <iostream>
     17 #include <algorithm>
     18 #include <functional>
     19 using namespace std ;
     20 
     21 #define rep(i, a, b) for (int (i) = (a); (i) <= (b); (i)++)
     22 #define Rep(i, a, b) for (int (i) = (a) - 1; (i) < (b); (i)++)
     23 #define REP(i, a, b) for (int (i) = (a); (i) >= (b); (i)--)
     24 #define clr(a) memset(a, 0, sizeof(a))
     25 #define Sort(a, len, cmp) sort(a + 1, a + len + 1, cmp)
     26 #define ass(a, sum) memset(a, sum, sizeof(a))
     27 
     28 #define ls ((rt) << 1)
     29 #define rs ((rt) << 1 | 1)
     30 #define lowbit(x) (x & -x)
     31 #define mp make_pair
     32 #define pb push_back
     33 #define fi first
     34 #define se second
     35 #define endl '
    '
     36 #define ENDL cout << endl
     37 #define SZ(x) ((int)x.size())
     38 
     39 typedef long long ll ;
     40 typedef unsigned long long ull ;
     41 typedef vector <int> vi ;
     42 typedef pair <int, int> pii ;
     43 typedef pair <ll, ll> pll ;
     44 typedef map <int, int> mii ;
     45 typedef map <string, int> msi ;
     46 typedef map <ll, ll> mll ;
     47 
     48 const int N = 1010 ;
     49 const double eps = 1e-8 ;
     50 const int iinf = INT_MAX ;
     51 const ll linf = 2e18 ;
     52 const double dinf = 1e30 ;
     53 const int MOD = 1000000007 ;
     54 
     55 inline int read(){
     56     int X = 0, w = 0 ;
     57     char ch = 0 ;
     58     while (!isdigit(ch)) { w |= ch == '-' ; ch = getchar() ; }
     59     while (isdigit(ch)) X = (X << 3) + (X << 1) + (ch ^ 48), ch = getchar() ;
     60     return w ? - X : X ;
     61 }
     62 
     63 void write(int x){
     64      if (x < 0) putchar('-'), x = - x ;
     65      if (x > 9) write(x / 10) ;
     66      putchar(x % 10 + '0') ;
     67 }
     68 
     69 void print(int x) {
     70     cout << x << endl ;
     71     exit(0) ;
     72 }
     73 
     74 void PRINT(string x) {
     75     cout << x << endl ;
     76     exit(0) ;
     77 }
     78 
     79 void douout(double x){
     80      printf("%lf
    ", x + 0.0000000001) ;
     81 }
     82 
     83 int n, m, x, top = 1, s, t ;
     84 int head[N * N], dep[N * N] ;
     85 
     86 struct Edge {
     87     int to, nxt, w ;
     88 } e[N * N * 6] ;
     89 
     90 void add(int a, int b, int w) {
     91     e[++top] = (Edge) {b, head[a], w} ;
     92     head[a] = top ;
     93 }
     94 
     95 void insert(int a, int b, int w) {
     96     add(a, b, w) ;
     97     add(b, a, w) ;
     98 }
     99 
    100 bool bfs() { //分层图
    101     queue <int> q ;
    102     q.push(s) ;
    103     clr(dep) ;
    104     dep[s] = 1 ;
    105     while (!q.empty()) {
    106         int now = q.front() ;
    107         q.pop() ;
    108         for (int i = head[now]; i; i = e[i].nxt) {
    109             int to = e[i].to ;
    110             if (e[i].w && !dep[to]) {
    111                 dep[to] = dep[now] + 1 ;
    112                 q.push(to) ;
    113             }
    114         }
    115     }
    116     if (!dep[t]) return 0 ;
    117     else return 1 ;
    118 }
    119 
    120 int dfs(int rt, int dis) {
    121     if (rt == t) return dis ;
    122     for (int i = head[rt]; i; i = e[i].nxt) {
    123         int to = e[i].to ;
    124         if (dep[to] == dep[rt] + 1 && e[i].w) {
    125             int p = dfs(to, min(e[i].w, dis));
    126             if (!p) {
    127                 dep[to] = -1;
    128                 continue;
    129             }
    130             e[i].w -= p ;
    131             e[i ^ 1].w += p ;
    132             return p ;
    133         }
    134     }
    135     return 0 ;
    136 }
    137 
    138 int dinic() {
    139     int res = 0 ;
    140     while (bfs()) {
    141         while (int d = dfs(s, iinf)) res += d ;
    142     }
    143     return res ;
    144 }
    145 
    146 int id(int x, int y) {
    147     return (x - 1) * m + y ;
    148 }
    149 
    150 signed main(){
    151     scanf("%d%d", &n, &m) ;
    152     s = 1, t = id(n, m) ;
    153     for (int i = 1; i <= n; i++)
    154     for (int j = 1; j < m; j++) {
    155         scanf("%d", &x) ;
    156         insert(id(i, j), id(i, j + 1), x) ;
    157     }
    158     for (int i = 1; i < n; i++)
    159     for (int j = 1; j <= m; j++) {
    160         scanf("%d", &x) ;
    161         insert(id(i, j), id(i + 1, j), x) ;
    162     }
    163     for (int i = 1; i < n; i++)
    164     for (int j = 1; j < m; j++) {
    165         scanf("%d", &x) ;
    166         insert(id(i, j), id(i + 1, j + 1), x) ;
    167     }
    168     printf("%d
    ", dinic()) ;
    169 }
    170 
    171 /*
    172 写代码时请注意:
    173     1.是否要开Long Long?数组边界处理好了么?
    174     2.实数精度有没有处理?
    175     3.特殊情况处理好了么?
    176     4.做一些总比不做好。
    177 思考提醒:
    178     1.最大值和最小值问题可不可以用二分答案?
    179     2.有没有贪心策略?否则能不能dp?
    180 */
    [BJOI2006]狼抓兔子 AC CODE
    加油ヾ(◍°∇°◍)ノ゙
  • 相关阅读:
    N46期第一周作业
    备份MBR分区表,并破坏后修复
    预习作业(五)作业
    预习作业(四)作业
    通过v$sqlarea,v$sql查询最占用资源的查询
    ORACLE快速彻底Kill掉的会话
    HTML5中修改表单验证默认提示语句
    input正则 常用正则(备用)
    使用扫描枪扫描条码时字符识别写入缓慢问题(针对element-ui的el-input)优化
    JQuery经验汇总
  • 原文地址:https://www.cnblogs.com/harryhqg/p/10034489.html
Copyright © 2020-2023  润新知