R2D2 and Droid Army--CSU-ACM2017暑假集训比赛1

探讨了如何利用不同类型的武器摧毁连续排列的机器人,以达到最大数量的连续摧毁效果。通过区间最大值查询(RMQ)和线段树等算法实现,采用二分查找确定最优解。
部署运行你感兴趣的模型镜像



An army of n droids is lined up in one row. Each droid is described by m integers a1, a2, ..., am, where ai is the number of details of the i-th type in this droid's mechanism. R2-D2 wants to destroy the sequence of consecutive droids of maximum length. He has m weapons, the i-th weapon can affect all the droids in the army by destroying one detail of the i-th type (if the droid doesn't have details of this type, nothing happens to it).
A droid is considered to be destroyed when all of its details are destroyed. R2-D2 can make at most k shots. How many shots from the weapon of what type should R2-D2 make to destroy the sequence of consecutive droids of maximum length?
Input
The first line contains three integers n, m, k (1 ≤ n ≤ 105, 1 ≤ m ≤ 5, 0 ≤ k ≤ 109) — the number of droids, the number of detail types and the number of available shots, respectively.
Next n lines follow describing the droids. Each line contains m integers a1, a2, ..., am (0 ≤ ai ≤ 108), where ai is the number of details of the i-th type for the respective robot.
Output
Print m space-separated integers, where the i-th number is the number of shots from the weapon of the i-th type that the robot should make to destroy the subsequence of consecutive droids of the maximum length.
If there are multiple optimal solutions, print any of them.
It is not necessary to make exactly k shots, the number of shots can be less.
Example
Input
5 2 4
4 0
1 2
2 1
0 2
1 3
Output
2 2
Input
3 2 4
1 2
1 3
2 2
Output
1 3
Note
In the first test the second, third and fourth droids will be destroyed.
In the second test the first and second droids will be destroyed.




题目大意:有n个机器人连续站着,每个机器人有m个属性值。现可以用m种武器打机器人,打一次则所有机器人的相应属性减1. 当一个机器人所有属性都减为0时就死亡。一共可以打k次,问分别用这m种武器打多少枪可以使得杀死的连在一起的机器人最多?

思路:

1、比较经典的模型,对于连续的X个人,假如都将其干掉的时候,需要对于每种属性使用的最少操作,就是对应这连续的X个人每种属性的最大值。


2、那么问题转化到区间最大值上来,这里我们可以使用RMQ来解,也可以用线段树来解。
接下来我们可以考虑枚举人数,然后O(NLogN)的去维护当前情况是否可行,直到枚举到不可行为止前的那个答案,就是最终答案。
由此看来,枚举人数是具有单调性的,要干掉更多的人,就需要更多的操作,那么我们可以二分这个人数。
对于可行方案,增加人数,不可行方案,减少人数。


3、二分过程中,维护最后一次可行解的答案,输出即可。


AC代码:

#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>

using namespace std;

const int k=log(100009.0)/log(2.0)+1;

int store[100009][9];
int STstore[100009][9][k];
int n,m,l,cnt,finalcnt;
int ans[9],output[9];


void STini()
{
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
            STstore[i][j][0]=store[i][j];
    for(int x=1;x<=m;x++)
    for(int j=1;j<=k;j++)
        for(int i=1;i<=n;i++)
        {
            if(i+(1<<j)-1>n)break;
            STstore[i][x][j]=max(STstore[i][x][j-1],STstore[i+(1<<(j-1))][x][j-1]);
        }
}

bool judge(int mid)
{
    bool flag=0;
    cnt=1;
    for(int i=1;i<=n;i++)
    {
        if(i+mid-1>n)break;
        int a=i,b=i+mid-1;
        int len=log(double(mid))/log(double(2));
        for(int z=1;z<=m;z++)
        {
            ans[z]=max(STstore[a][z][len],STstore[b-(1<<len)+1][z][len]);
        }
		
        int sum=0;
        for(int z=1;z<=m;z++)
            sum+=ans[z];
        if(sum<=l)
        {
			
		    for(int z=1;z<=m;z++)  
                output[z]=ans[z];
            flag=1;
        }
    }

    return flag;

}

int main()
{
    cin>>n>>m>>l;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
            scanf("%d",&store[i][j]);

    STini();

    int ll=0,rr=n,mid;
    while(ll<=rr)
    {
        mid=(ll+rr)/2;
        if(judge(mid))
            ll=mid+1;
        else
            rr=mid-1;
    }
	
	
    for(int i=1;i<=m;i++)  
    {  
        printf("%d ",output[i]);  
    }  
    printf("\n");

}




您可能感兴趣的与本文相关的镜像

Wan2.2-T2V-A5B

Wan2.2-T2V-A5B

文生视频
Wan2.2

Wan2.2是由通义万相开源高效文本到视频生成模型,是有​50亿参数的轻量级视频生成模型,专为快速内容创作优化。支持480P视频生成,具备优秀的时序连贯性和运动推理能力

基于实时迭代的数值鲁棒NMPC双模稳定预测模型(Matlab代码实现)内容概要:本文介绍了基于实时迭代的数值鲁棒非线性模型预测控制(NMPC)双模稳定预测模型的研究与Matlab代码实现,重点在于提升系统在存在不确定性与扰动情况下的控制性能与稳定性。该模型结合实时迭代优化机制,增强了传统NMPC的数值鲁棒性,并通过双模控制策略兼顾动态响应与稳态精度,适用于复杂非线性系统的预测控制问题。文中还列举了多个相关技术方向的应用案例,涵盖电力系统、路径规划、信号处理、机器学习等多个领域,展示了该方法的广泛适用性与工程价值。; 适合人群:具备一定控制理论基础和Matlab编程能力,从事自动化、电气工程、智能制造、机器人控制等领域研究的研究生、科研人员及工程技术人员。; 使用场景及目标:①应用于非线性系统的高性能预测控制设计,如电力系统调度、无人机控制、机器人轨迹跟踪等;②解决存在模型不确定性、外部扰动下的系统稳定控制问题;③通过Matlab仿真验证控制算法的有效性与鲁棒性,支撑科研论文复现与工程原型开发。; 阅读建议:建议读者结合提供的Matlab代码进行实践,重点关注NMPC的实时迭代机制与双模切换逻辑的设计细节,同时参考文中列举的相关研究方向拓展应用场景,强化对数值鲁棒性与系统稳定性之间平衡的理解。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值