国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

Codeforces 514D R2D2 and Droid Army【二分+RMQ】

2019-11-14 10:35:41
字體:
來源:轉載
供稿:網友

D. R2D2 and Droid Armytime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

An army of n droids is lined up in one row. Each droid is described bym integers a1,?a2,?...,?am, whereai is the number of details of thei-th type in this droid's mechanism. R2-D2 wants to destroy the sequence of consecutive droids of maximum length. He hasm weapons, the i-th weapon can affect all the droids in the army by destroying one detail of thei-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 mostk 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 containsm integers a1,?a2,?...,?am (0?≤?ai?≤?108), where ai is the number of details of thei-th type for the respective robot.

Output

PRint m space-separated integers, where thei-th number is the number of shots from the weapon of thei-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.

ExamplesInput
5 2 44 01 22 10 21 3Output
2 2Input
3 2 41 21 32 2Output
1 3Note

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個屬性值,當一個人的所有屬性值都小于等于0的時候,這個人就算被銷毀了。

我們每次操作可以選一種屬性值進行攻擊,使得所有人的這個屬性的值都-1.

我們最多可以進行K次操作,

問我們最多可以干掉多少個連續的人。

問這種時候的具體操作(每一種屬性用了多少次操作)。

思路:

1、比較經典的模型,對于連續的X個人,假如都將其干掉的時候,需要對于每種屬性使用的最少操作,就是對應這連續的X個人每種屬性的最大值。

2、那么問題轉化到區間最大值上來,這里我們可以使用RMQ來解,也可以用線段樹來解。

接下來我們可以考慮枚舉人數,然后O(NLogN)的去維護當前情況是否可行,直到枚舉到不可行為止前的那個答案,就是最終答案。

由此看來,枚舉人數是具有單調性的,要干掉更多的人,就需要更多的操作,那么我們可以二分這個人數。

對于可行方案,增加人數,不可行方案,減少人數。

3、二分過程中,維護最后一次可行解的答案,輸出即可。

Ac代碼:

#include<stdio.h>#include<string.h>#include<math.h>#include<iostream>using namespace std;int maxn[10][200005][20];int a[200060][10];int output[10];int n,m,k;void ST(){    for(int i=1;i<=m;i++)    {        for(int j=1;j<=n;j++)        {            maxn[i][j][0]=a[j][i];        }    }    int len=floor(log10(double(n))/log10(double(2)));    for(int z=1;z<=m;z++)    {        for(int j=1;j<=len;j++)        {            for(int i=1;i<=n+1-(1<<j);i++)            {                maxn[z][i][j]=max(maxn[z][i][j-1],maxn[z][i+(1<<(j-1))][j-1]);            }        }    }}int Slove(int mid){    int ans[10];    for(int i=1;i<=n;i++)    {        if(i+mid-1>n)break;        else        {            int a=i;int b=i+mid-1;            int len= floor(log10(double(b-a+1))/log10(double(2)));            for(int z=1;z<=m;z++)            {                ans[z]=max(maxn[z][a][len], maxn[z][b-(1<<len)+1][len]);            }            int sum=0;            for(int z=1;z<=m;z++)            {                sum+=ans[z];            }            if(sum<=k)            {                for(int z=1;z<=m;z++)                {                    output[z]=ans[z];                }                return 1;            }        }    }    return 0;}int main(){    while(~scanf("%d%d%d",&n,&m,&k))    {        for(int i=1;i<=n;i++)        {            for(int j=1;j<=m;j++)            {                scanf("%d",&a[i][j]);            }        }        ST();        int l=0;        int r=n;        while(r-l>=0)        {            int mid=(l+r)/2;            if(Slove(mid)==1)            {                l=mid+1;            }            else r=mid-1;        }        for(int i=1;i<=m;i++)        {            printf("%d ",output[i]);        }        printf("/n");    }}


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 尼玛县| 出国| 吉木乃县| 霍山县| 延庆县| 棋牌| 上犹县| 虞城县| 肃北| 深水埗区| 丰县| 宁远县| 隆尧县| 麦盖提县| 临夏市| 蓬溪县| 府谷县| 化州市| 鞍山市| 吉安市| 峨眉山市| 衡东县| 余姚市| 萨嘎县| 珠海市| 曲沃县| 张家界市| 射阳县| 天等县| 沙雅县| 蓬莱市| 天峨县| 松阳县| 五莲县| 海丰县| 文成县| 孟州市| 咸阳市| 页游| 新巴尔虎左旗| 金寨县|