题目链接http://codeforces.com/problemset/problem/589/B

题目大意:告诉你n 个矩形,知道矩形的长度和宽度(长和宽可以互换),每个矩形的长度可以剪掉一部分,宽度也同样,求出可以得到多少个一样(每个矩形的长相等,宽也相等)的矩形,使得面积之和最大,并输出长和宽。

解题思路:将每个矩形的长和宽都存到一个结构体数组内,对矩形的长进行排序,因为最终结果的长一定是某个矩形的长,宽也一定是某个矩形的宽,所以我们枚举长,然后将长大于等于该长度的矩形的宽加入到一个向量中,再对该向量进行排序,再对宽度进行枚举,找到最大值即可。

详见代码:

 #include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<cstring>
using namespace std;
typedef long long ll;
const int maxn=;
struct node{
ll l,w;
bool operator<(const node& a)const
{
return l<a.l; //长从小到大排
}
}st[maxn];
int n; int main()
{
cin>>n;
ll a,b;
for(int i=;i<n;i++)
{
cin>>a>>b;
if(a<b) swap(a,b);
st[i].l=a,st[i].w=b;
}
sort(st,st+n);
ll ans=,l,w;
vector<ll> k;
for(int i=;i<n;i++)
{
k.clear();
for(int j=i;j<n;j++)
k.push_back(st[j].w); //将长度大于等于st[i].l的矩形的宽度加入到向量
sort(k.begin(),k.end()); //宽度从小到大排
for(int j=;j<k.size();j++)
{
ll temp=(ll)(st[i].l*k[j]*(k.size()-j));
if(temp>ans)
{
ans=temp;
l=st[i].l;
w=k[j];
}
}
}
cout<<ans<<endl<<l<<" "<<w<<endl;
return ;
}

CodeForces - 589B(暴力)的更多相关文章

  1. CodeForces 589B Layer Cake (暴力)

    题意:给定 n 个矩形是a*b的,问你把每一块都分成一样的,然后全放一块,高度都是1,体积最大是多少. 析:这个题,当时并没有完全读懂题意,而且也不怎么会做,没想到就是一个暴力,先排序,先从大的开始选 ...

  2. CodeForces - 589B(暴力+排序)

    Dasha decided to bake a big and tasty layer cake. In order to do that she went shopping and bought n ...

  3. CodeForces 670D1 暴力或二分

    今天,开博客,,,激动,第一次啊 嗯,,先来发水题纪念一下 D1. Magic Powder - 1   This problem is given in two versions that diff ...

  4. Codeforces Round #439 (Div. 2) Problem E (Codeforces 869E) - 暴力 - 随机化 - 二维树状数组 - 差分

    Adieu l'ami. Koyomi is helping Oshino, an acquaintance of his, to take care of an open space around ...

  5. Codeforces Round #439 (Div. 2) Problem A (Codeforces 869A) - 暴力

    Rock... Paper! After Karen have found the deterministic winning (losing?) strategy for rock-paper-sc ...

  6. Codeforces Round #425 (Div. 2) Problem B Petya and Exam (Codeforces 832B) - 暴力

    It's hard times now. Today Petya needs to score 100 points on Informatics exam. The tasks seem easy ...

  7. Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) Problem C (Codeforces 831C) - 暴力 - 二分法

    Polycarp watched TV-show where k jury members one by one rated a participant by adding him a certain ...

  8. codeforces 691F 暴力

    传送门:https://codeforces.com/contest/691/problem/F 题意:给你n个数和q次询问,每次询问问你有多少对ai,aj满足ai*aj>=q[i],注意 a* ...

  9. Vicious Keyboard CodeForces - 801A (暴力+模拟)

    题目链接 题意: 给定一个字符串,最多更改一个字符,问最多可以有多少个“VK”子串? 思路: 由于数据量很小,不妨尝试暴力写.首先算出不更改任何字符的情况下有多个VK字串,然后尝试每一次更改一个位置的 ...

随机推荐

  1. 生命周期函数以及vue的全局注册

    beforeCreate 在创造实例之前 created 创造实例以后 beforeMount 在挂载前 render 渲染节点到页面上 //将虚拟dom数组渲染出来 mounted 挂载以后 bef ...

  2. from组件补充

    一.定义的规则 class TeacherForm(Form): #必须继承Form # 创建字段,本质上是正则表达式 username = fields.CharField( required=Tr ...

  3. Oracle 中sql文件的导入导出

    导出 一般导入的时候我用的是命令行 imp c##zs/@orcl fromuser=c##zs touser=c##zs file=D:\java\.dmp ignore=y c##zs 是创建的用 ...

  4. 结巴(jieba)分词

    一.介绍: jieba: “结巴”中文分词:做最好的 Python 中文分词组件 “Jieba” (Chinese for “to stutter”) Chinese text segmentatio ...

  5. python学习笔记(6)--条件分支语句

    if xxxx: coding if xxxx: coding else: coding if xxxx: coding elif xxx: coding …… else: coding 或者一种简洁 ...

  6. Linux中,去掉终端显示的当前目录的绝对路径

    Linux中,去掉终端显示的当前目录的绝对路径 去~/.bashrc中,找到PS1变量的定义,如果没有,手动加上: 可以将显示输出到标题栏上: #export PS1="[e]2;u@H w ...

  7. a标签实现锚点功能

    a标签实现锚点功能 <!DOCTYPE html> <html lang="en"> <head> <meta charset=" ...

  8. Android PowerManager电源管理(Android N )

    ./frameworks/base/core/java/android/os/PowerManager.java该类提供给Application访问电源相关接口. 它的内部类WakeLock是定义的唤 ...

  9. table-layui

    本文章为原创文章,转载请注明出处 html <div class="layui-btn-group tableBtn"> <button class=" ...

  10. shiro注解和标签

    Controller中注解: @RequiresAuthentication @RequiresGuest @RequiresPermissions("account:create" ...