E. Maximum Subsequence time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You are given an array a consisting of n integers, and additionally an integer m. You have to choose some sequence of…
题目:http://codeforces.com/contest/888/problem/E 一看就是折半搜索?……然后排序双指针. 两个<m的数加起来如果>=m,一定不会更新答案.因为-m后的值比原来的两个数都小(a+b-m<a+m-m),不如它们去加0: 而如果两个数加起来<m,值比它们都大,可能更新答案. #include<iostream> #include<cstdio> #include<cstring> #include<al…
[CF888E]Maximum Subsequence 题意:给你一个序列{ai},让你从中选出一个子序列,使得序列和%m最大. n<=35,m<=10^9 题解:不小心瞟了一眼tag就一下子知道怎么做了,吓得我赶紧把tag屏蔽了. 我们将原序列拆成两半,每一部分都暴力搜索出所有的子序列之和,用set存起来.然后枚举前一半的所有子序列和,设其为x,则使得总和%m最大的右半部分子序列和一定是所有<m-x的数中最大的那个,在set里找一下前驱就行了. #include <cstdio&…
888E - Maximum Subsequence 思路:折半枚举. 代码: #include<bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define mem(a,b) memset(a,b,sizeof(a)) ; int a[N]; set<int>s; int main() { ios::sync_with_stdio(false); cin.tie(); i…
[Usaco2012 Open]Balanced Cow Subsets 题目描述 给出\(N(1≤N≤20)\)个数\(M(i) (1 <= M(i) <= 100,000,000)\),在其中选若干个数,如果这几个数可以分成两个和相等的集合,那么方案数加\(1\). 求有多少种选数的方案. 输入输出格式 输入格式: * Line 1: The integer $ N$. * Lines 2..1+N: Line i+1 contains \(M(i)\). 输出格式: * Line 1:…
E. Prime Gift E. Prime Gift time limit per test 3.5 seconds memory limit per test 256 megabytes input standard input output standard output Opposite to Grisha's nice behavior, Oleg, though he has an entire year at his disposal, didn't manage to learn…
原题传送门 E. Maximum Subsequence time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You are given an array a consisting of n integers, and additionally an integer m. You have to choose some sequen…
Solitaire 题目连接: http://codeforces.com/gym/100231/ Description 给你一个8*8棋盘,里面有4个棋子,每个棋子可以做一下某个操作之一: 1.走向相邻的空格 2.迈过相邻的棋子 然后给你初始状态和结束状态,问你能否得到呢? Input 第一行给你4个初始状态棋子的坐标 第二行给你4个结束状态棋子的坐标 Output 输出能否从初始状态走到结束状态 Sample Input 4 4 4 5 5 4 6 5 2 4 3 3 3 6 4 6 Sa…
Codeforces Round #297 (Div. 2)E. Anya and Cubes Time Limit: 2 Sec  Memory Limit: 512 MBSubmit: xxx  Solved: 2xx 题目连接 http://codeforces.com/contest/525/problem/E Description Anya loves to fold and stick. Today she decided to do just that. Anya has n c…
题目链接 题意:给你两个数n,m,和一个大小为n的数组. 让你在数组找一些数使得这些数的和模m最大. 解法:考虑 dfs但是,数据范围不允许纯暴力,那考虑一下折半搜索,一个从头开始往中间搜,一个从后往中间搜.在中间相遇的时间二分更新最大值即可. #include<bits/stdc++.h> #define LL long long #define fi first #define se second #define mp make_pair #define pb push_back usin…