【CF1243A】Maximum Square【贪心】


题意:给你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【贪心】的更多相关文章
- UVALive 4867 Maximum Square 贪心
E - Maximum Square Time Limit:4500MS Memory Limit:0KB 64bit IO Format:%lld & %llu Submit ...
- Codeforces Round #599 (Div. 2) A. Maximum Square 水题
A. Maximum Square Ujan decided to make a new wooden roof for the house. He has
- 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 ...
- CodeForces 276D – Little Girl and Maximum XOR 贪心
整整10个月后第二次搞这个问题才搞懂........第一次还是太随意了. 解题思路: 经过打表可得规律答案要么是0 要么是2的N次 - 1 要得到最大的XOR值,其值一定是2的N次 - 1 即在 l ...
- hdu 6047 Maximum Sequence 贪心
Description Steph is extremely obsessed with “sequence problems” that are usually seen on magazines: ...
- HDU 6047 Maximum Sequence (贪心+单调队列)
题意:给定一个序列,让你构造出一个序列,满足条件,且最大.条件是 选取一个ai <= max{a[b[j], j]-j} 析:贪心,贪心策略就是先尽量产生大的,所以就是对于B序列尽量从头开始,由 ...
- HDU 6047 Maximum Sequence(贪心+线段树)
题目网址:http://acm.hdu.edu.cn/showproblem.php?pid=6047 题目: Maximum Sequence Time Limit: 4000/2000 MS (J ...
- [CF353C]Find Maximum(贪心)
题目链接:http://codeforces.com/contest/353/problem/C 题意:给你一串数字a[]和一个二进制串,要求找一个不超过m的二进制数,使得与对应a[]上的数字的乘积和 ...
- CodeForces 702 A Maximum Increase (贪心,高效算法)
题意:给定 n 个数,问你连续的最长的序列是几个. 析:从头扫一遍即可. 代码如下: #include <cstdio> #include <string> #include ...
随机推荐
- 阶段1 语言基础+高级_1-3-Java语言高级_04-集合_06 Set集合_6_LinkedHashSet集合
把www挪到最上面,第一个加入到哈希
- adb之mokey的用法
monkey是安卓稳定性的测试方向 目录 1.使用格式 2.一般命令 3.分析monkey日志 1.使用格式 monkey的固定使用模式如下:[adb shell] monkey [options] ...
- cookie/http/https
今天再学习顺便外加复习下http的相关知识,顺便试试在笔记中导出一个长篇的图片回事怎么样的效果. HTTP相关知识,不是很全仅供参考
- Nginx 日志切割(Logrotate)
Logrotate 配置文件 # ls /etc/logrotate.* /etc/logrotate.conf /etc/logrotate.d: cups dracut fmdcn httpd i ...
- .net refactor 命令行
VS中设置项目的编译后事件命令(此命令会在程序集生成后自动在原位置加密,覆盖原来的程序集): "C:\Program Files (x86)\Eziriz\.NET Reactor\dotN ...
- 解决jQuery的toggle()的自动触发问题
在1.9以后的版本toggle()就存在这个问题,用之前的版本就正常了 解决办法: 1.去 jquery官网下载一个版本升级文件.http://blog.jquery.com/2013/05/08/j ...
- 实验报告一 &第三周课程总结
实验报告 1.打印输出所有的“水仙花数”,所谓“水仙花数”是指一个3位数,其中各位数字立方和等于该数本身.例如,153是一个“水仙花数”. 实验代码: public class wdnmd{ publ ...
- Java程序控制结构
分支结构 循环结构 跳转结构 一.分支结构 概念:程序从两条或多条路径中选择一条去执行,这种结构称为分支结构 1. if结构 特点: ① 条件表达式的形式可以为: boolean的变量 boolean ...
- [AGC035F]Two Histograms
Description 你有一个 \(N\) 行.\(M\) 列的.每个格子都填写着 0 的表格.你进行了下面的操作: 对于每一行 \(i\) ,选定自然数 \(r_i\ (0 ≤ r i ≤ M ) ...
- AtCoder Beginner Contest 133-C - Remainder Minimization 2019
https://atcoder.jp/contests/abc133/tasks/abc133_c 思路:由于L,R区间太大,所以不能暴力枚举.由于求(i*j)%2019的最小值,那么2019的倍数对 ...