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 ;
}

最新文章

  1. 3 3Sum closest_Leetcode
  2. android TCP 客户端(仅接收数据)
  3. fancybox 基础 简单demo
  4. Cobar使用文档(可用作MySQL大型集群解决方案)
  5. Linux 简单字符设备驱动程序 (自顶向下)
  6. dbt
  7. apache kafka技术分享系列(目录索引)--转载
  8. wikioi 1044 拦截导弹 (1999年NOIP全国联赛提高组)
  9. nyoj 234 吃土豆
  10. poj 1015 Jury Compromise_dp
  11. 理解free命令
  12. 边框0.5px的实现方法
  13. 多态&amp;nbsp;OC——第十天
  14. byte[] 解析、转码二三事
  15. 为 github markdown 文件生成目录(toc)
  16. ThreadPoolExecutor源码解读
  17. $.getJSON的缓存问题处理
  18. Js 过滤emoji表情...持续补充中..
  19. 10个最好的 jQuery 视频插件
  20. 20145219《网络对抗》Web安全基础实践

热门文章

  1. Xcode自带工具symbolicatecrash解析Crash文件
  2. Python--格式化输出%s和%d
  3. 网络编程 - 1.简单的套接字通信/2.加上通信循环/3.bug修复/4.加上链接循环/5.模拟ssh远程执行命令
  4. What’s wrong with virtual methods called through an interface
  5. QT in VS 多语言实现(中英文切换,每个步骤都有截图,只有UTF8才能让Qt语言家正确读取。先qApp-&gt;removeTranslator,然后installTranslator,每个类都要写上槽函数RetranslateUI)
  6. SSO之CAS基础及应用视频教程(1)
  7. HDU中大数实现的题目,持续更新(JAVA实现)
  8. PKU 2352 Stars(裸一维树状数组)
  9. linux 下安装python3
  10. ACM-ICPC 2018 沈阳赛区网络预赛 G. Spare Tire (容斥原理)