POJ 3419 Difference Is Beautiful】的更多相关文章

Difference Is Beautiful Time Limit:5000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu Submit Status Practice POJ 3419 Description Mr. Flower's business is growing much faster than originally planned. He has now become the CEO of a world-…
题意:N个数,M个询问,每个询问为一个区间,求区间最长连续子序列,要求每个数都不同(perfect sequence,简称PS). 题解:很容易求出以每个数为结尾的ps,也就是求区间的最大值.有一个不同就是长度可能会超出询问范围,所以先对PS的首位置二分,然后RMQ.注意一点,序列有可能出现负数,所以先加最大值变为正数.其实也不算变形,挺裸的…… 这题卡线段树,然而我只会线段树,心塞…… 代码(树状数组): #include <iostream> #include <cstring>…
先处理出每一个i位置向左最远能到达的位置L[i].每一次询问,要找到L,R区间中的p位置,p位置左边的L[i]都是小于L的,p位置开始,到R位置,L[i]都大于等于L,对于前者,最大值为p-L,后者求一个区间最大值即可. #pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #include<cstring> #include<cmath> #include&…
题意:给n个数(n<=200000),每个数的绝对值不超过(10^6),有m个查询(m<=200000),每次查询区间[a,b]中连续的没有相同数的的最大长度. 析:由于n太大,无法暴力,也承受不了O(n*n)的复杂度,只能是O(nlogn),首先是用f[i] 表示每个数 i 为左端点,向右可以最多到达的点为f[i], 那么这个dp很好转移,f[i] = max(f[i+1], last[a[i]]),其中last数组是用来记录上次序列数中a[i]的出现的位置. 那么对于给定的区间[l, r]…
题意:给出一堆点,求从起点到终点的所有通路中相邻点的距离的最大值的最小值.(意思就是自己百度吧……) 解法:用相邻点的最大值作为权值代替路径的距离跑最短路或者最小生成树.然后我写了一个我以为是优化过的dijkstra但好像是prim的东西- -啊差不多啦…… 总之用优先队列维护权值进行广搜……然后交G++一直wa也不知道为啥……交了C++就过了…… 代码: #include<stdio.h> #include<iostream> #include<algorithm>…
-----------------------------最优化问题------------------------------------- ----------------------常规动态规划  SOJ1162 I-Keyboard  SOJ1685 Chopsticks SOJ1679 Gangsters SOJ2096 Maximum Submatrix  SOJ2111 littleken bg SOJ2142 Cow Exhibition  SOJ2505 The County…
 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…
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…
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…
题目: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…
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…
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…
-->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: 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…
题意: 就是说给你一些数,然后要求你使用这些数字组成2个数,然后求他们的差值最小. 思路: 我用的双重DFS做的,速度还比较快,其中有一个很重要的剪枝,若当前搜索的第二个数后面全部补零与第一个数所产生的差值比当前所搜索到的结果还要大,那么就直接返回.这个剪枝就是超时与几十MS的差距 注意一点就是可能有0 与一个数字存在的情况,比如0 3,0 5等等. #include<cstdio> #include<cstring> #include<cstdlib> #includ…
最小的差别 题目大意:输入一串数字,问你数字的组合方式,你可以随意用这些数字组合(无重复)来组合成一些整数(第一位不能为0),然后问你组合出来的整数的差最小是多少? 这一题可以用枚举的方法去做,这里我就用枚举和贪心(这个非常爽)的方法去. 首先这一题的限制是1000ms,我们知道全枚举的时间肯定是超时的,所以我们必须裁枝,我们这样看,我们得到的最小值,必须是两个数差别最小的时候才会出现,所以这里我们可以只用枚举lenth/2时候的数串的情况,这样就降低了很多的复杂度. 但是这样还是不够,但是我们…
枚举两个排列以及有那些数字,用dfs比较灵活. dfs1是枚举长度短小的那个数字,dfs2会枚举到比较大的数字,然后我们希望低位数字的差尽量大, 后面最优全是0,如果全是0都没有当前ans小的话就剪掉. (第1个dfs完了,忘了加return... #include<cstdio> #include<iostream> #include<string> #include<cstring> #include<queue> #include<v…
题意:将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…
http://poj.org/problem?id=1266 Cover an Arc. Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 823   Accepted: 308 Description A huge dancing-hall was constructed for the Ural State University's 80-th anniversary celebration. The size of t…
http://poj.org/problem?id=3262 Protecting the Flowers Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 4930   Accepted: 1965 Description Farmer John went to cut some wood and left N (2 ≤ N ≤ 100,000) cows eating the grass, as usual. When…
Sightseeing tour Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 6986   Accepted: 2901 Description The city executive board in Lund wants to construct a sightseeing tour by bus in Lund, so that tourists can see every corner of the beauti…
Selecting Courses Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8316   Accepted: 3687 Description It is well known that it is not easy to select courses in the college, for there is usually conflict among the time of the courses. Li Mi…
Wall Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 28157   Accepted: 9401 Description Once upon a time there was a greedy King who ordered his chief Architect to build a wall around the King's castle. The King was so greedy, that he wo…
POJ 3277 City Horizon Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 18466 Accepted: 5077 Description Farmer John has taken his cows on a trip to the city! As the sun sets, the cows gaze at the city horizon and observe the beautiful silho…
Wall Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 28462   Accepted: 9498 Description Once upon a time there was a greedy King who ordered his chief Architect to build a wall around the King's castle. The King was so greedy, that he wo…
http://poj.org/problem?id=1113 答案是凸包周长+半径为l的圆的周长... 证明?这是个坑.. #include <cstdio> #include <cstring> #include <cmath> #include <string> #include <iostream> #include <algorithm> #include <queue> #include <set>…
题目链接:http://poj.org/problem?id=3522 Slim Span Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 7522   Accepted: 3988 Description Given an undirected weighted graph G, you should find one of spanning trees specified as follows. The graph G…
Stars in Your Window Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10806   Accepted: 2980 Description Fleeting time does not blur my memory of you. Can it really be 4 years since I first saw you? I still remember, vividly, on the beaut…
题目链接:http://poj.org/problem?id=3264 Balanced Lineup Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 47515   Accepted: 22314 Case Time Limit: 2000MS Description For the daily milking, Farmer John's N cows (1 ≤ N ≤ 50,000) always line up i…