题意:从数组中选几个(任意),使他们的和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 二分的更多相关文章

  1. Educational Codeforces Round 32

    http://codeforces.com/contest/888 A Local Extrema[水] [题意]:计算极值点个数 [分析]:除了第一个最后一个外,遇到极值点ans++,包括极大和极小 ...

  2. 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 ...

  3. Educational Codeforces Round 61 D 二分 + 线段树

    https://codeforces.com/contest/1132/problem/D 二分 + 线段树(弃用结构体型线段树) 题意 有n台电脑,只有一个充电器,每台电脑一开始有a[i]电量,每秒 ...

  4. Educational Codeforces Round 15 C 二分

    C. Cellular Network time limit per test 3 seconds memory limit per test 256 megabytes input standard ...

  5. Educational Codeforces Round 32 E. Maximum Subsequence

    题目链接 题意:给你两个数n,m,和一个大小为n的数组. 让你在数组找一些数使得这些数的和模m最大. 解法:考虑 dfs但是,数据范围不允许纯暴力,那考虑一下折半搜索,一个从头开始往中间搜,一个从后往 ...

  6. 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 ...

  7. Educational Codeforces Round 32:E. Maximum Subsequence(Meet-in-the-middle)

    题目链接:E. Maximum Subsequence 用了一个Meet-in-the-middle的技巧,还是第一次用到这个技巧,其实这个技巧和二分很像,主要是在dfs中,如果数量减小一半可以节约很 ...

  8. 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 ...

  9. [Educational Codeforces Round 16]D. Two Arithmetic Progressions

    [Educational Codeforces Round 16]D. Two Arithmetic Progressions 试题描述 You are given two arithmetic pr ...

随机推荐

  1. laravel aritisan命令大全

    1常用命令 显示某个命令的帮助 php artisan -h make:controller 实例命令 php artisan make:controller -r Api/TestControlle ...

  2. Quartz.Net和队列应用demo

    using System; using System.Collections.Generic; using System.Threading; namespace ConsoleApplication ...

  3. SQLException:The server time zone

    报错信息如下: java.sql.SQLException: The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represen ...

  4. 【转】spring framework 5以前体系结构及内部各模块jar之间的maven依赖关系

    作者:凌承一  出处:http://www.cnblogs.com/ywlaker/  很多人都在用spring开发java项目,但是配置maven依赖的时候并不能明确要配置哪些spring的jar, ...

  5. HTML简介介绍

    网页概述 网页:纯文本格式的文件:(以村文本格式编写,后缀名改为HTML的文本文件) ---- 网站:多个网页的集合: ---- 主页:打开网站后显示的第一个页面: ---- 浏览器:将纯文本格式的文 ...

  6. Dubbox 环境搭建

    第一章:Dubbox简介 Dubbox是一个开源的RPC(Remote ProcedureCall Protocol)远程调用框架,是由dangdang对阿里的Dubbo的升级,可以被视为Dubbo的 ...

  7. C++类中拷贝构造函数详解

    a. C++标准中提到"The default constructor, copy constructor and copy assignment operator, and destruc ...

  8. python 存储数据

    如何进行数据存储,很多程序都要求用户输入某种信息,如让用户存储游戏首选项或提供要可视化的数据. 使用模块json进行数据存储. 1.1.使用json.dump()和json.load() #-*- e ...

  9. Centos7桥接设置网络并使用xrdp+tigervnc实现桌面远程访问

    最近用到了虚拟机,之前虚拟机的网络配置使用的NAT配置好了,但是无论怎样设置都无法使用局域网内的其它主机访问虚拟机的服务.经过了一天的折腾,远程主机仍然连接不上虚拟机服务,后来找到原因,NAT连接模式 ...

  10. 网络最大流(EK)

    以前在oi中见到网络流的题都是直接跳过,由于本蒟蒻的理解能力太弱,导致网络流的学习不断推迟甚至被安排在了tarjan之后,原本计划于学习完最短路后就来学网络流的想法也随之破灭,在看完众多大佬 的博客后 ...