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

首頁 > 學(xué)院 > 開發(fā)設(shè)計 > 正文

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

2019-11-14 10:34:28
字體:
供稿:網(wǎng)友

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

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

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

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

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

思路:

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

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

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

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

對于可行方案,增加人數(shù),不可行方案,減少人數(shù)。

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");    }}


發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 商河县| 时尚| 阳江市| 无极县| 临沭县| 泾源县| 亚东县| 汉川市| 楚雄市| 梅河口市| 绥阳县| 库尔勒市| 阳新县| 吉木萨尔县| 阳原县| 湟源县| 安宁市| 库尔勒市| 高州市| 武定县| 冀州市| 清涧县| 古田县| 澄城县| 梅河口市| 自治县| 灵武市| 秦安县| 方城县| 泸西县| 改则县| 嘉黎县| 饶平县| 英德市| 玉山县| 开鲁县| 马山县| 高州市| 五华县| 达拉特旗| 三都|