题意:从数组中选几个(任意),使他们的和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. HTML中CSS引用——选择器的使用

    一.元素选择器     1.书写格式:标记名{/*生命块*/}     2.所有与该标记匹配的元素,都将应用声明块中的规则 二.类选择器     1.书写格式:.类名{/*声明块*/}         ...

  2. redis--->字符串和哈希对比

    redis 的字符串和哈希对比 相同点和不同点 相同点: 首先是他们有很多效果类似的命令,比如set和hset,mset和hmset等等 大多数情况下使用字符串存储的场景使用hash也可以实现. 不同 ...

  3. 【置顶】入驻百家号【九哥聊IT】和【九哥九嫂小日子】,欢迎关注

    欢迎大家关注. 1.关注百家号[九哥聊IT],每天专注讲解互联网最新资讯和知识分享.2.关注百家号[九哥九嫂小日子],带你看下班之外的九哥.

  4. 每日一技|巧用 Telnet 调试 Dubbo 服务

    个人博客地址 studyidea.cn,点击查看更多原创文章 0x00. 前言 想象这样一个场景,线上某个服务突发异常,导致上游服务调用异常,数据处于中间状态.服务恢复之后,我们需要修复这笔数据至正常 ...

  5. Maven: 互联网开发常用的jar以及版本pom.xl文件

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/20 ...

  6. TensorFlow 编程基础

    1.TensorFlow 安装:https://www.cnblogs.com/pam-sh/p/12239387.html https://www.cnblogs.com/pam-sh/p/1224 ...

  7. 请注意安全!你的mongodb已经被黑了!互联网安全生产大过天!

    你所不知道的入侵,你的服务器安全吗?你的数据库安全吗? 讲真,也许是我以前一直从事内网应用开发吧,我从来没有想过在互联网上,有那么多扫描器. 10月份的时候,受人委托我做了一个简单的抢单插件,里面有用 ...

  8. gRPC in ASP.NET Core 3.x -- Protocol Buffer(2)Go语言的例子(上)

    上一篇文章(大约半年前写的):https://www.cnblogs.com/cgzl/p/11246324.html 建立Go项目 在GOPATH的src下面建立一个文件夹 protobuf-go, ...

  9. Ceph 存储集群2-配置:心跳选项、OSD选项、存储池、归置组和 CRUSH 选项

    一.心跳选项 完成基本配置后就可以部署.运行 Ceph 了.执行 ceph health 或 ceph -s 命令时,监视器会报告 Ceph 存储集群的当前状态.监视器通过让各 OSD 自己报告.并接 ...

  10. tmobst2

    (单选题)与下面代码效果相同的HQL 语句是( ). Criteria criteria = session.createCriteria(User.class); criteria.add(Rest ...