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 ...
随机推荐
- 通过HttpClient来调用Web Api接口
回到目录 HttpClient是一个被封装好的类,主要用于Http的通讯,它在.net,java,oc中都有被实现,当然,我只会.net,所以,只讲.net中的HttpClient去调用Web Api ...
- simpletest:一个简单的PHP试工具
1. 下载: http://simpletest.org/ .2. 下载后,只要测试文件中包含如下两个文件,就可以用了 : <?php require_once('simpletest/auto ...
- selenium python (二) 元素定位方法
定位的原则就是:id name class 优先,强烈建议和前端哥哥搞好关系.定位就不是问题:实在不行就xpath和css大部分偶可以定位到. webdriver定位的方法是通过一个By类,By类中有 ...
- LR之Java虚拟用户
1.认识Java虚拟用户 2.Java虚拟用户的适用范围
- jquery图片裁切+PHP文件上传
下载地址:download.csdn.net/source/2745353
- DOM笔记(十):JavaScript正则表达式
一.RegExp ECMAScript通过RegExp类型类支持正则表达式,语法和Perl类似: var exp = /pattern/flags; patternb部分是任何简单的或复杂的正则表达式 ...
- Linux-head,tail用法
linux ---tail命令 linux中tail命令---用于查看文件内容 最基本的是cat.more和less. 1. 如果你只想看文件的前5行,可以使用head命令,如: head -5 /e ...
- 第二百零三天 how can I 坚持
空虚的有点害怕. 日复一日. 今天做了什么?下班看了个搞笑段子. 上班和刘松聊了一下午,东扯西扯的. 下班玩了两局dota. 想租车去出去玩玩,确实没有什么想去的地方了. 莫巧菲. 哎,未来好可怕啊. ...
- Django中如何使用django-celery完成异步任务1(转)
原文链接: http://www.weiguda.com/blog/73/ 本篇博文主要介绍在开发环境中的celery使用,请勿用于部署服务器. 许多Django应用需要执行异步任务, 以便不耽误ht ...
- MYSQL数据库性能调优之六:备份
增量备份