POJ 3343 Against Mammoths

本文深入探讨了信息技术领域的策略规划与算法应用,包括大数据处理、人工智能、云计算、区块链等前沿技术,以及软件开发、测试、运维等核心环节。文章详细解析了不同技术领域的关键概念、实践案例和未来发展趋势,旨在为读者提供全面的技术洞察和实操指南。

Against Mammoths
Time Limit: 2000MS Memory Limit: 65536K
Total Submissions: 1676 Accepted: 542

Description

Back to year 3024, humans finally developed a new technology that enables them to conquer the alien races. The new technology made it possible to produce huge spaceships known as Saber Tooth spaceships as powerful as the aliens' defending mammoths. At that time, humans ruled several planets while some others were under control of the aliens. Using Saber Tooth ships, humans finally defeated aliens and this became the first Planet War in history. Our goal is to run a simulation of the ancient war to verify some historical hypotheses.

Producing each spaceship takes an amount of time which is constant for each planet but may vary among different planets. We call the number of spaceships each planet can produce in a year, the production rate of that planet. Note that each planet has a number of spaceships in it initially (before the simulation starts). The planets start producing ships when the simulation starts, so if a planet has n ships initially, and has the production rate p, it will have n + p ships at the beginning of year 1, and n + i × p ships at the beginning of year i (years are started from zero).

Bradley Bennett, the commander in chief of the human armies, decided a strategy for the war. For each alien planet A, he chooses a corresponding human planet P, and produces spaceships in P until a certain moment at which he sends all spaceships in P to invade the planet A. No alien planet is invaded by two human planets and no human planet sends its spaceships to two different alien planets.

The defense power of the alien planets comes from their powerful mammoths. Each alien planet contains a number of mammoths initially and produces a number of mammoths each year (called the production rate of the planet). When a fight between spaceships and mammoths takes place, the side having the greater number of troops is the winner. If the spaceships win, the alien planet is defeated. In case the number of mammoths and spaceships are equal, the spaceships win.

The difficulty with planning this strategy is that it takes some time for the spaceships to reach the alien planets, and during this time, the aliens produce mammoths. The time required for spaceships to travel from each human planet to each alien planet is known. The ships can leave their planets only at the beginning of years (right after the ships are produced) and reach the alien planets at the beginning of years too (right after the mammoths are produced).

As an example, consider a human planet with two initial spaceships and production rate three invading an alien planet with two initial mammoths and production rate two. The time required to travel between the two planets is two years and the ships are ordered to leave at year one. In this case, five ships leave the human planet. When they reach the alien planet, they confront eight mammoths and will be defeated during the fight.

Bennett decided to prepare a plan that destroys every alien planet in the shortest possible time. Your task is to write a program to generate such a plan. The output is the shortest possible time (in years) in which every alien planet is defeated.

Input

There are multiple test cases in the input. The first line of each test case contains two numbers H and A which are the number of planets under the control of humans and aliens respectively (both between 1 and 250). The second line of the test case contains H non-negative integers n1 m1 n2 m2 … nH mH. The number ni is the initial number of Saber Tooth spaceships in the ith human planet and mi is the production rate of that planet. The third line contains A non-negative integers which specify the initial number of mammoths and the production rate of the alien planets in the same format as the second line. After the third line, there are H lines each containingA positive integers. The jth number on the ith line shows how many years it takes a spaceship to travel from the ith human planet to the jth alien planet. The last line of the input contains two zero numbers. Every number in the input except H and A is between 0 and 40000.

Output

The output for each test case contains a single integer which is the minimum time in which all alien planets can be defeated. If it is impossible to destroy all alien planets, the output should be IMPOSSIBLE.

Sample Input

2 1
2 3 0 3
2 2
2
2
0 0

Sample Output

6

思路:通过二分时间来求最大匹配,用上静态邻接表还要2000+MS,超时的可能性比较大。poj的时间限制会比较松。但还是没过啊!!


#include<stdio.h>
#include<string.h>
#define inf 0x6fffffff
int n,m,top;
int edge[9000][9000];
int visit[90000],link[90000];

struct edg
{
    int v;
    int next;
}edg[90000];
int hand[90000];

struct plane
{
    int init;
    int rate;
}e[90000],a[90000];

