栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

zoj 3316 Game

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

zoj 3316 Game

#include <stdio.h>#include <stdlib.h>#include <string.h>#include <ctype.h>#include <math.h>#include <time.h>#include <iostream>#include <algorithm>#include <cstdio>#include <cstdlib>#include <cmath>#include <cstring>#include <cctype>#include <stack>#include <string>#include <list>#include <queue>#include <map>#include <vector>#include <deque>#include <set>using namespace std;#ifdef WIN32#define INT64 "%I64d"#define UINT64 "%I64u"#else#define INT64 "%lld"#define UINT64 "%llu"#endif#define INF 0x3f3f3f3f#define eps 1e-8#define PI acos(-1.)#define PI2 asin (1.);typedef long long LL;typedef unsigned long long ui64;#define MP make_pairtypedef vector<int> VI;typedef pair<int, int> PII;#define pb push_back#define mp make_pair#define CL(a,b) memset (a, b, sizeof (a))#define sqr(a,b) sqrt ((double)(a)*(a) + (double)(b)*(b))template <typename T> double DIS(T va, T vb) { return sqr(va.x - vb.x, va.y - vb.y); }template <class T> inline T INTEGER_LEN(T v) { int len = 1; while (v /= 10) ++len; return len; }template <typename T> inline T square(T va, T vb) { return va * va + vb * vb; }#pragma comment (linker, "/STACK:1024000000,1024000000")#define CY 400#define maxn 400struct Graph { int n, match[maxn]; bool adj[maxn][maxn]; void clear() { memset(adj, 0, sizeof(adj)); n = 0; } void insert(const int &u, const int &v) { n = max(n, max(u, v) + 1); adj[u][v] = adj[v][u] = 1; }int contract(int u, int v) { memset(in_blossom, 0, sizeof(in_blossom)); int b = find_base(base[u], base[v]); change_blossom(b, u); change_blossom(b, v); if (base[u] != b) { pre[u] = v; } if (base[v] != b) { pre[v] = u; } return b; }void argument(int u) { while (u != -1) { int v = pre[u]; int k = match[v]; match[u] = v; match[v] = u; u = k; } } void change_blossom(int b, int u) { while (base[u] != b) { int v = match[u]; in_blossom[base[v]] = in_blossom[base[u]] = true; u = pre[v]; if (base[u] != b) { pre[u] = v; } } } int find_base(int u, int v) { bool in_path[maxn] = {}; while (true) { in_path[u] = true; if (match[u] == -1) { break; } u = base[pre[match[u]]]; } while (!in_path[v]) { v = base[pre[match[v]]]; } return v; }int Q[maxn], pre[maxn], base[maxn]; bool hash[maxn]; bool in_blossom[maxn]; int bfs(int p) { memset(pre, -1, sizeof(pre)); memset(hash, 0, sizeof(hash)); for (int i = 0; i < n; ++i) { base[i] = i; } Q[0] = p; hash[p] = 1; for (int s = 0, t = 1; s < t; ++s) { int u = Q[s]; for (int v = 0; v < n; ++v) { if (adj[u][v] && base[u] != base[v] && v != match[u]) { if (v == p || (match[v] != -1 && pre[match[v]] != -1)) { int b = contract(u, v); for (int i = 0; i < n; ++i) { if (in_blossom[base[i]]) { base[i] = b; if (hash[i] == 0) { hash[i] = 1; Q[t++] = i; } } } } else if (pre[v] == -1) { pre[v] = u; if (match[v] == -1) { argument(v); return 1; } else { Q[t++] = match[v]; hash[match[v]] = 1; } } } } } return 0; } int max_match() { memset(match, -1, sizeof(match)); int ans = 0; for (int i = 0; i < n; ++i) { if (match[i] == -1) { ans += bfs(i); } } return ans; }}e;int x[CY], y[CY];int N, L;void input(int n) {for (int i = 0; i < n; ++i) {scanf("%d%d", &x[i], &y[i]);}scanf("%d", &L);}void solve(int n) {e.clear();for (int i = 0; i < n; ++i) {for (int j = i + 1; j < n; ++j) {if (abs(x[i] - x[j]) + abs(y[i] - y[j]) <= L) {e.insert(i, j);}}}int ans = e.max_match();if (ans * 2 == n) printf("YESn");else printf("NOn");}int main(void) {while (~scanf("%d", &N)) {input(N);solve(N);}return 0;}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/373873.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号