NOJ——1627Alex’s Game(II)(尺取)】的更多相关文章

[1627] Alex’s Game(II) 时间限制: 2000 ms 内存限制: 65535 K 问题描述 Alex likes to play with one and zero as you know . Today he gets a sequence which contains n(n<=1e5) integers.Each integer is no nore than 100.now he wants to know what’s the minimun contigous s…
Problem 1072: The longest same color grid Time Limits:  1000 MS   Memory Limits:  65536 KB 64-bit interger IO format:  %lld   Java class name:  Main Description There are n grid, m kind of color. Grid number 1 to N, color number 1 to M.  The color of…
题目链接 http://codeforces.com/problemset/gymProblem/100703/I Description standard input/outputStatements As a matter of fact, Dragon knows what Prince is interested in now. Prince uses to spend his rare off days learning different courses and trainings.…
Bob’s Race Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Problem Description Bob wants to hold a race to encourage people to do sports. He has got trouble in choosing the route. There are N houses and N - 1 roads…
题目链接:http://codeforces.com/problemset/problem/180/E 给你n个数,每个数代表一种颜色,给你1到m的m种颜色.最多可以删k个数,问你最长连续相同颜色的序列的长度是多少. 将相同颜色的下标存到对应颜色的容器中,比如ans[a[i]].push_back(i)就是将下标为i颜色为a[i]的数存到ans[a[i]]容器中. 对于每种颜色序列,尺取一下 在差距小于k的情况下取能取到的最大长度. //#pragma comment(linker, "/STA…
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 come in two…
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. After a con…
题目链接 Problem Description 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 le…
<题目链接> 题目大意:给定一段序列,每次进行两次操作,输入1 x代表插入x元素(x元素一定大于等于之前的所有元素),或者输入2,表示输出这个序列的任意子集$s$,使得$max(s)-mean(s)$表示这个集合的最大值与平均值的最大差值. 解题分析:首先,因为输入的$x$是非递减的,所以要使$max(s)-mean(s)$最大,肯定$max(s)$就是最后一个输入元素的大小.$x$已经确定了,现在就是尽可能的使$mean(s)$尽可能的小.如何使得平均值最小呢?肯定是从最前面的最小的元素开始…
尺取,写起来有点麻烦 枚举左端点,然后找到右端点,,使得区间[l,r]里各种颜色花朵的数量满足b数组中各种花朵的数量,然后再judge区间[l,r]截取出后能否可以供剩下的n-1个人做花环 /* 给定序列A,分成n段,每段k个, 然后删掉A中的一些,但任要能组成n段,使得A中的一段包含序列B中的所有元素 如果可以输出删掉的元素,否则输出-1 */ #include<bits/stdc++.h> using namespace std; #define maxn 500005 int m,k,n…
<题目链接> 题目大意: 给定一个整数序列,求出绝对值小于等于k的有序对个数. 解题分析: $O(nlong(n))$的二分很好写,这里就不解释了.本题尺取$O(n)$也能做,并且效率很不错. 尺取: #include <bits/stdc++.h> using namespace std; )]; int main(){ int T,n,k;scanf("%d",&T); while(T--){ scanf("%d%d",&…
<题目链接> 题目大意:给定一个只由26个小写字母组成的字符串,现在问你至少包含k个不同字母的连续子序列总数有多少. 解题分析:经仔细研究,我们发现,每次尺取到符合要求的最小区间,然后将区间的右端点一直移动到字符串的末尾,右端点每移动一位,又能组成一个符合条件的字符串序列,并且,因为每次尺取的过程中,左指针会不断向右移动一位,所以这样的求解能够是的最终的答案不重不漏. #include <bits/stdc++.h> using namespace std; )]; ]; inli…
/* 二维上的尺取,外层循环枚举j轴上的可能,内层在i轴上尺取即可 O(N^3) */ #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; #define maxn 305 int r,c,kk,sum[maxn][maxn]; char mp[maxn][maxn]; int main(){ while(scanf(&q…
尺取+枚举,推出公式以后就是一个枚举加尺取 但是这题的尺取不是对一个值尺取,而是在一个区间内,所以固定左边界,尺取右边界即可 #include<bits/stdc++.h> #define maxn 100005 #define ll long long using namespace std; int t,n,m,k,x,y,z,l,tot; ll cnt,sum[maxn]; int a[maxn]; ll solve(ll L,ll R){//求区间[l,R)内i+j的和 ll ans=…
因为没有初始化ans搞了一晚上 还是尺取,枚举所有l 然后寻找对应满足条件的r,这个串可以被后面所有的串包含,所以每个l 的贡献就是len-r+1 #include<bits/stdc++.h> using namespace std; #define ll long long int main(){ int t,k,len,r,sum; ll ans=; ]; ]; scanf("%d",&t); while(t--){ memset(vis,,sizeof vi…
题意:n个城市,初始能量c,进入i城市获得a[i]能量,可能负数,去i+1个城市失去b[i]能量,问你能不能完整走一圈. 思路:也就是走的路上能量不能小于0,尺取维护l,r指针,l代表出发点,r代表当前走到的点,维护一个sum.和工程的题一模一样啊. 代码: #include<set> #include<map> #include<stack> #include<cmath> #include<queue> #include<vector&…
Bound Found Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 1651   Accepted: 544   Special Judge Description Signals of most probably extra-terrestrial origin have been received and digitalized by The Aeronautic and Space Administration…
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) are given. Write a program to find the minimal length of the subsequence of consecutive elements o…
题意:在n*m方格中找有几个x*y矩阵. 思路:二维hash,总体思路和一维差不太多,先把每行hash,变成一维的数组,再对这个一维数组hash变成二维hash.之前还在想怎么快速把一个矩阵的hash算出来,然后看到是尺取,也不知道是什么...这应该算是用到了这个思想吧. 要先预处理每行y个的hash(看代码),然后每次算出上面两顶点在第一行的hash值,慢慢往下移.hash看上去就像是在算一个seed位数一样,seed取13那么就是把字符串转化为了一个13位数,这样想可能在移动的时候更容易理解…
The heat during the last few days has been really intense. Scientists from all over the Berland study how the temperatures and weather change, and they claim that this summer is abnormally hot. But any scientific claim sounds a lot more reasonable if…
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) are given. Write a program to find the minimal length of the subsequence of consecutive elements o…
Bob’s Race Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 3905    Accepted Submission(s): 1245 Problem Description Bob wants to hold a race to encourage people to do sports. He has got trouble…
Description 你的朋友Mishka和你参加一个微积分讲座.讲座持续n分钟.讲师在第i分钟讲述ai个定理.   米什卡真的对微积分很感兴趣,尽管在演讲的所有时间都很难保持清醒.给你一个米什卡行为的数组t.如果Mishka在演讲的第一分钟睡着了,那么ti将等于0,否则它将等于1.当米什卡醒来时,他写下讲师所讲述的所有定理 .否则,他什么都不写.   你知道一些方式让Mishka直线醒过来持续k分钟.但是,您只能使用一次.你可以在1和n - k + 1之间的任何一分钟开始使用它.如果你在一分…
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 representations 5 + 7 + 11 + 13 + 17 and 53…
B. Complete the Word time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output ZS the Coder loves to read the dictionary. He thinks that a word is nice if there exists a substring (contiguous segmen…
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) are given. Write a program to find the minimal length of the subsequence of consecutive elements of the sequen…
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 come in two…
任意门:http://codeforces.com/contest/1073/problem/C C. Vasya and Robot time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Vasya has got a robot which is situated on an infinite Cartesian plane, i…
题目链接 emmm看起来好像无从下手, \(l_i,r_i\)这么大,肯定是要离散化的. 然后我们是选\(m\)个区间,我们先对这些区间按长度排个序也不影响. 排序后,设我们取的\(m\)个区间的编号是\(b_1,b_2,...,b_m\), 若\(b_m\)确定,我们肯定是要尽量使\(b_1,b_2,...,b_{m-1}\)尽量接近\(b_m\)的,这样可使代价最小. 所以,就可以尺取了. 定义两个指针\(l,r\),首先\(r\)指针不停右移覆盖一遍扫到的区间直到满足条件有一个点被连续覆盖…
1686 第K大区间 基准时间限制:1 秒 空间限制:131072 KB 分值: 40 难度:4级算法题 定义一个区间的值为其众数出现的次数.现给出n个数,求将所有区间的值排序后,第K大的值为多少. 众数(统计学/数学名词)_百度百科 Input 第一行两个数n和k(1<=n<=100000,k<=n*(n-1)/2) 第二行n个数,0<=每个数<2^31 Output 一个数表示答案. Input示例 4 2 1 2 3 2 Output示例 2 //首先,考虑区间的值的性…