hdu 5265 pog loves szh II
2015-06-09 19:34
267 查看
原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=5265
原先用二分写挂了,估计边界没处理好,换了set好歹过了,罪过,罪过。。
原先用二分写挂了,估计边界没处理好,换了set好歹过了,罪过,罪过。。
[code]#include<algorithm> #include<iostream> #include<cstdlib> #include<cstring> #include<cstdio> #include<set> using std::multiset; using std::max; const int Max_N = 100010; typedef unsigned long long ull; ull n, p, arr[Max_N]; void solve() { ull res = 0; multiset<ull> rec; for (int i = 0; i < n; i++) { scanf("%lld", &arr[i]); rec.insert(arr[i] %= p); } multiset<ull>::iterator ite; for (int i = 0; i < n; i++) { rec.erase(rec.find(arr[i])); ite = rec.lower_bound(p - arr[i]); ull v1 = *--ite; ite = rec.lower_bound(2 * p - arr[i]); ull v2 = *--ite; res = max(res, max((v1 + arr[i]) % p, (v2 + arr[i]) % p)); rec.insert(arr[i]); } printf("%lld\n", res); } int main() { #ifdef LOCAL freopen("in.txt", "r", stdin); freopen("out.txt", "w+", stdout); #endif while (~scanf("%lld %lld", &n, &p)) solve(); return 0; }
相关文章推荐
- sizeHint() minimumSizeHint() sizePolicy() 的使用
- WINRAR4.2破解方式或注册码
- 20150528循环
- 20150601数组
- opencv霍夫变换检测圆cvHoughCircles和直线cvHoughLines2的应用
- 第十四周 程序阅读三
- Qt 自定义 滚动条 样式
- SkinPP for VC
- OpenLayers学习笔记6——使用jQuery UI实现查询并标注(功能实现篇)
- 又是六天没碰Java
- 影响数据检索效率的几个因素
- Qt:QListWidget的item上实现右键菜单(空白的地方)
- C++中的4个类型转换关键字
- 修改ubuntu设备名
- 20150528分支结构
- 关于Linux的总结(三)
- leetcode[141&142]:Linked List Cycle I & II
- 20150528分支结构_练习
- TCP 滑动窗口
- 纪录片《跨国并购》——小感