【题目链接】:http://codeforces.com/contest/514/problem/D

【题意】



给你每个机器人的m种属性p1..pm

然后r2d2每次可以选择m种属性中的一种,进行一次攻击;

攻击过后每个机器人的该种属性都减少1;

可以最多攻击k次;

机器人只有m种属性都变为0之后才死掉;

然后问你如何分配这k次攻击,每次攻击时选择的属性;

使得连续的死掉的机器人的区间长度最长;

【题解】



对于选择的一个区间[l..r]

如果要使得这个区间的机器人全都死掉;

则需要攻击的次数就为

max(a[l..r][1])+max(a[l..r][2])+...+max(a[l..r][m])

因为某一种属性的在这个区间的最大值如果都变成0了,那么其他的也就变成0了;

则问题就是RMQ问题了;

然后写个二分;

枚举左端点,二分右端点;

上面那个值小于等于k就符合,增大右端点

否则减小右端点

写了个ST算法的。没写线段树



【Number Of WA】



0



【完整代码】

#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define ps push_back
#define fi first
#define se second
#define rei(x) scanf("%d",&x)
#define rel(x) scanf("%lld",&x)
#define ref(x) scanf("%lf",&x)
#define ms(x,y) memset(x,y,sizeof x) typedef pair<int,int> pii;
typedef pair<LL,LL> pll; const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0);
const int N = 1e5+100;
const int M = 5+3;
const int maxpow = 20; int n,m,k;
int a[M][N],two[maxpow];
int f[M][N][maxpow],need[N];
int ans[M],len,temp[M]; int main()
{
//freopen("F:\\rush.txt","r",stdin);
rei(n),rei(m),rei(k);
rep1(i,1,n)
rep1(j,1,m)
rei(a[j][i]);
two[0] = 1;
rep1(i,1,17)
two[i] = two[i-1]*2;
need[1] = 0;
int now = 1;
rep1(i,2,100000)
if (i==two[now])
{
now++;
need[i]=need[i-1]+1;
}
else
need[i]=need[i-1];
rep1(i,1,m)
rep1(j,1,n)
f[i][j][0] = a[i][j];
rep1(k,1,m)
{
for (int l = 1;two[l]<=n;l++)
{
rep1(i,1,n)
{
if (i+two[l]-1>n) break;
int j = i+two[l]-1;
f[k][i][l] = max(f[k][i][l-1],f[k][j-two[l-1]+1][l-1]);
}
}
}
rep1(i,1,n)
{
int l = i,r = n;
while (l <= r)
{
int mid = (l+r)>>1;
//i..mid
int cd = need[mid-i+1],cost = 0;
rep1(j,1,m)
{
temp[j] = max(f[j][i][cd],f[j][mid-two[cd]+1][cd]);
cost+=temp[j];
}
if (cost<=k)
{
if (mid-i+1>len)
{
rep1(j,1,m)
ans[j] = temp[j];
len = mid-i+1;
}
l = mid+1;
}
else
r = mid-1;
}
}
rep1(i,1,m)
printf("%d ",ans[i]);
//printf("\n%.2lf sec \n", (double)clock() / CLOCKS_PER_SEC);
return 0;
}

【codeforces 514D】R2D2 and Droid Army的更多相关文章

  1. 【Cf #291 B】R2D2 and Droid Army(二分,线段树)

    因为题目中要求使连续死亡的机器人最多,令人联想到二分答案. 考虑如何检验这之中是否存在一段连续的长度为md的区间,其中花最多k步使得它们都死亡. 这个条件等价于区间中m个最大值的和不超过k. 枚举起点 ...

  2. Codeforces 514 D R2D2 and Droid Army(RMQ+二分法)

    An army of n droids is lined up in one row. Each droid is described by m integers a1, a2, ..., am, w ...

  3. Codeforces 514 D R2D2 and Droid Army(Trie树)

    题目链接 大意是判断所给字符串组中是否存在与查询串仅一字符之差的字符串. 关于字符串查询的题,可以用字典树(Trie树)来解,第一次接触,做个小记.在查询时按题目要求进行查询. 代码: #define ...

  4. Codeforces Round #291 (Div. 2) D. R2D2 and Droid Army [线段树+线性扫一遍]

    传送门 D. R2D2 and Droid Army time limit per test 2 seconds memory limit per test 256 megabytes input s ...

  5. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  6. R2D2 and Droid Army(多棵线段树)

    R2D2 and Droid Army time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  7. 【codeforces 546E】Soldier and Traveling

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  8. 【codeforces 707E】Garlands

    [题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...

  9. 【codeforces 707C】Pythagorean Triples

    [题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...

随机推荐

  1. remove namespace from xml config file

    从xml配置文件中移除命令空间 https://stackoverflow.com/questions/987135/how-to-remove-all-namespaces-from-xml-wit ...

  2. c#用webkit内核支持html5

    [实例简介]经过测试可用 [实例截图] [核心代码] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 using System; ...

  3. CSS小代码汇总整理

    /**实现斑马线的表格*/table.flexme tbody tr:nth-child(2n){background-color:#D6E7FC;} /*返回偶数序的子元素*/table.flexm ...

  4. Django-CKeditor使用笔记

    1. 安装django-ckeditor $ pip install django-ckeditor 2. 在setting中,添加ckeditor , ckeditor_uploader 到INST ...

  5. TextMeshPro 图片字Sprite

      生成 需要一个资源  右键生成 调整位置  放在目录  使用 <sprite="NumDamage" index=1><sprite="NumDam ...

  6. P1462 通往奥格瑞玛的道路(二分答案+最短路)

    P1462 通往奥格瑞玛的道路 题目背景 在艾泽拉斯大陆上有一位名叫歪嘴哦的神奇术士,他是部落的中坚力量 有一天他醒来后发现自己居然到了联盟的主城暴风城 在被众多联盟的士兵攻击后,他决定逃回自己的家乡 ...

  7. bzoj2730矿场搭建(Tarjan割点)

    2730: [HNOI2012]矿场搭建 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 1771  Solved: 835[Submit][Statu ...

  8. H5 触摸事件

    HTML5中新添加了很多事件,但是由于他们的兼容问题不是很理想,应用实战性不是太强,所以在这里基本省略,咱们只分享应用广泛兼容不错的事件,日后随着兼容情况提升以后再陆续添加分享.今天为大家介绍的事件主 ...

  9. Django day30 自定义配置settings文件,分页器,版本控制

    一:自定义配置settings文件 1.有两套配置文件,默认配置,用户的配置 2.如果某个字段,用户配置了,就用用户的,如果没配置,就用默认的 二:分页器 1.三种分页: # 普通分页 from re ...

  10. Akka源码分析-ActorSystem

    由于本人对Akka比较感兴趣,也用Akka开发了一些系统,但对Akka的源码还没有具体分析过,希望研究源码的同时写一点博客跟大家分享.有不当之处还请指正.我准备采取Debug的方式来研究Akka的运行 ...