题意:给你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. Delphi XE2 之 FireMonkey 入门(8) - TImage

    TImage 主要成员: { 属性 } Bitmap              : TBitmap;        //图像 BitmapMargins        : TBounds;      ...

  2. HashTable 和 HashMap 区别

    hashMap去掉了HashTable 的contains方法,但是加上了containsValue()和containsKey()方法. hashTable同步的,而HashMap是非同步的,效率上 ...

  3. 测开之路九十七:js的引用方式

    第一种:引用外部js文件 准备一个js文件 <!-- 引用外部的js --><script src="../js/js01.js"></script& ...

  4. 测开之路九十一:css常用的选择器

    一:全局选择器:* 二:标签选择器,如给所有p标签加个背景色 三:id选择器:# ,如给id为id_01的元素加一个框 四:类选择器:. 如设置一个类选择器为blue,当有标签引用blue的时候,背景 ...

  5. ora-01033,ORA-16038

    ORA-01033: ORACLE initialization or shutdown in progress 1.进入CMD,执行set ORACLE_SID=fbms,确保连接到正确的SID:2 ...

  6. 【Python】Visual Studio Code 安装&&使用 hello python~~~~

    1.安装Python 官网下载: https://www.python.org/downloads/   选择版本下载 2.下载完毕后,点击安装. 3.看到页面,直接下一步,全部默认选项. 4.安装即 ...

  7. Java ——数组 选择排序 冒泡排序

    本节重点思维导图 数组 public static void main(String[] args) { int a ; a=3; int[] b; b = new int[3];//强制开辟内存空间 ...

  8. pycharm运行时出现‘no module named 'requests'’

    参考文章:https://www.jianshu.com/p/f7c808365a9e 出现无requests的包的错误--->找包中是否有requests 1.从files下拉框中点击sett ...

  9. charles_01_打断点修改接口请求&返回数据

    前言 测试过程中,为了模拟某场景测试,经常需要修改接口请求或者返回数据.可通过抓包工具打断点,实现模拟测试场景.常用的抓包工具charles和fiddler均可打断点mock数据.由于小编安装了cha ...

  10. review-1

    # ### for 循环和序列的运用 # remember = ['从入门到放弃', '从入门到如土', 123, 'happy']# for each in remember:# print(eac ...