二分答案,对于当前答案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. Android(java)学习笔记128:xml文件生成

    1.xml文件: 用元素描述数据,跨平台. 2.利用传统的方式创建xml文件,下面是一个案例: 设计思路:建立一个学生管理系统,创建xml文件保存学生信息: (1)首先是布局文件activity_ma ...

  2. linux文件查找-find命令

    find命令:用于在文件树中查找文件,并作出相应的处理 1.find命令的格式: find pathname -options [-print -exec -ok ...] {}\ 2.find命令的 ...

  3. linux readahead

    blockdev --getra /dev/sda blockdev --setra 2048 /dev/sda 必须将其写入配置文件/etc/rc.local,否则重启就会失效.[root@loca ...

  4. C10 C语言数据结构

    目录 枚举 结构体 共用体 枚举 enum enum枚举是 C 语言中的一种基本数据类型,它可以让数据更简洁,更易读. 枚举语法定义格式为: enum 枚举名 {枚举元素1,枚举元素2,……}; 枚举 ...

  5. 获取页面的title值

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  6. 27. Remove Element@python

    Given an array nums and a value val, remove all instances of that value in-place and return the new ...

  7. c++结构体双关键字排序

    #include<bits/stdc++.h> using namespace std; struct node{ int l,r; }num[]; int w_comp(const no ...

  8. Unity基础-脚本的基本使用

    脚本的基本使用 定义与挂载monobehaviour 1.新建一个场景 2.新建脚本 using System.Collections; using System.Collections.Generi ...

  9. quartz 任务调度

    quartz 设置参数, 获取参数 在job中使用spring注入的service对象 循环获取所有的job 删除job @PersistJobDataAfterExecution @Disallow ...

  10. 腾讯云Ubuntu服务器修改root密码

    1.修改root密码 执行以下命令,按照提示修改密码 sudo passwd root 2.修改ssh配置 执行以下命令 sudo vi /etc/ssh/sshd_config 找到 PermitR ...