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

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

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

2019-11-14 10:00:51
字體:
供稿:網(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個(gè)人,每個(gè)人有M個(gè)屬性值,當(dāng)一個(gè)人的所有屬性值都小于等于0的時(shí)候,這個(gè)人就算被銷毀了。

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

我們最多可以進(jìn)行K次操作,

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

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

思路:

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

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

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

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

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

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

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ā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 玉林市| 清徐县| 色达县| 泗洪县| 博野县| 桐乡市| 舟曲县| 柳河县| 应城市| 玛曲县| 忻城县| 泗洪县| 涞水县| 秦皇岛市| 永泰县| 阿尔山市| 东丽区| 南宁市| 临安市| 红河县| 西充县| 多伦县| 齐河县| 永德县| 衡山县| 赫章县| 酒泉市| 清水县| 平山县| 呼图壁县| 正定县| 田阳县| 聊城市| 科技| 沿河| 咸丰县| 叙永县| 视频| 文化| 阿克陶县| 太保市|