题意:给你n个长度为ai的木板,求最大能拼成的矩形为多大

题解:显然贪心每次选最大的进去拼,那么剧需要枚举矩形长度x,看最长的k个能够拼出长度为x的矩形即可

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cmath>
using namespace std;
int T,n;
int a[];
int main()
{
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
for(int i=;i<=n;i++)scanf("%d",&a[i]);
sort(a+,a++n);
int ans=;
for(int i=n;i>;i--)
{
if(ans+<=a[i])ans++;
else {printf("%d\n",ans);break;}
if(i==)printf("%d\n",ans);
}
}
return ;
}

【CF1243A】Maximum Square【贪心】的更多相关文章

  1. UVALive 4867 Maximum Square 贪心

    E - Maximum Square Time Limit:4500MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit ...

  2. Codeforces Round #599 (Div. 2) A. Maximum Square 水题

    A. Maximum Square Ujan decided to make a new wooden roof for the house. He has

  3. Codeforces Round #599 (Div. 2) A. Maximum Square

    Ujan decided to make a new wooden roof for the house. He has nn rectangular planks numbered from 11  ...

  4. CodeForces 276D – Little Girl and Maximum XOR 贪心

    整整10个月后第二次搞这个问题才搞懂........第一次还是太随意了. 解题思路: 经过打表可得规律答案要么是0 要么是2的N次 - 1 要得到最大的XOR值,其值一定是2的N次 - 1 即在 l ...

  5. hdu 6047 Maximum Sequence 贪心

    Description Steph is extremely obsessed with “sequence problems” that are usually seen on magazines: ...

  6. HDU 6047 Maximum Sequence (贪心+单调队列)

    题意:给定一个序列,让你构造出一个序列,满足条件,且最大.条件是 选取一个ai <= max{a[b[j], j]-j} 析:贪心,贪心策略就是先尽量产生大的,所以就是对于B序列尽量从头开始,由 ...

  7. HDU 6047 Maximum Sequence(贪心+线段树)

    题目网址:http://acm.hdu.edu.cn/showproblem.php?pid=6047 题目: Maximum Sequence Time Limit: 4000/2000 MS (J ...

  8. [CF353C]Find Maximum(贪心)

    题目链接:http://codeforces.com/contest/353/problem/C 题意:给你一串数字a[]和一个二进制串,要求找一个不超过m的二进制数,使得与对应a[]上的数字的乘积和 ...

  9. CodeForces 702 A Maximum Increase (贪心,高效算法)

    题意:给定 n 个数,问你连续的最长的序列是几个. 析:从头扫一遍即可. 代码如下: #include <cstdio> #include <string> #include ...

随机推荐

  1. 阶段1 语言基础+高级_1-3-Java语言高级_05-异常与多线程_第4节 等待唤醒机制_1_线程状态概述

    Thread中有个嵌套类 它描述了线程的状态 线程状态的图 Object类中的Wait方法和notify方法

  2. oracle 11g 数据库恢复技术 ---03 补充日志

    三 补充日志(supplemental logging) 补充日志是对重做记录中变更矢量的补充信息,增加了变更矢量记载的记录量.Oracle某些功能要求启用补充日志才能正常或更好的工作,比如logmi ...

  3. 基于Quartz.net 的任务调度平台Weiz.TaskManager

    Weiz.TaskManager https://github.com/weizhong1988/Weiz.TaskManager 任务管理平台 系统简介 Quartz.net是一个开源的任务调度工具 ...

  4. VMware虚拟机上运行Manjaro系统

    Manjaro系统是从ArchLinux系统发展而来.它的软件安装工具不是ubuntu的apt-get,不是yum,而是pacman. 在虚拟机安装好Manjaro后, 安装虚拟机工具VM-Tools ...

  5. [Python3] 006 列表的常用方法

    目录 一个篱笆三个桩,list 有--好多个桩 1. 列表的小伙伴们 (1) 召唤小伙伴 (2) 我给"他们"分了个组 2. 小伙伴们的"才艺展示" (1) & ...

  6. webpack打包html里的img图片

    对待css里的图片, 因为已经通过引入css文件到js,打包了,可以正常通过module.rules.test检测到,然后正常打包. 但是对于html里的图片, 这个需要安装一个插件html-with ...

  7. 从头到尾说一次 Java 垃圾回收,写得非常好!

    Java技术栈 www.javastack.cn 优秀的Java技术公众号 作者:聂晓龙(花名:率鸽),阿里巴巴高级开发工程 ⬆️ 图片来源于网络 之前上学的时候有这个一个梗,说在食堂里吃饭,吃完把餐 ...

  8. 3486 ( Interviewe )RMQ

    Problem Description YaoYao has a company and he wants to employ m people recently. Since his company ...

  9. django信号相关

    Django中提供了“信号调度”,用于在框架执行操作时解耦.通俗来讲,就是一些动作发生的时候,信号允许特定的发送者去提醒一些接受者. 1.Django内置信号 Model signals pre_in ...

  10. nginx负载均衡的搭建和简单例子

    一,nginx 下载地址:http://nginx.org/en/download.html 二,下载对应版本 三,打开下载的安装包:如下图 四,运行nginx.exe 1,这个是时候,程序运行都是一 ...