domino

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)

Problem Description
Little
White plays a game.There are n pieces of dominoes on the table in a
row. He can choose a domino which hasn't fall down for at most k times,
let it fall to the left or right. When a domino is toppled, it will
knock down the erect domino. On the assumption that all of the tiles are
fallen in the end, he can set the height of all dominoes, but he wants
to minimize the sum of all dominoes height. The height of every domino
is an integer and at least 1.
 
Input
The first line of input is an integer T ( 1≤T≤10)
There are two lines of each test case.
The first line has two integer n and k, respectively domino number and the number of opportunities.( 2≤k,n≤100000)
The second line has n - 1 integers, the distance of adjacent domino d, 1≤d≤100000
 
Output
For each testcase, output of a line, the smallest sum of all dominoes height
 
Sample Input
1
4 2
2 3 4
 
Sample Output
9
 
Source

BestCoder Round #85

思路:每次多推一次将最大的改成高度为1的骨牌;

   坑点:k可能大于n;

#include<bits/stdc++.h>
using namespace std;
#define ll __int64
#define esp 0.00000000001
const int N=1e5+,M=1e6+,inf=1e9+,mod=;
int a[N];
int main()
{
int x,y,z,i,t;
int T;
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&x,&y);
for(i=;i<x;i++)
scanf("%d",&a[i]);
sort(a+,a+x);
ll ans=;
for(i=;i<=(x-y);i++)
ans+=a[i]+;
if(y<=x)
ans+=y;
else
ans+=x;
printf("%I64d\n",ans);
}
return ;
}

hdu 5777 domino 贪心的更多相关文章

  1. HDU 5777 domino

    贪心一下.有k次机会,也就是那些数字中,最大的k-1可以不选择.答案为:sum{a[i]}-sum{最大的k-1个a[i]}+n.注意:k>=n的时候直接输出n. #pragma comment ...

  2. HDU 5777 domino (排序,水题)

    题意:小白在玩一个游戏.桌子上有n张多米诺骨牌排成一列.它有k次机会,每次可以选一个还没有倒的骨牌,向左或者向右推倒.每个骨 牌倒下的时候,若碰到了未倒下的 骨牌,可以把它推倒.小白现在可以随意设置骨 ...

  3. Hdu 4864(Task 贪心)(Java实现)

    Hdu 4864(Task 贪心) 原题链接 题意:给定n台机器和m个任务,任务和机器都有工作时间值和工作等级值,一个机器只能执行一个任务,且执行任务的条件位机器的两个值都大于等于任务的值,每完成一个 ...

  4. D - 淡黄的长裙 HDU - 4221(贪心)

    D - 淡黄的长裙 HDU - 4221(贪心) James is almost mad! Currently, he was assigned a lot of works to do, so ma ...

  5. hdu 2037简单贪心--活动安排问题

    活动安排问题就是要在所给的活动集合中选出最大的相容活动子集合,是可以用贪心算法有效求解的很好例子.该问题要求高效地安排一系列争用某一公共资源的活动.贪心算法提供了一个简单.漂亮的方法使得尽可能多的活动 ...

  6. HDU 4864 Task (贪心+STL多集(二分)+邻接表存储)(杭电多校训练赛第一场1004)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4864 解题报告:有n台机器用来完成m个任务,每个任务有一个难度值和一个需要完成的时间,每台机器有一个可 ...

  7. HDU 4310 Hero (贪心算法)

    A - Hero Time Limit:3000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Sta ...

  8. hdu 4268 multiset+贪心

    Alice和Bob有n个长方形,有长度和宽度,一个矩形可以覆盖另一个矩形的条件的是,本身长度大于等于另一个矩形,且宽度大于等于另一个矩形,矩形不可旋转,问你Alice最多能覆盖Bob的几个矩形? /* ...

  9. hdu 4864 Task (贪心 技巧)

    题目链接 一道很有技巧的贪心题目. 题意:有n个机器,m个任务.每个机器至多能完成一个任务.对于每个机器,有一个最大运行时间xi和等级yi, 对于每个任务,也有一个运行时间xj和等级yj.只有当xi& ...

随机推荐

  1. 通过创建脚本代替"scrapy crawl Test"命令

    文件结构: 1.在命令行scrapy crawl Test正常运行的条件下在项目的根目录创建start.py文件(注意目录,同scrapy.cfg文件一个目录): start.py源代码: # -*- ...

  2. Group By 与 Count

    select UserID,COUNT(0) From [Order] a Group By UserID UserID   (无列名)1             5     2            ...

  3. Spring Data 关于Repository的介绍(四)

    Repository类的定义: public interface Repository<T, ID extends Serializable> { } 1)Repository是一个空接口 ...

  4. Java 集合框架查阅技巧

    如何记录每一个容器的结构和所属体系呢? List ArrayList LinkedList Set HashSet TreeSet 其中,后缀名就是该集合所属的体系,前缀名就是该集合的数据结构. 看到 ...

  5. Hibernate简单配置

    1.配置构建路径,加载用户库,hibernate4.3.8 MySQL-Driver 2.写User.java      纯POJO+持久化注解=PO @Entity @Table(name=&quo ...

  6. static关键字注意事项

    /* static关键字注意事项 A:在静态方法中是没有this关键字的 如何理解呢? 静态是随着类的加载而加载,this是随着对象的创建而存在. 静态比对象先存在. B:静态方法只能访问静态的成员变 ...

  7. nodejs升级的两种方法

    方法一: 用n升级nodejs # 全局安装n$ npm install -g n# 升级到最新稳定版$ n stable # 升级到最新版$ n latest# 升级到定制版$ n v7.10.0# ...

  8. ionic学习笔记—创建项目

    环境搭建: 安装node.js  --> npm或cnpm   -->  安装jdk  -->  安装AndroidSDK  -->  安装cordova  -->  安 ...

  9. JSON 弹窗

    JSON和AJAX <script type="text/javascript"> $(document).ready(function(e) { var a = { ...

  10. 关于 ActionBar、ToolBar、StatusBar 的开发经验整理

    一.ActionBar.ToolBar概述 1.1 ActionBar 1.2 ToolBar 1.3 StatusBar StatusBar 是一个半透明阴影,View 可以伸展到其后面. 1.4 ...