题意:从数组中选几个(任意),使他们的和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. Web自动化测试项目搭建(一) 需求与设计

    一.项目需求 测试/生产环境更新后,自动化回归测试 项目易于维护和运行 支持多种测试策略 支持可视化测试报告 运行结果,支持多种方式通知相关人员 可定时/触发的方式运行自动化测试用例 二.设计 2.1 ...

  2. C语言博客作业9

    本周作业头 这个作业属于那个课程 C语言程序设计II 这个作业要求在哪里 作业链接 我在这个课程的目标是 熟练掌握C语言 这个作业在那个具体方面帮助我实现目标 pta作业的完成 参考文献 文章链接 本 ...

  3. Java8新特性一点通 | 回顾功能接口Functional Interface

    Functional Interface Functional Interface是什么? 功能接口是java 8中的新增功能,它们只允许一个抽象方法.这些接口也称为单抽象方法接口(SAM接口).这些 ...

  4. java代码之美(14)---Java8 函数式接口

    Java8 函数式接口 之前写了有关JDK8的Lambda表达式:java代码之美(1)---Java8 Lambda 函数式接口可以理解就是为Lambda服务的,它们组合在一起可以让你的代码看去更加 ...

  5. 开源虚拟机Bochs安装以及踩坑

    因为想要写一个简单的操作系统,所以需要安装虚拟机来模拟出硬件,VMware不适合这个场景,因为会使用硬件级别的虚拟化,而bochs这个开源虚拟机,是用软件虚拟了所有的硬件,所以调试可以做到非常细的粒度 ...

  6. 基于H5与webGL的 3d 电子围栏展示

    前言 现代工业化的推进在极大加速现代化进程的同时也带来的相应的安全隐患,在传统的可视化监控领域,一般都是基于 Web SCADA 的前端技术来实现 2D 可视化监控,本系统采用 Hightopo 的 ...

  7. 今天更新IDEA后,我依旧要永久激活(支持2019.3.3版本)

    起因 今天一早用IDEA写代码,看到有下角有提示更新,有点强迫症的我,就手欠的又点了下更新,结果尼玛悲剧了,居然许可证过期,IDEA过期了,如下图所示: 就想用下新功能,就这样对我,就给两天的使用时间 ...

  8. tmobst6

    1.(单选题)Oracle数据库中,在SQL语句中连接字符串的方法是:(). A)CAT B)CONCAT C)JOIN D)UNION 2.(单选题)在数据库中,有一个名为seq的序列对象,以下语句 ...

  9. 9. Palindrome Number QuestionEditorial Solution

    Determine whether an integer is a palindrome. Do this without extra space. click to show spoilers. S ...

  10. 代理IP批量验证程序

    #include <afxinet.h> #include <afxwin.h> #include <iostream> #include <fstream& ...