poj 2100(尺取法)】的更多相关文章

Graveyard Design Time Limit: 10000MS   Memory Limit: 64000K Total Submissions: 6107   Accepted: 1444 Case Time Limit: 2000MS Description King George has recently decided that he would like to have a new design for the royal graveyard. The graveyard m…
1.POJ 3320 2.链接:http://poj.org/problem?id=3320 3.总结:尺取法,Hash,map标记 看书复习,p页书,一页有一个知识点,连续看求最少多少页看完所有知识点 必须说,STL够屌.. #include<iostream> #include<cstring> #include<cmath> #include<queue> #include<algorithm> #include<cstdio>…
Jessica's Reading Problem Description Jessica's a very lovely girl wooed by lots of boys. Recently she has a problem. The final exam is coming, yet she has spent little time on it. If she wants to pass it, she has to master all ideas included in a ve…
题目链接: http://poj.org/problem?id=3320 题目大意:一本书有P页,每页有个知识点,知识点可以重复.问至少连续读几页,使得覆盖全部知识点. 解题思路: 知识点是有重复的,因此需要统计不重复元素个数,而且需要记录重复个数. 最好能及时O(1)反馈不重复的个数.那么毫无疑问,得使用Hash. 推荐使用map,既能Hash,也能记录对于每个key的个数. 尺取的思路: ①不停扩展R,并把扫过知识点丢到map里,直到map的size符合要求. ②更新结果. ②L++,map…
Bound Found Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 4297   Accepted: 1351   Special Judge Description Signals of most probably extra-terrestrial origin have been received and digitalized by The Aeronautic and Space Administration…
传送门:Problem 3320 参考资料: [1]:挑战程序设计竞赛 题意: 一本书有 P 页,每页都有个知识点a[i],知识点可能重复,求包含所有知识点的最少的页数. 题解: 相关说明: 设以a[start]开始的最初包含所有知识点的最少连续子序列为a[start,....,end]; mymap[ a[i] ] : 知识点 a[i] 在当前最少连续子序列中出现的次数. (1):求出所需复习的知识点总个数. (2):求出最先包含所有知识点的最少页数a[start,........,end].…
Description King George has recently decided that he would like to have a new design for the royal graveyard. The graveyard must consist of several sections, each of which must be a square of graves. All sections must have different number of graves.…
尺取法:顾名思义就是像尺子一样一段一段去取,保存每次的选取区间的左右端点.然后一直推进 解决问题的思路: 先移动右端点 ,右端点推进的时候一般是加 然后推进左端点,左端点一般是减 poj 2566 题意:从数列中找出连续序列,使得和的绝对值与目标数之差最小 思路: 在原来的数列开头添加一个0 每次找到的区间为 [min(i,j)+1,max(i,j)] 应用尺取法的代码: while (r <=n) { int sub = pre[r].sum - pre[l].sum; while (abs(…
poj3061 Subsequence 题目链接: http://poj.org/problem?id=3061 挑战P146.题意:给定长度为n的数列整数a0,a1,...,a(n-1)以及整数S,求出总和不小于S的连续子序列的长度的最小值,如果解不存在,则输出零.$10<n<10^5,0<a_i<=10^4,S<10^8$; 思路:尺取法,设起始下标s,截止下标e,和为sum,初始时s=e=0;若sum<S,将sum增加a(e),并将e加1,若sum>=S,更…
题目链接: http://poj.org/problem?id=3061 题目大意:找到最短的序列长度,使得序列元素和大于S. 解题思路: 两种思路. 一种是二分+前缀和.复杂度O(nlogn).有点慢. 二分枚举序列长度,如果可行,向左找小的,否则向右找大的. 前缀和预处理之后,可以O(1)内求和. #include "cstdio" #include "cstring" ],n,s,a,T; bool check(int x) { int l,r; ;i+x-&…
Description Jessica's a very lovely girl wooed by lots of boys. Recently she has a problem. The final exam is coming, yet she has spent little time on it. If she wants to pass it, she has to master all ideas included in a very thick text book. The au…
http://poj.org/problem?id=3320 题意:给出一串数字,要求包含所有数字的最短长度. 思路: 哈希一直不是很会用,这道题也是参考了别人的代码,想了很久. #include<iostream> #include<algorithm> #include<string> #include<cstring> using namespace std; ; int n; int len; //开散列法,也就是用链表来存储,所以下面的len是从P…
题目传送门 /* 尺取法:先求出不同知识点的总个数tot,然后以获得知识点的个数作为界限, 更新最小值 */ #include <cstdio> #include <cmath> #include <cstring> #include <algorithm> #include <set> #include <map> using namespace std; ; const int INF = 0x3f3f3f3f; int a[MA…
题目传送门 /* 题意:求连续子序列的和不小于s的长度的最小值 尺取法:对数组保存一组下标(起点,终点),使用两端点得到答案 1. 记录前i项的总和,求[i, p)长度的最小值,用二分找到sum[p] - s[i] >= s的p 2. 除了O (nlogn)的方法,还可以在O (n)实现,[i, j)的区间求和,移动两端点,更新最小值,真的像尺取虫在爬:) */ #include <cstdio> #include <algorithm> #include <cstri…
http://poj.org/problem?id=3061 题目大意: 给定长度为n的整列整数a[0],a[1],--a[n-1],以及整数S,求出总和不小于S的连续子序列的长度的最小值. 思路: 方法一: 首先求出各项的和sum[i],这样可以在O(1)的时间内算出区间上的总和,这样,枚举每一个起点i,然后二分搜索出结果大于sum[i]+tot的最小下标.(tot是题目中的S) 总的时间为O(nlogn) 方法二: 设以a[s]开始的总和最初大于S时的连续子序列为a[s]+a[s+1]+--…
题意 $ T $ 组数据,每组数据给一个长度 $ N $ 的序列,要求一段连续的子序列的和大于 $ S $,问子序列最小长度为多少. 输入样例 2 10 15 5 1 3 5 10 7 4 9 2 8 5 11 1 2 3 4 5 输出样例 2 3 解析 我们很容易发现对于这题我们可以二分答案,先找出一个初始长度,判断是否存在合法序列,如果存在缩小长度,如果不存在加长长度. 时间复杂度 $ O(nlogn) $ 代码 #include<cstdio> #include<algorithm…
jessica's Reading PJroblem Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9134   Accepted: 2951 Description Jessica's a very lovely girl wooed by lots of boys. Recently she has a problem. The final exam is coming, yet she has spent litt…
http://poj.org/problem?id=2566: Bound Found Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 2237   Accepted: 692   Special Judge Description Signals of most probably extra-terrestrial origin have been received and digitalized by The Aero…
题目链接: 传送门 Sum of Consecutive Prime Numbers Time Limit: 1000MS     Memory Limit: 65536K Description Some positive integers can be represented by a sum of one or more consecutive prime numbers. How many such representations does a given positive intege…
题 题意 P个数,求最短的一段包含P个数里所有出现过的数的区间. 分析 尺取法,边读边记录每个数出现次数num[d[i]],和不同数字个数n个. 尺取时,l和r 代表区间两边,每次r++时,d[r]即r的出现次数+1,d[l]即l的出现次数大于1时,左边可以短一点,d[l]--,l++,直到d[l]出现次数为1,当不同数达到n个,且区间更小,就更新答案. 代码 #include <cstdio> #include <map> using namespace std; map <…
转自博客:http://blog.chinaunix.net/uid-24922718-id-4848418.html 尺取法就是两个指针表示区间[l,r]的开始与结束 然后根据题目来将端点移动,是一种十分有效的做法.适合连续区间的问题 poj3061 给定长度为n的数列整数a0,a1,a2,a3 ..... an-1以及整数S.求出综合不小于S的连续子序列的长度的最小值.如果解不存在,则输出0. 这里我们拿第一组测试数据举例子,即 n=10, S = 15, a = {5,1,3,5,10,7…
Description Signals of most probably extra-terrestrial origin have been received and digitalized by The Aeronautic and Space Administration (that must be going through a defiant phase: "But I want to use feet, not meters!"). Each signal seems to…
Subsequence Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 13955   Accepted: 5896 Description A sequence of N positive integers (10 < N < 100 000), each of them less than or equal 10000, and a positive integer S (S < 100 000 000) ar…
传送门 参考资料: [1]:http://www.voidcn.com/article/p-huucvank-dv.html 题意: 题意就是找一个连续的子区间,使它的和的绝对值最接近target. 题解: 这题的做法是先预处理出前缀和,然后对前缀和进行排序,再用尺取法贪心的去找最合适的区间. 要注意的是尺取法时首尾指针一定不能相同,因为这时区间相减结果为0,但实际上区间为空,这是不存在的,可能会产生错误的结果. 处理时,把(0,0)这个点也放进数组一起排序,比单独判断起点为1的区间更方便. 还…
<题目链接> 题目大意: 给你一段长度为n的整数序列,并且给出一个整数S,问你这段序列中区间之和大于等于S的最短区间长度是多少. 解题分析:本题可以用二分答案做,先求出前缀和,然后枚举区间长度,然后再判断其是否合法即可,复杂度$O(nlog(n))$.同时,尺取法也是一个不错的选择,通过不断的移动区间的头.尾指针来寻求答案,复杂度为 $O(n)$. 尺取法: #include <cstdio> #include <cstring> #include <algori…
传送门:Problem 3061 https://www.cnblogs.com/violet-acmer/p/9793209.html 马上就要去上课了,先献上二分AC代码,其余的有空再补 题意: 给定长度为 n 的整数数列 a[0,1,2,........,n]以及整数 S. 求出总和不小于 S 的连续子序列的长度的最小值. 如果解不存在,则输出 0. 题解: 1.二分 由于所有的元素都大于 0 ,所以数组a[ ] 的前缀和sum[ ]为递增的序列,满足二分的条件. 首先确定子序列的起点为s…
Jessica's a very lovely girl wooed by lots of boys. Recently she has a problem. The final exam is coming, yet she has spent little time on it. If she wants to pass it, she has to master all ideas included in a very thick text book. The author of that…
Jessica's Reading Problem Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7467   Accepted: 2369 Description Jessica's a very lovely girl wooed by lots of boys. Recently she has a problem. The final exam is coming, yet she has spent littl…
Time Limit: 1000MS   Memory Limit: 65536K Description Some positive integers can be represented by a sum of one or more consecutive prime numbers. How many such representations does a given positive integer have? For example, the integer 53 has two r…
Bound Found Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 5207   Accepted: 1667   Special Judge Description Signals of most probably extra-terrestrial origin have been received and digitalized by The Aeronautic and Space Administration…