题目: 思路: 读完题之后第一时间想到的是尺取法来做这个题,结果让自己写写崩了,还是练得少!! 到网上搜了一下学习了大佬的标记方法,用一个变量来判断是不是都已经出现,要比每次都判断一下快超多. 代码: #include <bits/stdc++.h> #define inf 0x3f3f3f3f #define MAX 1e3 #define FRE() freopen("in.txt","r",stdin) #define FRO() freopen(…
题意:给定 n 个由0~m-1的整数组成的序列,输入 k ,问你找出连续的最短序列,使得这个序列含有1-k的所有整数. 析:这个题,很简单么,只要从头开始扫一遍就OK,时间复杂度为O(n). 代码如下: #include <cstdio> #include <string> #include <cstdlib> #include <cmath> #include <iostream> #include <cstring> #inclu…
题目大意:按照题目中的要求构造出一个序列,找出最短的子序列,包含1~k. 解题思路:先根据题目的方法构造出序列,然后用Towpointer的方法,用v[i]来记录当前[l, r]中有几个i:当r移动时,出现v[i] == 1时, c++(用来记录有几个1~k的数字):当c == k 时,就要移动l,当出现v[i] == 0时,c--. #include <cstdio> #include <cstring> #include <iostream> #include &l…
题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=3141 题意 一个1到n的排列,每次随机删除一个,问删除前的逆序数 思路 综合考虑,对每个数点,令value为值,pos为位置,time为出现时间(总时间-消失时间),明显是统计value1 > value2, pos1 < pos2, time1 < time2的个…
Emily the entrepreneur has a cool business idea: packaging and selling snowflakes. She has devised a machine that captures snowflakes as they fall, and serializes them into a stream of snowflakes that flow, one by one, into a package. Once the packag…
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 尺取法. 考虑一个1..i的窗口. 里面在到达了i位置的时候恰好有1..k这些数字了. 为了更接近答案. 显然可以试着让左端点变成2.(如果还能有1..k这些数字的话. 所以有1..k这些数字之后.就让左端点尽可能往右. 然后尝试更新答案. 然后让右端点右移. 重复上述过程. [代码] #include <bits/stdc++.h> #define ll long long #define rep1(i,a,b) for (…
D. Longest k-Good Segment 题目连接: http://www.codeforces.com/contest/616/problem/D Description The array a with n integers is given. Let's call the sequence of one or more consecutive elements in a segment. Also let's call the segment k-good if it conta…
转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud First One Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 1158    Accepted Submission(s): 347 Problem Description soda has an integer…
[尺取法]Jurisdiction Disenchantment PROBLEM 时间限制: 1 Sec 内存限制: 128 MB 题目描述 The Super League of Paragons and Champions (SLPC) has been monitoring a plot by a corrupt politician to steal an election. In the past week, the politican has used a mind-control…
Alice are given an array A[1..N] with N numbers. Now Alice want to build an array B by a parameter K as following rules: Initially, the array B is empty. Consider each interval in array A. If the length of this interval is less than K, then ignore th…