二分答案,对于当前答案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. 剑指offer24 二叉搜索树的后序遍历序列

    自己写的更简洁的代码 class Solution { public: bool VerifySquenceOfBST(vector<int> sequence) { int length ...

  2. Elastic Search Java Api 创建索引结构,添加索引

    创建TCP客户端 Client client = new TransportClient() .addTransportAddress(new InetSocketTransportAddress( ...

  3. 【转】Intellij IDEA 提交代码到远程GitHub仓库

    1.文章参考自:http://my.oschina.net/lujianing/blog/180728 2.设置相关绑定 Settings——Version Control——Git——Path to ...

  4. Python——三目运算符

    一.三目运算符 1.if语句三目运算符语法格式 Python可以通过if'语句来实现三目运算符的功能,因此可以把这种if语句当做三目运算符,具体语法格式如下: 返回True执行 if 表达式 else ...

  5. 第三单元OO总结

  6. javaweb基础(18)_jsp属性范围

    所谓的属性范围就是一个属性设置之后,可以经过多少个其他页面后仍然可以访问的保存范围. 一.JSP属性范围 JSP中提供了四种属性范围,四种属性范围分别指以下四种: 当前页:一个属性只能在一个页面中取得 ...

  7. java基础—基础语法2

    一.语句

  8. JavaScript无提示关闭当前页面窗口,兼容IE/Firefox/Chrome

    <script type="text/javascript" language="javascript"> function fc(){ var b ...

  9. libnet TCP示例

    [root@TD18 tmp]#gcc -o .c -lnet [root@TD18 tmp]#./ please enter Host address 11.11.11.11 please ente ...

  10. python面向对象之抽象工厂设计模式

    class truck: def use(self): return "拉货" def __str__(self): return "大卡车" class mi ...