Educational Codeforces Round 32 E 二分
题意:从数组中选几个(任意),使他们的和modm的值最大
题解:我一开始是直接暴力写,然后就会t
其实这题可以用二分的方法写,一半数组的值用来遍历,一般数组的值用来查询。
二分查询就能把时间继续缩短
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn=;
const ll inf=1e9;
set<int> st[],temp;
int n,m,a[];
int main(){
//freopen("in.txt","r",stdin);
cin >> n >> m;
for (int i=;i<n;i++) cin >> a[i]; set<int>::iterator it;
for(int i=;i<n/;i++){
temp.clear();
for(it=st[].begin();it!=st[].end();it++){
temp.insert((*it+a[i])%m);
}
for(it=temp.begin();it!=temp.end();it++){
st[].insert(*it);
}
st[].insert(a[i]%m);
}
for(int i=n/;i<n;i++){
temp.clear();
for(it=st[].begin();it!=st[].end();it++){
temp.insert((*it+a[i])%m);
}
for(it=temp.begin();it!=temp.end();it++){
st[].insert(*it);
}
st[].insert(a[i]%m);
}
st[].insert();
st[].insert(); int ans = ;
for (it=st[].begin();it!=st[].end();it++){
//在st[1]中找有无和i配对使值为m-1(或更小)
int x = m - *it - ;
set<int>::iterator itt = st[] . upper_bound(x);
itt--;
ans=max(ans,*itt+*it);
}
cout << ans << endl;
return ;
}
Educational Codeforces Round 32 E 二分的更多相关文章
- Educational Codeforces Round 32
http://codeforces.com/contest/888 A Local Extrema[水] [题意]:计算极值点个数 [分析]:除了第一个最后一个外,遇到极值点ans++,包括极大和极小 ...
- Educational Codeforces Round 32 Maximum Subsequence CodeForces - 888E (meet-in-the-middle,二分,枚举)
You are given an array a consisting of n integers, and additionally an integer m. You have to choose ...
- Educational Codeforces Round 61 D 二分 + 线段树
https://codeforces.com/contest/1132/problem/D 二分 + 线段树(弃用结构体型线段树) 题意 有n台电脑,只有一个充电器,每台电脑一开始有a[i]电量,每秒 ...
- Educational Codeforces Round 15 C 二分
C. Cellular Network time limit per test 3 seconds memory limit per test 256 megabytes input standard ...
- Educational Codeforces Round 32 E. Maximum Subsequence
题目链接 题意:给你两个数n,m,和一个大小为n的数组. 让你在数组找一些数使得这些数的和模m最大. 解法:考虑 dfs但是,数据范围不允许纯暴力,那考虑一下折半搜索,一个从头开始往中间搜,一个从后往 ...
- Educational Codeforces Round 32 Problem 888C - K-Dominant Character
1) Link to the problem: http://codeforces.com/contest/888/problem/C 2) Description: You are given a ...
- Educational Codeforces Round 32:E. Maximum Subsequence(Meet-in-the-middle)
题目链接:E. Maximum Subsequence 用了一个Meet-in-the-middle的技巧,还是第一次用到这个技巧,其实这个技巧和二分很像,主要是在dfs中,如果数量减小一半可以节约很 ...
- Educational Codeforces Round 32 Almost Identity Permutations CodeForces - 888D (组合数学)
A permutation p of size n is an array such that every integer from 1 to n occurs exactly once in thi ...
- [Educational Codeforces Round 16]D. Two Arithmetic Progressions
[Educational Codeforces Round 16]D. Two Arithmetic Progressions 试题描述 You are given two arithmetic pr ...
随机推荐
- 异想家Win10系统安装的软件与配置
1.C盘推荐一个硬盘,256G,安装好驱动,显卡配置好高性能,激活Win10,屏蔽WIn10驱动更新(Show or hide updates.diagcab),改电脑名称为Sandeepin-PC. ...
- 《ASP.NET Core 高性能系列》关于.NET Core的配置信息的若干事项
1.配置文件的相关闲话 Core自身对于配置文件不是必须品,但由上文分析可知ASP.NET Core默认采用appsettings.json作为配置文件,关于配置信息的优先等级 命令行>环境变量 ...
- VC简单操作mysql
#include <iostream> #include <winsock.h> #include <mysql.h> #pragma comment(lib, & ...
- 家用联通光纤开启IPv6
前提是地区运营商支持提供IPv6地址,并且是用联通光猫进行拨号上网. 原文在我的开源中国博客 https://my.oschina.net/finchxu/blog/3165614 注意,阅读以下内容 ...
- Http POST 提交 415错误 Unsupported Media Type 解决方案
1 问题 在调用webapi post 提交时出现 415 Unsupported Media Type 错误 前端代码如下: $.post("/api/student/poststuden ...
- Codeforces_456_A
http://codeforces.com/problemset/problem/456/A 按价格排序,比较质量. #include<cstdio> #include<algori ...
- 前端:CSS第四章第一节
块级元素一行只有一个,比如P标签 CSS层叠样式表,意思就是样式是可以叠加的,比如下面的代码 <style> .ok{ color: aqua; } .blue{ color: #5283 ...
- 牛客练习赛25 A 因数个数和(数论分块)
题意: q次询问,每次给一个x,问1到x的因数个数的和. 1<=q<=10 ,1<= x<=10^9 1s 思路: 对1~n中的每个数i,i作为i,2i,3i,...的约数,一 ...
- Zabbix:主动模式
简介 Zabbix 是由 Alexei Vladishev 开发的一种网络监视.管理系统,基于 Server-Client 架构.可用于监视各种网络服务.服务器和网络机器等状态,官方站点:https: ...
- num13---外观模式/过程模式
假设家庭影院有一系列设备,每个设备都有各种开闭等功能性方法,使用家庭影院功能的时候,需要进行各个设备的一系列操作,繁琐麻烦. 现在提供一个外观类,在里面定义操作流程,客户端只需要和外观类进行接口交互即 ...