Flower:

传送门:http://acm.hdu.edu.cn/showproblem.php?pid=6486

题解:

逆向思维+规律

因为每次剪n-1,所以逆向就是控制n-1朵不变,每次增高1朵,直到所有等高,即所有的高度都等于最高的那一朵,记录增高的次数为sum,反过来就是最高的那个减少sum,
如果减少sum后小于1则不成立,大于等于1,则需要减少sum次。
sum=每朵花与最高的差的和。

AC代码:

 #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
ll n;
scanf("%lld",&n);
int i;
ll a[];
for(i=;i<n;i++)
{
scanf("%lld",&a[i]);
}
sort(a,a+n);
ll sum=;
for(i=;i<n;i++)
{
sum+=(a[n-]-a[i]);
}
if(a[n-]-sum<)
printf("-1\n");
else
printf("%lld\n",sum);
}
return ;
}

Flower(规律+逆向思维)的更多相关文章

  1. IEEEXtreme 10.0 - Flower Games

    这是 meelo 原创的 IEEEXtreme极限编程比赛题解 题目来源 第10届IEEE极限编程大赛 https://www.hackerrank.com/contests/ieeextreme-c ...

  2. [Cqoi2015] 编号 【逆向思维,暴力枚举】

    Online Judge:Luogu-P4222 Label:逆向思维,暴力枚举 题目描述 你需要给一批商品编号,其中每个编号都是一个7位16进制数(由0~9, a-f组成).为了防止在人工处理时不小 ...

  3. hdu1452 Happy 2004(规律+因子和+积性函数)

    Happy 2004 题意:s为2004^x的因子和,求s%29.     (题于文末) 知识点: 素因子分解:n = p1 ^ e1 * p2 ^ e2 *..........*pn ^ en 因子 ...

  4. Codeforces Round #384 (Div. 2) B. Chloe and the sequence(规律题)

    传送门 Description Chloe, the same as Vladik, is a competitive programmer. She didn't have any problems ...

  5. ACM/ICPC 之 DP解有规律的最短路问题(POJ3377)

    //POJ3377 //DP解法-解有规律的最短路问题 //Time:1157Ms Memory:12440K #include<iostream> #include<cstring ...

  6. HDU 5795 A Simple Nim 打表求SG函数的规律

    A Simple Nim Problem Description   Two players take turns picking candies from n heaps,the player wh ...

  7. 微服务(Microservices)——Martin Flower【翻译】

    原文是 Martin Flower 于 2014 年 3 月 25 日写的<Microservices>. 本文内容 微服务 微服务风格的特性 组件化(Componentization ) ...

  8. Autumn is a second spring when every leaf is a flower.

    Autumn is a second spring when every leaf is a flower. 秋天即是第二个春天,每片叶子都是花朵.——阿尔贝·加缪

  9. 在sqlserver中做fibonacci(斐波那契)规律运算

    --利用sqlserver来运算斐波那契规律 --利用事物与存储过程 declare @number intdeclare @A intdeclare @B intdeclare @C int set ...

随机推荐

  1. jdbcUrl is required with driverClassName

    https://blog.csdn.net/newbie_907486852/article/details/81391525 springboot2.0配置多数据源: spring.datasour ...

  2. System.AccessViolationException处理

    程序出现 System.AccessViolationException异常会终止进程,try catch是无法捕捉的. 有个处理方法在引发异常的发放上面加上 [System.Runtime.Exce ...

  3. ① Python3.0基础语法

    稍微了解一下py2.0和py3.0的区别,Py3.0在设计的时候,为了不带入过多的累赘,没有考虑向下兼容低版本的Py2.0.而在低版本中Py2.6作为过渡版,基本使用Py2.x的语法和库,同时考虑Py ...

  4. iOS - swift 后使用打包动态库

    WWDC2014上发布的Xcode6 beta版有了不少更新,其中令我惊讶的一个是苹果在iOS上开放了动态库,在Xcode6 Beta版的更新文档中是这样描述的: Frameworks for iOS ...

  5. day34-python之进程调用

    1.信号量 import threading,time class myThread(threading.Thread): def run(self): if semaphore.acquire(): ...

  6. git 命令提交项目到git服务器

    1.先下载git,然后安装git https://git-scm.com/downloads 2.在电脑任意盘创建一个目录 3.在创建的目录下点击右键 4.初始化git 使用git init 初始化, ...

  7. git 出现 fatal: remote origin already exists 错误

    当输入$ git remote add origin git@github.com:djqiang(github帐号名)/gitdemo(项目名).git 出现 如下错误: 解决办法如下: 1.先输入 ...

  8. 代替for-in 遍历对象

    object.keys() object.getOwnPropertyName()

  9. es6 javascript的Class 类的继承

    原文链接:https://blog.csdn.net/qq_30100043/article/details/53542531 1 基本用法 Class 之间可以通过extends关键字实现继承, 这 ...

  10. mac中git flow使用

    初始化 git flow init   最后就一路回车选择默认的就ok了 常用命令以及分支:分支介绍:1.master.只有一个,并且不会在master上进行代码的操作.2.develop.只有一个, ...