题目

题意:

有n * k块木板,每个木桶由k木板组成,每个木桶的容量定义为它最短的那块木板的长度。

任意两个木桶的容量v1,v2,满足|v1-v2| <= d。

问n个木桶容量的最大的和为多少,或者说明不可能做出这样的n个木桶。

思路:

一道纯粹的贪心题,可以确定最小的数MIN,那莫其他区间的最小的数就不能大过MIN+l ,  可以想出假设我们从小到大排序,我们的目的是尽可能的把不满足条件的与满足条件的最大反正一个区间里面。我们可以用sum标记,如果扫描的时候遇到不满足的,sum++,这表示不满足的需要匹配掉的,具体可看代码分析

#include<stdio.h>
#include<iostream>
#include<algorithm>
using namespace std;
#define ll long long
ll a[];
bool cmp(ll a,ll b)
{
return b<a;
}
int main( )
{
int n,k,l;
scanf("%d%d%d",&n,&k,&l);
for(ll i= ; i<n*k ; i++)
cin>>a[i];
sort(a,a+n*k,cmp);
ll minx=a[n*k-];///找到最小的 ll sum=,ans=,nu=;///sum是后面需要多少区间包括,ans是确定了多少区间
for(ll i= ; i<n*k ; i++)
{
if(a[i]-minx<=l&&sum>=k-)
{
ans++;
nu+=a[i];
sum-=k-;
}
else
sum++;
}
if(ans==n)
cout<<nu;
else
puts("");
return ;
}

codeforces 985C Liebig's Barrels(贪心)的更多相关文章

  1. codeforces 985C Liebig's Barrels

    题意: 有n * k块木板,每个木桶由k木板组成,每个木桶的容量定义为它最短的那块木板的长度. 任意两个木桶的容量v1,v2,满足|v1-v2| <= d. 问n个木桶容量的最大的和为多少,或者 ...

  2. codeforce 985C Liebig's Barrels(贪心+思维)

    Liebig's Barrels time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...

  3. CF985C Liebig's Barrels 贪心 第二十

    Liebig's Barrels time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...

  4. Codeforce Div-2 985 C. Liebig's Barrels

    http://codeforces.com/contest/985/problem/C C. Liebig's Barrels time limit per test 2 seconds memory ...

  5. codeforces Gym 100338E Numbers (贪心,实现)

    题目:http://codeforces.com/gym/100338/attachments 贪心,每次枚举10的i次幂,除k后取余数r在用k-r补在10的幂上作为候选答案. #include< ...

  6. [Codeforces 1214A]Optimal Currency Exchange(贪心)

    [Codeforces 1214A]Optimal Currency Exchange(贪心) 题面 题面较长,略 分析 这个A题稍微有点思维难度,比赛的时候被孙了一下 贪心的思路是,我们换面值越小的 ...

  7. Liebig's Barrels CodeForces - 985C (贪心)

    链接 大意:给定$nk$块木板, 要制作$n$个$k$块板的桶, 要求任意两桶容积差不超过$l$, 每个桶的容积为最短木板长, 输出$n$个桶的最大容积和 假设最短板长$m$, 显然最后桶的体积都在$ ...

  8. codeforces 349B Color the Fence 贪心,思维

    1.codeforces 349B    Color the Fence 2.链接:http://codeforces.com/problemset/problem/349/B 3.总结: 刷栅栏.1 ...

  9. Codeforces Gym 100269E Energy Tycoon 贪心

    题目链接:http://codeforces.com/gym/100269/attachments 题意: 有长度为n个格子,你有两种操作,1是放一个长度为1的东西上去,2是放一个长度为2的东西上去 ...

随机推荐

  1. PHP如何将XML转成数组

    如果你使用 curl 获取的 xml data $xml = simplexml_load_string($data); $data['tk'] = json_decode(json_encode($ ...

  2. (转载)Eclipse报错:java.lang.ClassNotFoundException: ContextLoaderListener

    转载自:http://www.cnblogs.com/love540376/p/5527757.html Eclipse中tomcat部署工程启动后报错: 严重: Error configuring  ...

  3. easyui layout 折叠之后显示标题

    方法一:重载扩展panel收缩事件 (function($){ var buttonDir = {north:'down',south:'up',east:'left',west:'right'}; ...

  4. ZBar在Windows上的使用 -- ImageMagick and OpenCV

    博客转载自:https://blog.csdn.net/sunflower_boy/article/details/49095265 1. 下载ZBar v0.10 http://zbar.sourc ...

  5. php学习笔记-逻辑运算符

    $a and $b 只有当$a和$b都是true才返回true,否则false. $a or $b 只要$a或者$b至少有一个是true则返回true.意思是或者$a是true,或者是$b是true, ...

  6. 算法Sedgewick第四版-第1章基础-2.1Elementary Sortss-003比较算法及算法的可视化

    一.介绍 1. 2. 二.代码 1. package algorithms.elementary21; /*********************************************** ...

  7. Django框架 之 URLconf

    Django框架 之 URLconf 浏览目录 URL 摘要 Django如何处理一个请求 反向解析URL name模式 namespace模式 一.URL 1.摘要 我们要在Django项目中为应用 ...

  8. 关于LIst Set Map 异常的知识点---我的笔记

    今天新的内容1.List接口2.Set接口3.Map集合4.异常==================================================================== ...

  9. Bulma 源码结构

    源码基于 Bulma 0.4.0 版本. 一.入口文件 bulma.sass bulma.sass 是 Bulma 使用 SASS 编译的入口文件. sass bulma.sass css/bulma ...

  10. [转载]Redhat Enterprise 6.1 如何使用免费的CentOS的yum源

    Redhat Enterprise 6.1 如何使用免费的CentOS的yum源 graybull posted @ 2013年2月18日 22:29 in Unix/Linux with tags  ...