本文共 3900 字,大约阅读时间需要 13 分钟。
In GGO, a world dominated by gun and steel, players are fighting for the honor of being the strongest gunmen. Player Shino is a sniper, and her aimed shot kills one monster at a time. Now she is in an n \times nn×n map, and there are monsters in some grids. Each monster has an experience. As a master, however, Shino has a strange self-restrain. She would kill at most one monster in a column, and also at most one in a row. Now she wants to know how to get max experience, under the premise of killing as many monsters as possible.
The first line contains an integer nn. (n<=500)Then n lines follow. In each line there are n integers, and AijAij represents the experience of the monster at grid (i,j)(i,j). If Aij=0Aij=0, there is no monster at grid (i,j)(i,j).
The experience is the minimal experience of all the monster which are killed.
It guaranteed that the maximum of the experience of the monster is not larger than 10^9
One integer, the value of max experience.
22 01 8
2
#include #include #include #include #include #include #include #include #include #include #include #include #include #define rap(i, a, n) for(int i=a; i<=n; i++)#define rep(i, a, n) for(int i=a; i =a; i--)#define lep(i, a, n) for(int i=n; i>a; i--)#define rd(a) scanf("%d", &a)#define rlld(a) scanf("%lld", &a)#define rc(a) scanf("%c", &a)#define rs(a) scanf("%s", a)#define rb(a) scanf("%lf", &a)#define rf(a) scanf("%f", &a)#define pd(a) printf("%d\n", a)#define plld(a) printf("%lld\n", a)#define pc(a) printf("%c\n", a)#define ps(a) printf("%s\n", a)#define MOD 2018#define LL long long#define ULL unsigned long long#define Pair pair #define mem(a, b) memset(a, b, sizeof(a))#define _ ios_base::sync_with_stdio(0),cin.tie(0)//freopen("1.txt", "r", stdin);using namespace std;const int maxn = 1e6 + 10, INF = 0x7fffffff;int n, s, t;int head[maxn], cur[maxn], vis[maxn], d[maxn], cnt, nex[maxn << 1];struct node{ int u, v, c;}Node[maxn << 1];void add_(int u, int v, int c){ Node[cnt].u = u; Node[cnt].v = v; Node[cnt].c = c; nex[cnt] = head[u]; head[u] = cnt++;}void add(int u, int v, int c){ add_(u, v, c); add_(v, u, 0);}bool bfs(){ queue Q; mem(d, 0); Q.push(s); d[s] = 1; while(!Q.empty()) { int u = Q.front(); Q.pop(); for(int i = head[u]; i != -1; i = nex[i]) { int v = Node[i].v; if(!d[v] && Node[i].c > 0) { d[v] = d[u] + 1; Q.push(v); if(v == t) return 1; } } } return d[t] != 0;}int dfs(int u, int cap){ int ret = 0; if(u == t || cap == 0) return cap; for(int &i = cur[u]; i != -1; i = nex[i]) { int v = Node[i].v; if(d[v] == d[u] + 1 && Node[i].c > 0) { int V = dfs(v, min(cap, Node[i].c)); Node[i].c -= V; Node[i ^ 1].c += V; ret += V; cap -= V; if(cap == 0) break; } } if(cap > 0) d[u] = -1; return ret;}int Dinic(){ int ans = 0; while(bfs()) { memcpy(cur, head, sizeof head); ans += dfs(s, INF); } return ans;}int w[550][550];void build(int m){ mem(head, -1); cnt = 0; for(int i = 1; i <= n; i++) { add(s, i, 1); add(n + i, t, 1); for(int j = 1; j <= n; j++) if(w[i][j] >= m) add(i, n + j, 1); }}int main(){ while(cin >> n) { int sum = 0; mem(head, -1); cnt = 0; s = 0, t = maxn - 1; int l = 1e9, r = 0; for(int i = 1; i <= n; i++) { add(s, i, 1); add(n + i, t, 1); for(int j = 1; j <= n; j++) { rd(w[i][j]); if(w[i][j]) add(i, n + j, 1); l = min(l, w[i][j]); r = max(r, w[i][j]); } } int max_flow = Dinic(); while(l < r) { int m = (l + r + 1) / 2; build(m); if(Dinic() < max_flow) r = m - 1; else l = m; } cout << r << endl; } return 0;}
转载于:https://www.cnblogs.com/WTSRUVF/p/10715685.html