二分答案,对于当前答案Ans,求出某些人类可打败某些外星人的对应边,建图后求是否有完备匹配。

//#include <cmath>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <fstream>
#include <iostream> #define rep(i, l, r) for(int i=l; i<=r; i++)
#define down(i, l, r) for(int i=l; i>=r; i--)
#define N 259
#define MAX 1<<30
#define ll long long using namespace std;
int read()
{
int x=0, f=1; char ch=getchar();
while (ch<'0' || ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
while (ch>='0' && ch<='9') { x=x*10+ch-'0'; ch=getchar(); }
return x*f;
} struct edge{int y, n;} e[N*N]; int fir[N], en;
int na, nb, ma[N], mb[N], ra[N], rb[N], now, k[N], b[N], d[N][N], l, r;
ll t; void Add(int x, int y) { en++, e[en].y=y, e[en].n=fir[x], fir[x]=en; } bool Find(int x)
{
int o=fir[x], y=e[o].y;
while (o)
{
if (b[y]!=now)
{
b[y]=now;
if (!k[y] || Find(k[y])) { k[y]=x; return true; }
}
o=e[o].n, y=e[o].y;
}
return false;
} int main()
{
while(scanf("%d %d", &na, &nb) && (na || nb))
{
rep(i, 1, na) ma[i]=read(), ra[i]=read();
rep(i, 1, nb) mb[i]=read(), rb[i]=read();
rep(i, 1, na) rep(j, 1, nb) d[i][j]=read(); l=0, r=MAX;
while (l!=r)
{
t=(l+r)/2; bool can=true;
rep(i, 1, nb) fir[i]=0; en=0;
rep(i, 1, na)
rep(j, 1, nb)
{
if(d[i][j] > t) continue;
ll s1 = ma[i]+ra[i]*(t-d[i][j]);
ll s2 = mb[j]+rb[j]*t;
if(s1 >= s2) Add(j, i);
}
rep(i, 1, na) k[i]=b[i]=0;
rep(i, 1, nb) if (!Find(now=i)) { can=false; break; }
if (can) r=t; else l=t+1;
}
if (l==MAX) printf("IMPOSSIBLE\n"); else printf("%d\n", l);
}
return 0;
}

HDU-2413 Against Mammoths的更多相关文章

  1. hdu 2413(最大匹配+二分)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2413 思路:由于要求最少的时间,可以考虑二分,然后就是满足在limit时间下,如果地球战舰数目比外星战 ...

  2. HDU——PKU题目分类

    HDU 模拟题, 枚举1002 1004 1013 1015 1017 1020 1022 1029 1031 1033 1034 1035 1036 1037 1039 1042 1047 1048 ...

  3. hdu 1716(dfs)

    题目链接 : http://acm.hdu.edu.cn/showproblem.php?pid=1716     排列2   Problem Description Ray又对数字的列产生了兴趣:现 ...

  4. 【转载】图论 500题——主要为hdu/poj/zoj

    转自——http://blog.csdn.net/qwe20060514/article/details/8112550 =============================以下是最小生成树+并 ...

  5. hdu 1716 排列2(DFS搜索)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1716 排列2 Time Limit: 1000/1000 MS (Java/Others)    Me ...

  6. HDU 4489 The King’s Ups and Downs dp

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4489 The King's Ups and Downs Time Limit: 2000/1000 ...

  7. HDU 5643 King's Game 打表

    King's Game 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5643 Description In order to remember hi ...

  8. hdu图论题目分类

    =============================以下是最小生成树+并查集====================================== [HDU] 1213 How Many ...

  9. HDU图论题单

    =============================以下是最小生成树+并查集====================================== [HDU] 1213 How Many ...

  10. STL训练 HDU - 1716 Ray又对数字的列产生了兴趣:

    HDU - 1716 Ray又对数字的列产生了兴趣: 现有四张卡片,用这四张卡片能排列出很多不同的4位数,要求按从小到大的顺序输出这些4位数. Input 每组数据占一行,代表四张卡片上的数字(0&l ...

随机推荐

  1. Codeforces Round #321 (Div. 2) C Kefa and Park(深搜)

    dfs一遍,维护当前连续遇到的喵的数量,然后剪枝,每个统计孩子数量判断是不是叶子结点. #include<bits/stdc++.h> using namespace std; ; int ...

  2. Harvest of Apples

    问题 B: Harvest of Apples 时间限制: 1 Sec  内存限制: 128 MB提交: 18  解决: 11[提交] [状态] [讨论版] [命题人:admin] 题目描述 Ther ...

  3. Python 模块(二)

    1 logging 模块 logging有两种的配置的方式,configure.logger 1.1 config方式 import logging ''' 日志的配置:config模式 只能选择在屏 ...

  4. mysql绿色版下载及应用

    一.mysql绿色版下载 第一歩:打开下载网址:https://www.oracle.com 点击Menu-->Database and Technologies-->Databases- ...

  5. c++ 调用php

    int _System(const char * cmd, std::string& strRet) { FILE * fp; char * p = NULL; ; if ((fp = _po ...

  6. c++ 函数指针应用,定义一个方法,传入两个参数和一个函数指针,并返回结果

    #include <iostream> #include <string> using namespace std; double add(double x, double y ...

  7. Codevs1033 蚯蚓的游戏

    题目描述 Description 在一块梯形田地上,一群蚯蚓在做收集食物游戏.蚯蚓们把梯形田地上的食物堆积整理如下: a(1,1)  a(1,2)…a(1,m) a(2,1)  a(2,2)  a(2 ...

  8. [vijos]P1979 NOIP2015 信息传递

    描述 有 n 个同学(编号为 1 到 n)正在玩一个信息传递的游戏.在游戏里每人都有一个固定的信息传递对象,其中,编号为 i 的同学的信息传递对象是编号为 TiTi 的同学. 游戏开始时,每人都只知道 ...

  9. Mysql数据库插入中文出现乱码相关

    查看数据库编码的命令:show variables like "character%"; mysql> show variables like "character ...

  10. MySQL多源复制

    MySQL多源复制 1. 配置多源复制 1.1 配置环境如下 1.2 从库的重要参数配置 1.3 在Master上导出需要同步的数据库 1.4 在master上创建复制账号 1.5 备份数据导入 1. ...