codeforce 589B枚举
2017-08-25 12:00:53
writer:pprp
很简单的枚举,但是我调试了很长时间,出现各种各样的问题
/*
theme:cf 589B
writer:pprp
declare:枚举
date:2017/8/25
*/ #include <bits/stdc++.h> using namespace std;
const int N = ;
typedef long long ll;
ll ans = -, record_w = -, record_h = -; class rect
{
public:
int w;
int h; bool operator <(const rect & r2)
{
return w < r2.w;
} }; rect rec[N]; int main()
{
int n;
scanf("%d",&n); //input section
for(int i = ; i < n ; i++)
{
scanf("%d%d",&rec[i].w, &rec[i].h);
//w is bigger than h
if(rec[i].w > rec[i].h) //w > h??
swap(rec[i].w,rec[i].h);
}
//sort the w
sort(rec,rec + n); //define a vector to store the height
vector<int> hh; //从小到大枚举w的长度
for(int i = ; i < n ; i++)
{
hh.clear();
//将宽度高于w的对象的h储存在vector中
for(int j = i ; j < n ; j++)
hh.push_back(rec[j].h);//一开始这里写成i了粗心犯的错 //对高度进行排序
sort(hh.begin(), hh.end()); //记录当前高度
int len = hh.size(); //枚举当前w的情况下,采用不同的h的最佳解
for(int j = ; j < hh.size() ; j++, len--)
{
ll cmp = (ll)rec[i].w * hh[j] * len; //wrong before: (ll)(rec[i].w * hh[j] * len) 这样就会越界,这个错误是调试出来的,如果都是ll就会溢出
if(cmp > ans)
{
ans = cmp;
record_h = hh[j];
record_w = rec[i].w;
}
}
}
cout << ans << endl;
cout << record_w << " " << record_h << endl; return ;
}
codeforce 589B枚举的更多相关文章
- codeforce Pashmak and Buses(dfs枚举)
/* 题意:n个同学,k个车, 取旅游d天! 要求所有的学生没有两个或者两个以上的在同一辆车上共同带d天! 输出可行的方案! 对于d行n列的矩阵,第i行第j列表示的是第i天第j个同学所在的车号! 也就 ...
- codeforce No to Palindromes!(枚举)
/* 题意:给定一个字符串中没有任何长度>1的回文子串!求按照字典序的该串的下一个字符串 也不包含长度>1的任何回文子串! 思路:从最低位进行枚举,保证第i位 不与 第 i-1位和第 i- ...
- Codeforce 733B - Parade (枚举)
Very soon there will be a parade of victory over alien invaders in Berland. Unfortunately, all soldi ...
- Two progressions CodeForce 125D 思维题
An arithmetic progression is such a non-empty sequence of numbers where the difference between any t ...
- Swift enum(枚举)使用范例
//: Playground - noun: a place where people can play import UIKit var str = "Hello, playground& ...
- 编写高质量代码:改善Java程序的151个建议(第6章:枚举和注解___建议88~92)
建议88:用枚举实现工厂方法模式更简洁 工厂方法模式(Factory Method Pattern)是" 创建对象的接口,让子类决定实例化哪一个类,并使一个类的实例化延迟到其它子类" ...
- Objective-C枚举的几种定义方式与使用
假设我们需要表示网络连接状态,可以用下列枚举表示: enum CSConnectionState { CSConnectionStateDisconnected, CSConnectionStateC ...
- Help Hanzo (素数筛+区间枚举)
Help Hanzo 题意:求a~b间素数个数(1 ≤ a ≤ b < 231, b - a ≤ 100000). (全题在文末) 题解: a~b枚举必定TLE,普通打表MLE,真是头疼 ...
- 枚举:enum
枚举 所谓枚举就是指定好取值范围,所有内容只能从指定范围取得. 例如,想定义一个color类,他只能有RED,GREEN,BLUE三种植. 使用简单类完成颜色固定取值问题. 1,就是说,一个类只能完成 ...
随机推荐
- 出现unmapped spring configuration files found
intell idea启动出现unmapped spring configuration files found提示. 把spring里面的内容都打勾.
- 剑指Offer——矩阵中的路径
题目描述: 请设计一个函数,用来判断在一个矩阵中是否存在一条包含某字符串所有字符的路径.路径可以从矩阵中的任意一个格子开始,每一步可以在矩阵中向左,向右,向上,向下移动一个格子.如果一条路径经过了矩阵 ...
- 浅谈virtualenv(虚拟环境)
简介 virtualenv为应用提供了隔离的Python运行环境,解决了不同应用间多版本的冲突问题. 例如: 如果我们要同时开发多个应用程序,那这些应用程序都会共用一个Python,就是安装在系统的P ...
- C#线程池ThreadPool
线程池可以看做容纳线程的容器: 一个应用程序最多只能有一个线程池: 设置线程数量ThreadPool.SetMaxThreads(initDownCardThreadPool, maxDownCard ...
- awk的常用操作场景以及工作中涉及到的一些场景实例
废话不多说,直接上这个实例: 一. 统计apache日志单ip访问请求数排名: 假设apache日志内容access.log内容为: /Dec/::: +] - /Dec/::: +] - /Dec ...
- PAT 1077 Kuchiguse [一般]
1077 Kuchiguse (20 分) The Japanese language is notorious for its sentence ending particles. Personal ...
- PAT 1036 Boys vs Girls[简单]
1036 Boys vs Girls (25 分) This time you are asked to tell the difference between the lowest grade of ...
- 5.MySQL必知必会之过滤数据-WHERE
本章将讲授如何使用SELECT语句的WHERE子句指定搜索条件. 1.使用WHERE子句 数据库表一般包含大量的数据,很少需要检索表中所有行.通常只 会根据特定操作或报告的需要提取表数据的子集.只检索 ...
- 101. Symmetric Tree(判断二叉树是否对称)
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For ...
- matlab和mathematics最新的FTP地址
https://dio.obspm.fr/interne/logiciels/matlab/ 分享一个地址,非常好的FTP网站.