二分答案,对于当前答案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. TortoiseGit和git bash冲突解决

    软件版本 TortoiseGit版本: TortoiseGit 2.5.0.0 (C:\Program Files\TortoiseGit\bin) git version 2.8.1.windows ...

  2. C、C++、C#中struct的简单比较

    比较这三者是因为C.C++.C#这三者存在着一定的血缘关系,而他们三者都有的struct却有很大的不同. 功能 C中的struct是最简单的.只能有成员变量而不能有成员函数. C++和C#中都支持,而 ...

  3. Android(java)学习笔记122:BroadcastReceiver之 有序广播和无序广播(BroadcastReceiver优先级)

    之前我们在Android(java)学习笔记178中自定义的广播是无序广播,下面我们要了解一下有序广播: 1. 我们首先了解一下有序广播和无序广播区别和联系? (1)有序广播> 接受者有优先级, ...

  4. Linux 备份

    备份之前的准备工作 安装常用的软件 常用软件的安装,见我另一篇blog Ubuntu 16.04 安装札记 的第四部分. 清理系统中没用的垃圾 至于垃圾清理,主要清理对象有 sudo rm -r ~/ ...

  5. Adobe登陆出现Access denied解决方法

    当我安装好Adobe Acrobat Reader DC时,想要登陆Adobe账号时被Access denied. 一般说需要梯子,然而本人亲测这种方法不行(香港主机,全局模式下). 一个简单有效的方 ...

  6. Array - Remove Element

    /** * 无额外空间.顺序可以被改变.不需要修改后面的数字. * @param nums 数组 * @param val 目标值 * @return nums中移除val后的长度 */ public ...

  7. nginx 的反向代理及缓存功能

    上游服务器的设置 server { #监听的IP及端口 listen 127.0.0.1:8080; #虚拟主机对硬解析的主机名 #server_name localhost; #charset ko ...

  8. 剑指offer38 数字在排序数组中出现的次数

    这种方法没用迭代,而是使用了循环的方式 class Solution { public: int GetNumberOfK(vector<int> data ,int k) { if(da ...

  9. QT5:第一章 初始化

    一.简介 二.新建项目 在项目Application中: QT Widgets Application(桌面QT应用) QT Console Application(控制台QT应用) QT for P ...

  10. 测试 code style

    c++ #include <iostream> int main(int argc, char *argv[]) { /* An annoying "Hello World&qu ...