[BJOI2006]狼抓兔子 暴力AC啦!
阿新 • • 發佈:2018-11-29
click 貪心 寫代碼 sizeof res map eps top space
直接暴力建邊,在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[BJOI2006]狼抓兔子 AC CODE#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 #defineREP(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 ‘\n‘ 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\n", 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\n", dinic()) ; 169 } 170 171 /* 172 寫代碼時請註意: 173 1.是否要開Long Long?數組邊界處理好了麽? 174 2.實數精度有沒有處理? 175 3.特殊情況處理好了麽? 176 4.做一些總比不做好。 177 思考提醒: 178 1.最大值和最小值問題可不可以用二分答案? 179 2.有沒有貪心策略?否則能不能dp? 180 */
[BJOI2006]狼抓兔子 暴力AC啦!