【codeforces 514D】R2D2 and Droid Army
【题目链接】: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的更多相关文章
- 【Cf #291 B】R2D2 and Droid Army(二分,线段树)
因为题目中要求使连续死亡的机器人最多,令人联想到二分答案. 考虑如何检验这之中是否存在一段连续的长度为md的区间,其中花最多k步使得它们都死亡. 这个条件等价于区间中m个最大值的和不超过k. 枚举起点 ...
- 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 ...
- Codeforces 514 D R2D2 and Droid Army(Trie树)
题目链接 大意是判断所给字符串组中是否存在与查询串仅一字符之差的字符串. 关于字符串查询的题,可以用字典树(Trie树)来解,第一次接触,做个小记.在查询时按题目要求进行查询. 代码: #define ...
- 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 ...
- 【codeforces 415D】Mashmokh and ACM(普通dp)
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
- R2D2 and Droid Army(多棵线段树)
R2D2 and Droid Army time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- 【codeforces 546E】Soldier and Traveling
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【codeforces 707E】Garlands
[题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...
- 【codeforces 707C】Pythagorean Triples
[题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...
随机推荐
- YTU 2750: 猜算式
2750: 猜算式 时间限制: 1 Sec 内存限制: 128 MB Special Judge 提交: 22 解决: 1 题目描述 看下面的算式: □□ x □□ = □□ x □□□ 它表示 ...
- 【HAOI 2008】 糖果传递
[题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=1045 [算法] 环形均分纸牌问题 [代码] #include<bits/std ...
- Area of Polycubes
http://poj.org/problem?id=3792 题意:给出n个小正方体的中心坐标,求构成的多重小立方体的表面积.要求输入的下一个小正方体必须与之前的正方体有一个面是相交的.如果不满足条件 ...
- [Swift通天遁地]四、网络和线程-(9)上传图片并实时显示上传进度
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...
- linux tmux基本操作
1. 安装工具 Centos : yum install tmux 2. 基本操作 新建会话:tmux new -s session-name 查看会话:tmux ls 进入会话:tmux a -t ...
- 安装git,创建本地版本库
安装 由于我使用的是Ubuntu,因此安装很简单,输入:sudo apt-get install git 如果是其他Linux版本,可以直接通过源码安装.先从Git官网下载源码,然后解压,依次输入:. ...
- excel另存为csv
# -*- coding: utf-8 -*- """ Created on Tue Jul 11 21:25:57 2017 import pandas as pd i ...
- Coursera公开课-Machine_learing:编程作业8(2016-10-06 20:49)
Anomaly Detection and Recommender Systems 本周编程作业分为两部分:异常检测和推荐系统. 异常检测:本质就是使用样本的到特种值的gaussian分布,来预估正确 ...
- Perforce 的基本使用教程
一.简介 P4是什么 二.基本使用方法 1.下载代码 下载最新代码 Get Latest Revision 下载指定commit代码 Get Revision 2. 检出代码 选择指定目录,右键 Ch ...
- Java类加载机制总结
关于Java类加载机制的几个基本概念: JDK提供的基本类加载器:引导类加载器(Bootstrap Class Loader)-用于加载JDK中的核心类.扩展类加载器(Ext Class Loader ...