CH 2401 - 送礼 - [折半DFS+二分]】的更多相关文章

题目链接:传送门 描述 作为惩罚,GY被遣送去帮助某神牛给女生送礼物(GY:貌似是个好差事)但是在GY看到礼物之后,他就不这么认为了.某神牛有N个礼物,且异常沉重,但是GY的力气也异常的大(-_-b),他一次可以搬动重量和在w(w<=2^31-1)以下的任意多个物品.GY希望一次搬掉尽量重的一些物品,请你告诉他在他的力气范围内一次性能搬动的最大重量是多少. 输入格式 第一行两个整数,分别代表W和N.以后N行,每行一个正整数表示G[i],G[i]<= 2^31-1. 输出格式 仅一个整数,表示G…
1514: Packs Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 61  Solved: 4[Submit][Status][Web Board] Description Give you n packs, each of it has a value v and a weight w. Now you should find some packs, and the total of these value is max, total of…
Description In the ``Four Color Map Theorem" was proven with the assistance of a computer. This theorem states that every map can be colored using only four colors, in such a way that no region is colored using the same color as a neighbor region. He…
原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://wintys.blog.51cto.com/425414/94051 Java二分查找实现,欢迎大家提出交流意见. /** *名称:BinarySearch *功能:实现了折半查找(二分查找)的递归和非递归算法. *说明: * 1.要求所查找的数组已有序,并且其中元素已实现Comparable<T>接口,如Integer.String等. * 2.非递归查找使用search()…
655. 输出二叉树 在一个 m*n 的二维字符串数组中输出二叉树,并遵守以下规则: 行数 m 应当等于给定二叉树的高度. 列数 n 应当总是奇数. 根节点的值(以字符串格式给出)应当放在可放置的第一行正中间.根节点所在的行与列会将剩余空间划分为两部分(左下部分和右下部分).你应该将左子树输出在左下部分,右子树输出在右下部分.左下和右下部分应当有相同的大小.即使一个子树为空而另一个非空,你不需要为空的子树输出任何东西,但仍需要为另一个子树留出足够的空间.然而,如果两个子树都为空则不需要为它们留出…
树洞 CH Round #72 - NOIP夏季划水赛 描述 在一片栖息地上有N棵树,每棵树下住着一只兔子,有M条路径连接这些树.更特殊地是,只有一棵树有3条或更多的路径与它相连,其它的树只有1条或2条路径与其相连.换句话讲,这些树和树之间的路径构成一张N个点.M条边的无向连通图,而度数大于2的点至多有1个.近年以来,栖息地频繁收到人类的侵扰.兔子们联合起来召开了一场会议,决定在其中K棵树上建造树洞.当危险来临时,每只兔子均会同时前往距离它最近的树洞躲避,路程中花费的时间在数值上等于距离.为了在…
题目描述: 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 how to sol…
题目链接:https://vjudge.net/problem/POJ-3977 题意:给一个大小<=35的集合,找一个非空子集合,使得子集合元素和的绝对值最小,如果有多个这样的集合,找元素个数最少的. 思路:显然,可以用折半搜索,分别枚举一半,最大是2的18次方,复杂度能够满足.因为集合非空,枚举时考虑只在前一半选和只在后一半选的情况.对于前一半后一半都选的情况,把前一半的结果存下来,排序,枚举后一半的时候在前一半里二分查找最合适的即可. 思路不难,实现有很多细节,最开始用dfs写得一直wa,…
时间限制:1000MS  内存限制:65535K提交次数:0 通过次数:0 题型: 编程题   语言: G++;GCC Description Global warming is a big problem, isn't it? It is reported that the ice of Antarctica is melting. It results that oceans are glowing and more and more places are flooded. Now the…
get了很多新技能 当时想到了用dfs,但是排序用的是限制时间排序,一直没搞出来. 正解: 二分用时,dfs判断,为了顺利进行做题,需要按照做题开始时间排序 还可以用dp 题意: 作为史上最强的刷子之一,zhx常常参与各种比赛. 有一天,zhx去虐一场比赛.他觉得题太简单了. 这场比赛有n道题.他一眼就已经计算出他做第i道题要花ti的时间,做完后可以得到vi分. 因为他太强了,所以他被管理员盯上了.如果他在第li个单位时间前做完了第i道题,那么管理员就会认为他在作弊,然后把他的号封了. zhx不…
http://acdream.info/problem?pid=1726 官方题解:http://acdream.info/topic?tid=4246 求n个数里面能不能选一些数出来让它们的和等于k. 因为k很大,不能用背包,但是n很小,最大为40,所以拆成了2部分,之后最大为2^20次方<1050000;每次枚举前一半的和,然后用数组存储,然后得到一个总和减去后一半的差用二分查找. #include<cstdio> #include<cstring> #include&l…
Shik and Travel Time Limit: 50 Sec  Memory Limit: 512 MB Description 给定一棵n个点的树,保证一个点出度为2/0. 遍历一遍,要求每条边被经过两次,第一次从根出发,最后一次到根结束,在叶子节点之间移动. 移动一次的费用为路径上的边权之和,第一次和最后一次免费,移动的最大费用 最小可以是多少. Input 第一行一个n,表示点数. 之后两个数x, y,若在第 i 行,表示 i+1 -> x 有一条权值为 y 的边. Output…
SubsetTime Limit: 30000MS        Memory Limit: 65536KTotal Submissions: 6754        Accepted: 1277 DescriptionGiven a list of N integers with absolute values no larger than 1015, find a non empty subset of these numbers which minimizes the absolute v…
A. Tavas and Nafas time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Today Tavas got his test result as an integer score and he wants to share it with his girlfriend, Nafas. His phone operati…
Sumsets Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11946   Accepted: 3299 Description Given S, a set of integers, find the largest d such that a + b + c = d where a, b, c, and d are distinct elements of S. Input Several S, each cons…
折半搜索,map会T所以用hash表来存状态 #include<iostream> #include<cstdio> #include<map> using namespace std; const int N=10,mod=739391; int n,m,k[N],p[N],w,a[155][N],h[1000005],cnt; long long ans; map<int,int>mp; struct qwe { int ne,to,va; }e[400…
传送门 官方题解:http://acdream.info/topic?tid=4246 参考:https://www.cnblogs.com/nowandforever/p/4492428.html 题意:在给定的n个数中,能否找到几个数使得这几个和等于H: 思路:注意这道题的条件 0<n<=40, 0<=H<10^9, 0<=a[i]<10^9,其中 H 和 A [i] 给的比较大,dp的空间开不下,而n比较小,只有40,所以可以把所给的数分成20.20两部分,用df…
Classy Numbers time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output Let's call some positive integer classy if its decimal representation contains no more than 33 non-zero digits. For example,…
描述 Farmer John is well known for his great cows. Recently, the cows have decided to participate in the Incredible Cows Puzzle Contest (ICPC). Farmer John wants to divide the cows into two teams, and he wants to minimize the difference of Puzzle Solvi…
题目描述 Given a list of N integers with absolute values no larger than 10 15, find a non empty subset of these numbers which minimizes the absolute value of the sum of its elements. In case there are multiple subsets, choose the one with fewer elements.…
题目链接:http://poj.org/problem?id=3977 给你n个数,找到一个子集,使得这个子集的和的绝对值是最小的,如果有多种情况,输出子集个数最少的: n<=35,|a[i]|<=10e15 子集个数共有2^n个,所以不能全部枚举,但是可以分为两部分枚举: 枚举一半的所有情况,然后后一半二分即可: #include<iostream> #include<algorithm> #include<string.h> #include<st…
/*折半插入查找思想:每趟将一个带排序的元素作为关键字插入到已经排好的部分序列的适当位置上,查找适当位置的方法用折半查找法 * 适合记录数较多的场景 * 在查找插入位置时节省了时间 * 在记录移动次数方面和直接插入查找是一样的,所以时间复杂度还是O(n^2) * 空间复杂度同为O(1)*/ import java.util.Scanner; public class zhebancharusort { public static void main(String args[]){ Scanner…
D time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Roman planted a tree consisting of n vertices. Each vertex contains a lowercase English letter. Vertex 1 is the root of the tree, each of…
#include<iostream> #include<algorithm> #include<cstring> #include<map> #include<set> #define MAX_N 35 #define MAX_T 500005 using namespace std; typedef long long ll; map<ll,int> ma[2]; ll n,m,a[MAX_N],tot[2]={0,0}; ll d…
题目传送门 性质是:把节点dfs序以后,异象石按这个序号排序,然后相邻两两求树上距离,这些距离的和除以二就是最小斯坦纳树. 插入删除的具体操作是根据我们上述性质,用一个set维护dfn,比如插入x,则ans加上:(set里的,即之前已经插进来的)左x + x右 - 左右. ; typedef set<ll> S; typedef S::iterator Sit; int n, m, t, tot, Time; ], nxt[maxn << ]; int dfn[maxn], mp[…
思路: //By SiriusRen #include <cstdio> #include <cstring> #include <algorithm> using namespace std; typedef long long ll; ; ][],C[][],f[],val[],X,g[]; ],allnum[],Ans,T; +(<<)],s2[+(<<)]; bool operator<(Node a,Node b){return…
题目内容 Vjudge链接 给你\(n\)个数,求出这\(n\)个数的一个非空子集,使子集中的数加和的绝对值最小,在此基础上子集中元素的个数应最小. 输入格式 输入含多组数据,每组数据有两行,第一行是元素组合\(n\)(若\(n\)为0表示输入结束),第二行有\(n\)个数,表示要给出的\(n\)个数. 数据范围 \(n\le 35\) 输出格式 每组数据输出一行两个数中间用空格隔开,表示最小的绝对值和该子集的元素个数. 样例输入 1 10 3 20 100 -100 0 样例输出 10 1 0…
4 Values whose Sum is 0 Time Limit: 15000MS   Memory Limit: 228000K Total Submissions: 25675   Accepted: 7722 Case Time Limit: 5000MS Description The SUM problem can be formulated as follows: given four lists A, B, C, D of integer values, compute how…
[题目链接] http://poj.org/problem?id=3977 [题目大意] 在n个数(n<36)中选取一些数,使得其和的绝对值最小. [题解] 因为枚举所有数选或者不选,复杂度太高无法承受, 我们考虑减小枚举的范围,我们将前一半进行枚举,保存其子集和, 然后后一半枚举子集和取反在前一半中寻找最接近的,两部分相加用以更新答案. [代码] #include <cstdio> #include <utility> #include <algorithm>…
题目传送门 运输计划 Description 公元 2044 年,人类进入了宇宙纪元.L 国有 n 个星球,还有 n?1 条双向航道,每条航道建立在两个星球之间, 这 n?1 条航道连通了 L 国的所有星球.小 P 掌管一家物流公司, 该公司有很多个运输计划,每个运输计划形如 :有一艘物流飞船需要从 ui 号星球沿最快的宇航路径飞行到 vi 号星球去.显然,飞船驶过一条航道是需要时间 的,对于航道 j,任意飞船驶过它所花费的时间为 tj,并且任意两艘飞船之间不会产生任何干扰.为了鼓励科技 创新,…