void addedge(int i,int j)
{
    edg[top].v=j;
    edg[top].next=hand[i];
    hand[i]=top++;
}
int check(int time,int dis,plane h,plane a)
{
    if(time<dis) return 0;
    if(h.init>=a.init+dis*a.rate) return 1;
    if(h.init+h.rate*(time-dis)>=a.init+a.rate*time) return 1;
    return 0;
}

int find(int x)
{
    int i;
    for(i=hand[x];i!=-1;i=edg[i].next)
    {
        int k=edg[i].v;
        if(!visit[k])
        {
            visit[k]=1;
            if(!link[k]||find(link[k]))
            {
                link[k]=x;
                return 1;
            }
        }
    }
    return 0;
}

void solve()
{
    int k=-1;
    int l_time=0;
    int h_time=inf;
    int m_time; 
    while(l_time<=h_time)       //二分时间
    {
        m_time=(l_time+h_time)/2;
        memset(link,0,sizeof(link));
        memset(hand,-1,sizeof(hand));
        top=0;
        int i,j;
        for(i=1;i<=n;i++)
        {
            for(j=1;j<=m;j++)
            {
                if(check(m_time,edge[i][j],e[i],a[j]))
                {
                    addedge(i,j);
                }
            }
        }
        int sum=0;
        for(i=1;i<=n;i++)
        {
            memset(visit,0,sizeof(visit));
            if(find(i)) sum++;
        }
        if(sum==m)
        {
            k=m_time;
            h_time=m_time-1;
        }
        else l_time=m_time+1;
    }
    if(k!=-1) printf("%d\n",k);
    else printf("IMPOSSIBLE\n");
}
int main()
{
    while(scanf("%d %d",&n,&m)!=EOF)
    {
        if(n==0&&m==0) break;
        int i;
        for(i=1;i<=n;i++) scanf("%d %d",&e[i].init,&e[i].rate);
        for(i=1;i<=m;i++) scanf("%d %d",&a[i].init,&a[i].rate);
        int j;
        for(i=1;i<=n;i++)
        {
            for(j=1;j<=m;j++)
            {
                scanf("%d",&edge[i][j]);
            }
        }
        solve();
    }
}




**项目名称:** 基于Vue.jsSpring Cloud架构的博客系统设计开发——微服务分布式应用实践 **项目概述:** 本项目为计算机科学技术专业本科毕业设计成果,旨在设计并实现一个采用前后端分离架构的现代化博客平台。系统前端基于Vue.js框架构建,提供响应式用户界面;后端采用Spring Cloud微服务架构,通过服务拆分、注册发现、配置中心及网关路由等技术,构建高可用、易扩展的分布式应用体系。项目重点探讨微服务模式下的系统设计、服务治理、数据一致性及部署运维等关键问题,体现了分布式系统在Web应用中的实践价值。 **技术架构:** 1. **前端技术栈:** Vue.js 2.x、Vue Router、Vuex、Element UI、Axios 2. **后端技术栈:** Spring Boot 2.x、Spring Cloud (Eureka/Nacos、Feign/OpenFeign、Ribbon、Hystrix、Zuul/Gateway、Config) 3. **数据存储:** MySQL 8.0(主数据存储)、Redis(缓存会话管理) 4. **服务通信:** RESTful API、消息队列(可选RabbitMQ/Kafka) 5. **部署运维:** Docker容器化、Jenkins持续集成、Nginx负载均衡 **核心功能模块:** - 用户管理:注册登录、权限控制、个人中心 - 文章管理:富文本编辑、分类标签、发布审核、评论互动 - 内容展示:首页推荐、分类检索、全文搜索、热门排行 - 系统管理:后台仪表盘、用户内容监控、日志审计 - 微服务治理:服务健康检测、动态配置更新、熔断降级策略 **设计特点:** 1. **架构解耦:** 前后端完全分离,通过API网关统一接入,支持独立开发部署。 2. **服务拆分:** 按业务域划分为用户服务、文章服务、评论服务、文件服务等独立微服务。 3. **高可用设计:** 采用服务注册发现机制,配合负载均衡熔断器,提升系统容错能力。 4. **可扩展性:** 模块化设计支持横向扩展,配置中心实现运行时动态调整。 **项目成果:** 完成了一个具备完整博客功能、具备微服务典型特征的分布式系统原型,通过容器化部署验证了多服务协同运行的可行性,为云原生应用开发提供了实践参考。 资源来源于网络分享,仅用于学习交流使用,请勿用于商业,如有侵权请联系我删除!
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值