题目链接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. LR 两种html与url录制

    一直在使用LR,对于Html_based script和Url-based script 两种录制方式之间,要如何选择,仍是一知半解.最近测试时遇到同样的业务功能,两种录制方式的脚本,单次执行时间差别 ...

  2. C++多态(静多态和动多态)

    如今的C++已经是个多重泛型编程语言(multiparadigm programming lauguage),一个同时支持过程形式(procedural).面向对象形式(object-oriented ...

  3. 三、checkedListBoxControl

    一.checkedListBoxControl的使用全选 private void InitDate() { CheckedListBoxItem[] itemArr = { new CheckedL ...

  4. How to helloworld on Xcode

    create a mac app,click button to change label text? create project,click left window button on Main. ...

  5. faster rcnn

    模型下载 https://github.com/rbgirshick/py-faster-rcnn/issues/542

  6. Atcoder Beginner Contest 121 D - XOR World(区间异或和)

    题目链接:https://atcoder.jp/contests/abc121/tasks/abc121_d 题目很裸(Atcoder好像都比较裸 就给一个区间求异或和 n到1e12 肯定不能O(n) ...

  7. 洛谷P3389 【模板】高斯消元法

    P3389 [模板]高斯消元法 题目背景 Gauss消元 题目描述 给定一个线性方程组,对其求解 输入输出格式 输入格式: 第一行,一个正整数 n 第二至 n+1行,每行 n+1 个整数,为a1​,a ...

  8. 弹出层-layui

    type 0(信息框,默认)1(页面层)2(iframe层)3(加载层)4(tips层) 弹出层 //winIndex存储弹出层的index,以便关闭弹出层时使用 function openWindo ...

  9. python模块psutil的使用

    介绍 psutil是一个跨平台库(http://code.google.com/p/psutil/),能够轻松实现获取系统运行的进程和系统利用率(包括CPU.内存.磁盘.网络等)信息.它主要应用于系统 ...

  10. MVC 动态菜单

    直接上代码: 一,创建菜单 Action public ActionResult GetMenu() { //获取菜单 List<MenuItem> mainMenu = mm.GetMe ...