hdu 5265 pog loves szh II STL
pog loves szh II
Time Limit: 20 Sec
Memory Limit: 256 MB
题目连接
http://acm.hdu.edu.cn/showproblem.php?pid=5265
Description
Input
每组数据第一行两个整数n(2≤n≤100000),p(1≤p≤231−1)。
接下来一行n个整数ai(0≤ai≤231−1)。
Output
对于每组的每个询问,输出一行,表示pog与szh的最大恩爱值。
Sample Input
4 4
1 2 3 0
4 4
0 0 2 2
Sample Output
3
2
HINT
题意
题解:
STL大法好!
STL拯救世界!
代码:
//qscqesze
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define test freopen("test.txt","r",stdin)
#define maxn 2000001
#define mod 10007
#define eps 1e-9
int Num;
char CH[];
const int inf=0x3f3f3f3f;
const ll infll = 0x3f3f3f3f3f3f3f3fLL;
inline ll read()
{
ll x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
inline void P(int x)
{
Num=;if(!x){putchar('');puts("");return;}
while(x>)CH[++Num]=x%,x/=;
while(Num)putchar(CH[Num--]+);
puts("");
}
//************************************************************************************** ll a[maxn]; multiset<ll> S;
int main()
{
//test;
int n;
ll p;
while(cin>>n>>p)
{
S.clear();
for(int i=;i<n;i++)
{
a[i]=read();
a[i]%=p;
S.insert(a[i]);
}
ll ans=;
for(int i=;i<n;i++)
{
S.erase(S.find(a[i]));
multiset<ll>::iterator it=S.lower_bound(p-a[i]);
it--;
ans=max(ans,(a[i]+*it)%p);
it=S.lower_bound(p*-a[i]);
it--;
ans=max(ans,(a[i]+*it)%p);
S.insert(a[i]);
}
cout<<ans<<endl;
} }
hdu 5265 pog loves szh II STL的更多相关文章
- hdu 5265 pog loves szh II
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5265 pog loves szh II Description Pog and Szh are pla ...
- HDU 5265 pog loves szh II (二分查找)
[题目链接]click here~~ [题目大意]在给定 的数组里选两个数取模p的情况下和最大 [解题思路]: 思路见官方题解吧~~ 弱弱献上代码: Problem : 5265 ( pog love ...
- HDU 5265 pog loves szh II 二分
题目链接: hdu:http://acm.hdu.edu.cn/showproblem.php?pid=5265 bc(中文):http://bestcoder.hdu.edu.cn/contests ...
- HDU 5265 pog loves szh II (技巧)
题意:给一个数字序列,要求再其中找到两个数,其和再模p的结果是最大的,求此和. 思路:先将输入的元素模p,排序.结果可能有两种情况: (1)a+b大于p:肯定由两个最大的数之和来产生. (2)a+b小 ...
- hdu 5266 pog loves szh III(lca + 线段树)
I - pog loves szh III Time Limit:6000MS Memory Limit:131072KB 64bit IO Format:%I64d & %I ...
- 贪心/二分查找 BestCoder Round #43 1002 pog loves szh II
题目传送门 /* 贪心/二分查找:首先对ai%=p,然后sort,这样的话就有序能使用二分查找.贪心的思想是每次找到一个aj使得和为p-1(如果有的话) 当然有可能两个数和超过p,那么an的值最优,每 ...
- hdu 5264 pog loves szh I
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5264 pog loves szh I Description Pog has lots of stri ...
- hdu 5264 pog loves szh I 水题
pog loves szh I Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?p ...
- HDU 5266 pog loves szh III(区间LCA)
题目链接 pog loves szh III 题意就是 求一个区间所有点的$LCA$. 我们把$1$到$n$的$DFS$序全部求出来……然后设$i$的$DFS$序为$c[i]$,$pc[i]$为$c ...
随机推荐
- LR之录制SQL脚本
1.选择协议 ①MS SQL serve ②ODBC 一般情况下选ODBC 2.录制步骤
- C++C#时间转换
time_t是从1970年1月1日的格林尼治时间开始的,所以以下就是你要的结果System.DateTime time= new System.DateTime(1970, 1, 1).ToLocal ...
- c/c++工程中外部头文件及库添加方法
在VS工程中,添加c/c++工程中外部头文件及库的基本步骤: 1.添加工程的头文件目录:工程---属性---配置属性---c/c++---常规---附加包含目录:加上头文件存放目录. 2.添加文件引用 ...
- 初识---Qt解析XML文件(QDomDocument)
关于XML及其使用场景不在此多做介绍,今天主要介绍Qt中对于XML的解析.QtXml模块提供了一个读写XML文件的流,解析方法包含DOM和SAX,两者的区别是什么呢? DOM(Document Ob ...
- 为网页设计师准备的30个使用的HTML5框架
原文地址:http://www.goodfav.com/zh/html5-framework-8189.html 网页设计师在开始使用一些应用程序之前需要考虑几个事实,以确保在应用Web程序框架时,这 ...
- DOCTYPE的笔记
平时用HTML5 所以都直接简写doctype <!DOCTYPE html> <html> 从来没考虑这个东西全文是什么 <!DOCTYPE html PUBLIC & ...
- 消息队列与RabbitMQ
1 什么是消息队列 消息指进程或应用间通信的数据:队列是保存数据的结构:消息队列是指进程或应用间通信时,保存消息的容器.消息队列独特的机制和结构保证了消息发送者和接收者之间良好的异步通信. 2 为什么 ...
- HDOJ-ACM1009(JAVA) (传说中的贪心算法)分为数组实现 和 封装类实现
转载声明:原文转自:http://www.cnblogs.com/xiezie/p/5564311.html 这个道题有几点要注意的: 数组存放的类型:float或double 打印的格式:(如果只是 ...
- T-SQL游标
游标是面向行的,它会使开发人员变懒,懒得去想用面向集合的查询方式实现某些功能. 在性能上,游标会迟更多的内存,减少可用的并发,占用带宽,锁定资源,当然还有更多的代码量. 用一个比喻来说明为什么游标会占 ...
- 实体框架 (EF) 入门 => 二、在全新的数据库中使用 Code First
学习资料:http://msdn.microsoft.com/zh-cn/data/jj193542 视频建立的控制台应用程序,我在这里使用MVC. 一.非常有磁性的,非常优雅 很喜欢看这个人的视频, ...