Smallest Difference Description Given a number of distinct decimal digits, you can form one integer by choosing a non-empty subset of these digits and writing them in some order. The remaining digits can be written down in some order to form a second…
 Smallest Difference(最小差) Time Limit: 1000MS    Memory Limit: 65536K Description - 题目描述 Given a number of distinct decimal digits, you can form one integer by choosing a non-empty subset of these digits and writing them in some order. The remaining d…
Smallest Difference Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6493   Accepted: 1771 Description Given a number of distinct decimal digits, you can form one integer by choosing a non-empty subset of these digits and writing them in…
Smallest Difference Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 19528   Accepted: 5329 Description Given a number of distinct decimal digits, you can form one integer by choosing a non-empty subset of these digits and writing them in…
题目:http://poj.org/problem?id=2718 题意: 就是输入N组数据,一组数据为,类似 [1  4  5  6  8  9]这样在0~9之间升序输入的数据,然后从这些数据中切一刀,比如  n1:[1 4 5],n2:[6 8 9]这样,然后 abs(n1- n2),对n1 和 n2的所有可能的排列 n1: [1 4 5][1 5 4]...这样,要算出来的最小的差,显然从中间切一刀才会出现这种解. 题解: 这里可以用来练习 STL,算法不会也没有关系,可以在这题学到 bi…
http://poj.org/problem?id=2718 题目大意: 给你一些数字(单个),不会重复出现且从小到大.他们可以组成两个各个位上的数字均不一样的数,如 0, 1, 2, 4, 6 ,7可以组成10 和 2467,但最小的差值由204和176组成,差值为28,这题就是求最小的差值. 思路: 直接枚举即可. 注意不能有前导0,当只有两个数时...比如0 和2答案为2,分开讨论就是了. #include<cstdio> #include<cstdlib> #include…
题意: 就是说给你一些数,然后要求你使用这些数字组成2个数,然后求他们的差值最小. 思路: 我用的双重DFS做的,速度还比较快,其中有一个很重要的剪枝,若当前搜索的第二个数后面全部补零与第一个数所产生的差值比当前所搜索到的结果还要大,那么就直接返回.这个剪枝就是超时与几十MS的差距 注意一点就是可能有0 与一个数字存在的情况,比如0 3,0 5等等. #include<cstdio> #include<cstring> #include<cstdlib> #includ…
Description Given a number of distinct , the integer may not start with the digit . For example, , , , , and , you can write the pair of integers and . Of course, there are many ways to form such pairs of integers: and , and , etc. The absolute value…
题意:将n个数字分成两组,两组分别组成一个数字,问两个数字的最小差值.要求,当组内数字个数多于1个时,组成的数字不允许有前导0.(2<=n<=10,每个数字范围是0~9) 分析: 1.枚举n个数字的全排列. 2.当两组数字个数相同或只差1时组成的两个数字才可能出现最小差值. 3.0~cnt/2 - 1为前半组数字,cnt/2~cnt-1为后半组数字. 4.注意getchar()的位置. #pragma comment(linker, "/STACK:102400000, 102400…
枚举两个排列以及有那些数字,用dfs比较灵活. dfs1是枚举长度短小的那个数字,dfs2会枚举到比较大的数字,然后我们希望低位数字的差尽量大, 后面最优全是0,如果全是0都没有当前ans小的话就剪掉. (第1个dfs完了,忘了加return... #include<cstdio> #include<iostream> #include<string> #include<cstring> #include<queue> #include<v…
Description On the evening of 3 August 1492, Christopher Columbus departed from Palos de la Frontera with a few ships, starting a serious of voyages of finding a new route to India. As you know, just in those voyages, Columbus discovered the America…
https://vjudge.net/problem/POJ-2965 与poj-1753相似,只不过这个要记录路径.poj-1753:https://www.cnblogs.com/fht-litost/p/9160723.html 题意 4*4的方格,翻转其中的一个把手,会带动同行同列的把手一起动.现要求把所有把手都翻成‘-’状态,问最少需要几步. 分析 异曲同工之妙.加个vector记录路径即可.使用状态压缩的写法输出路径也很方便. #include<iostream> #include…
Smallest Difference Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6740   Accepted: 1837 Description Given a number of distinct decimal digits, you can form one integer by choosing a non-empty subset of these digits and writing them in…
-->Smallest Difference 直接写中文了 Descriptions: 给定若干位十进制数,你可以通过选择一个非空子集并以某种顺序构建一个数.剩余元素可以用相同规则构建第二个数.除非构造的数恰好为0,否则不能以0打头. 举例来说,给定数字0,1,2,4,6与7,你可以写出10和2467.当然写法多样:210和764,204和176,等等.最后一对数差的绝对值为28,实际上没有其他对拥有更小的差. Input  输入第一行的数表示随后测试用例的数量.对于每组测试用例,有一行至少两个…
Smallest Difference Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10387   Accepted: 2836 Description Given a number of distinct decimal digits, you can form one integer by choosing a non-empty subset of these digits and writing them in…
POJ 2718 问题描述: 给一串数,求划分后一个子集以某种排列构成一个数,余下数以某种排列构成另一个数,求这两个数最小的差,注意0开头的处理. 超时问题:一开始是得到一个数列的组合之后再从中间进行切割得到两数,会超时.后来采用的方法是将前面的数在DFS中得到固定,在函数work中对后面(n-n/2)个数进行排列组合. 针对整个数列的dfs排列组合剪枝,若当前搜索的第二个数后面全部补零与第一个数所产生的差值比当前所搜索到的结果还要大,那么就直接返回.这个剪枝就是超时与几十MS的差距int nu…
Binary search. class Solution { int _findClosest(vector<int> &A, int v) { , e = A.size() - ; int ret = INT_MAX; while(s <= e) { ; int vmid = A[mid]; int dist = abs(vmid - v); ret = min(ret, dist); ; if(vmid < v) { s = mid + ; } else if(vmi…
POJ 3190 Stall Reservations贪心 Description Oh those picky N (1 <= N <= 50,000) cows! They are so picky that each one will only be milked over some precise time interval A..B (1 <= A <= B <= 1,000,000), which includes both times A and B. Obvi…
D. Diverse Garland time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You have a garland consisting of nn lamps. Each lamp is colored red, green or blue. The color of the ii-th lamp is sisi ('…
Given two array of integers(the first array is array A, the second array is arrayB), now we are going to find a element in array A which is A[i], and another element in array B which is B[j], so that the difference between A[i] and B[j] (|A[i] - B[j]…
LintCode 387: Smallest Difference 题目描述 给定两个整数数组(第一个是数组A,第二个是数组B),在数组A中取A[i],数组B中取B[j],A[i]和B[j]两者的差越小越好(|A[i] - B[j]|).返回最小差. 样例 给定数组A = [3,4,6,7],B = [2,3,8,9],返回 0. Mon Feb 27 2017 思路 先将两个数组排序,然后分别用一个指针i, j,从前往后遍历,若A[i] > B[j],要想差更小,那么需要j++,其它情况同理.…
POJ 2392 Space Elevator(贪心+多重背包) http://poj.org/problem?id=2392 题意: 题意:给定n种积木.每种积木都有一个高度h[i],一个数量num[i].另一个限制条件,这个积木所在的位置不能高于limit[i],问能叠起的最大高度? 分析: 本题是一道多重背包问题, 只是每一个物品的选择不只要受该种物品的数量num[i]限制, 且该物品还受到limit[i]的限制. 这里有一个贪心的结论: 我们每次背包选取物品时都应该优先放置当前limit…
完全想不到啊,同余模定理没学过啊,想起上学期期末考试我问好多同学'≡'这个符号什么意思,都说不知道,你们不是上了离散可的吗?不过看了别人的解法我现在会了,同余模定理介绍及运用点这里点击打开链接 简单说一下同余模定理:如果(a - b) / m = 0,说明a%m等于b%m,那么对于本题应该如何运用呢?  已知a % n = m,那么(a * 10 + x) % n = a * 10 % n + x % n = (a % n * 10 + x ) % n = (m *10 + x ) % n,有了…
Blue Jeans  Time Limit: 1000MS        Memory Limit: 65536K Total Submissions: 21078        Accepted: 9340 Description The Genographic Project is a research partnership between IBM and The National Geographic Society that is analyzing DNA from hundred…
Sum of Consecutive Prime Numbers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 19895   Accepted: 10906 Description Some positive integers can be represented by a sum of one or more consecutive prime numbers. How many such representatio…
思路: 暴力枚举三个点 判一判 搞定 (x1*y1=x2*y2) x1.y1.x2.y2为他们两两的差 //By SiriusRen #include <cstdio> using namespace std; int n,cnt; struct Point{int x,y;}point[888]; struct ans{int x,y,z;}ans[888]; int main(){ scanf("%d",&n); for(int i=1;i<=n;i++)…
Flip Game   Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 52279   Accepted: 22018 Description Flip game is played on a rectangular 4x4 field with two-sided pieces placed on each of its 16 squares. One side of each piece is white and th…
http://poj.org/problem?id=3187 给定一个个数n和sum,让你求原始序列,如果有多个输出字典序最小的. 暴力枚举题,枚举生成的每一个全排列,符合即退出. dfs版: #include <iostream> #include <cstdio> #include <cmath> #include <vector> #include <cstring> #include <string> #include <…
  How Big Is It?  Ian's going to California, and he has to pack his things, including his collection of circles. Given a set of circles, your program must find the smallest rectangular box in which they fit. All circles must touch the bottom of the b…
昨天梦到这道题了,所以一定要A掉(其实梦到了3道,有两道记不清了) 暴力枚举等的是哪张牌,将是哪张牌,然后贪心的判断就行了. 对于一个状态判断是否为胡牌,1-n扫一遍,然后对于每个牌,先mod 3, 如果还有剩余,就需要和i+1,i+2凑成顺子,减掉i+1,i+2的值就行了,然后 只要枚举到的i为负就是不可行,还有要枚举到n+2位,因为第n,n-1为可能 减了n+1,n+2但是没扫到. /******************************************************…