hdu 3991 Harry Potter and the Present II //最小路径覆盖
来源:互联网 发布:心动网络股份有限公司 编辑:程序博客网 时间:2024/06/12 00:10
很容易看出是最小路径覆盖
那场比赛几乎没怎么做,弄项目了
接着注意一些比较白痴的问题,比如将数组赋值为1<<30,接着两个相加和别人比大小。。。这是纯悲剧。。。。(TLE了N次,这里。。。悲剧)
#include <cstdio>#include <cstring>struct EDGE{ int v, next;}edge[2010010];struct NODE{ int p; long long t;}node[1010];const long long inf = 1ll<<60;long long map[105][105];bool usedif[1005];int link[1005];int head[1010];int cnt, gx, gy;bool cmp(NODE a, NODE b){ return a.t < b.t;}void addedge(int u, int v){ edge[cnt].v = v; edge[cnt].next = head[u]; head[u] = cnt++;}bool can(int t){ for(int p = head[t]; p != -1; p = edge[p].next) { int i = edge[p].v; if(usedif[i]==0) { usedif[i]=1; if(link[i]==-1||can(link[i])) { link[i]=t; return true; } } } return false;}int MaxMatch(){ int num=0; memset(link,-1,sizeof(link)); for(int i=0; i< gx; i++) { memset(usedif,0,sizeof(usedif)); if(can(i)) num++; } return num;//返回最大匹配数}int main(){ int T; scanf("%d", &T); int cas = 1; while(T--) { int n, m, q; scanf("%d%d%d", &n, &m, &q); int d = 1<< 30; for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) if(i != j) map[i][j] = inf; else map[i][j] = 0; //printf("%d\n", map[0][1]); while(m--) { int a, b; long long c; scanf("%d%d%I64d", &a, &b, &c); if(map[a][b] > c) { map[a][b] = map[b][a] = c; } } for(int k = 0; k < n; k++) for(int i = 0; i < n; i++) { if(i == k) continue; if(map[i][k] == inf) continue; for(int j = 0; j < n; j++) if(map[k][j] != inf && map[i][k] + map[k][j] < map[i][j]) { map[i][j] = map[i][k] + map[k][j]; } } for(int i = 0; i < q; i++) { scanf("%d%d", &node[i].p, &node[i].t); } //sort(node, node + q, cmp); gx = q; cnt = 0; memset(head, -1, sizeof(head)); for(int i = 0; i < q; i++) { for(int j = 0; j < q; j++) if(i != j && node[j].t - node[i].t >= map[node[i].p][node[j].p]) { //printf("%d\n",node[j].t - node[i].t); //printf("%d\n",map[node[i].p][node[j].p]); addedge(i, j); } } //printf("cnt=%d\n", cnt); int ans = gx - MaxMatch(); printf("Case %d: %d\n", cas++, ans - 1); } return 0;}
- HDU--3991[Harry Potter and the Present II] Floyd预处理+最小路径覆盖
- hdu 3991 Harry Potter and the Present II //最小路径覆盖
- hdu 3991 Harry Potter and the Present II (最短路+最小路径覆盖)
- HDU 3991 Harry Potter and the Present II(Floyd+DAG最小路径覆盖)
- HDU 3991 Harry Potter and the Present II(Floyd+DAG最小路径覆盖)
- HDU 3991 Harry Potter and the Present II(Floyd+DAG最小路径覆盖)
- hdu 3991 Harry Potter and the Present II
- hdu 3991 Harry Potter and the Present II
- 最小匹配hdu 3991 Harry Potter and the Present
- hdu3991 Harry Potter and the Present II
- HDU 3987 Harry Potter and the Forbidden Forest 最小割
- 【HDU】3987 Harry Potter and the Forbidden Forest 最小割
- 【最小割】HDU 3987 Harry Potter and the Forbidden Forest
- hdu 3987 Harry Potter and the Forbidden Forest 最小割
- Harry Potter and the Hide Story HDU
- HDU--3987[Harry Potter and the Forbidden Forest] 求最小割集中的最小边数
- hdu 3987 Harry Potter and the Forbidden Forest 求割边最少的最小割
- HDU 3987 Harry Potter and the Forbidden Forest (求割边最少的最小割)
- 一枚电子信息男的困惑
- vc 实现垂直滚动条对话框
- typedef struct与struct
- Linux命令使用技巧
- 这些题目,来测试一下你的C语言水平
- hdu 3991 Harry Potter and the Present II //最小路径覆盖
- Fatal server error:Server is already active for display 0
- java5中的可变参数
- CentOS(with XEN)&Ubuntu双系统引导的问题
- ubuntu下声音的控制方法
- ARM汇编伪指令介绍
- session与cookie的解说
- WEB开发学习之基础
- 用GDB调试程序