题意:给出 n个数,找到尽量长的一个序列,使得该序列中没有重复的元素 看的紫书,滑动窗口来做的 当右端碰到有相同的数的时候,左端向前滑动一个数 模拟一个样例好理解些 #include<iostream> #include<cstdio> #include<cstring> #include <cmath> #include<stack> #include<vector> #include<map> #include<…
题目地址:UVa 11572 这样的方法曾经接触过,定义两个指针,不断从左向右滑动,推断指针内的是否符合要求. 这个题为了能高速推断是否有这个数,能够用STL中的set. 代码例如以下: #include <iostream> #include <cstdio> #include <string> #include <cstring> #include <stdlib.h> #include <math.h> #include <…
本书是关于使用刘汝佳set, 通过收集找到.count()和删除.erase().这种方法比我好.用较短的时间. 我想map这个任务可以完成.但是,这是不容易删除,必须先找到find()标.然后删除索引对应的元素 但map有map的使用方法.以下的方法就是比較easy实现的一种方法. 我本想着这个一边读完就计算出了ans,应该更快一点的.可是其实还不如先读再用set处理来得快. #include<cstdio> #include<iostream> #include<map&…
Emily the entrepreneur has a cool business idea: packaging and selling snowakes. She has devised amachine that captures snowakes as they fall, and serializes them into a stream of snowakes that ow,one by one, into a package. Once the package is full,…
/* STLsort离散化==T 手工sort离散化==T map在线==T map离线处理c==A 240ms */ #include<cstdio> #include<map> #define maxn 1000010 using namespace std; int T,n,c[maxn],a[maxn],ans,s,t,num; map<int,int>p; int init(){ ,f=;char s=getchar(); ;s=getchar();} +s-…
用set,保存当前区间出现过的数字,如果下一个数字没有出现过,加入,否则删掉左端点,直到没有重复为止 #include<bits/stdc++.h> using namespace std; ; int A[maxn]; int main() { int T; scanf("%d",&T); while(T--){ int n; scanf("%d",&n); ; i < n; i++) scanf("%d",A…
题目:点击打开题目链接 思路:从左往右扫描,定义扫描左端点L,右端点R,保证每次往几何中添加的都是符合要求的连续的数列中的元素,L和R从0扫到n,复杂度为O(n),使用set维护子数列,set查找删除都是O(logn),所以复杂度为O(nlogn),应特别注意set内并不是原子数列顺序,若要删除子数列起始元素,不能使用begin迭代器 AC代码: #include <iostream> #include <set> #include <algorithm> #inclu…
题意:输入一个长度为n(n <= 10^6)的序列A,找到一个尽量长的连续子序列AL~AR,使得该序列中没有相同的元素. 分析: 法一:从r=0开始不断增加r,当a[r+1]在子序列a[l~r]中出现过,只需增大l,并继续延伸r,因为a[l~r]为可行解,则l增大后必然还是可行解.用set判断a[r+1]是否出现过,并进行a[l]的删除操作. #pragma comment(linker, "/STACK:102400000, 102400000") #include<cs…
白书一:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=64609#overview 注意UVA没有PE之类的,如果PE了显示WA. UVA401:Palindromes #include <iostream> #include <cstdio> #include <cstring> #include <cstdlib> #include <algorithm> using namesp…
题目地址:UVa 120 水题. 从最大的開始移,每次都把大的先翻到最上面,再翻到以下. 代码例如以下: #include <iostream> #include <cstdio> #include <string> #include <cstring> #include <stdlib.h> #include <math.h> #include <ctype.h> #include <queue> #incl…
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 package is…
用STL做会很方便 SET: /*by SilverN*/ #include<iostream> #include<algorithm> #include<cstring> #include<cstdio> #include<cmath> #include<set> using namespace std; ; int a[mxn]; int n,T; int main(){ scanf("%d",&T);…
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…
白书P61 - 点集配对问题 状压DP #include <iostream> #include <cstdio> #include <cstring> using namespace std; #define INF 0x3f3f3f3f struct Point { double x,y,z; }p[+]; int n; <<)+]; //dp[j]表示j对应状态(0为未配对,1为配对了)的最小距离和 double dist(int i,int j) {…
白书P60 - 硬币问题 完全背包.DP #include <iostream> #include <cstdio> #include <cstring> using namespace std; #define INF 0x3f3f3f3f #define N 1010 int n,s; int w[N]; //w表示n种硬币的面值 int dp1[N]; //dp1[j]表示刚好凑足j的最少硬币数 int dp2[N]; //dp2[j]表示刚好凑足j的最多硬币数…
题目大意:起重机有n节,题目给出要调节的k节,每节调节成x度,求最后底部的起重机的坐标(最顶上的起点为(0,0)). 分析:一开始我看白书,看不懂他那个向量旋转的坐标是怎么来的,翻了很多博客,才发现,是自己数学基础的遗漏(都怪自己高中没好好学T.T),向量旋转涉及到复数的概念和表达. 首先复数表达式z=x+i*y=|z|*(cosx+i*sinx)(i²=-1),假设两个个复数分别为 z1=x1+y1*i=r1*(cos(p1)+i*sin(p1)) z2=x2+y2*i=r2*(cos(p2)…
白书的一道水题.话说好久没认真做难题了.今天出了排名,所有队伍里倒数第一啊! 代码没什么可说的了. #include <algorithm> #include <cstring> #include <ctype.h> #include <cstdlib> #include <cstdio> #include <vector> #include <string> #include <queue> #include…
白书上的线段树RMQ实现,自己重写了一遍: #include <bits/stdc++.h> using namespace std; const int MAXN=1<<17; int n,dat[MAXN*2-1]; //把所有的值设为MAXN void init(int _n) { n=1; while(n<_n)n*=2; for(int i=0;i<2*n-1;i++) { dat[i]=MAXN; } } //把第k个值(0-index)更新为a void…
题目: 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 pa…
You are given a string S consisting of lowercase letters, and your task is counting the number of substring that the number of each lowercase letter in the substring is no more than K.   Input In the first line there is an integer T , indicates the n…
题意:求长度为N的序列中,最长的一个无重复元素的连续子序列. 解法:[L,R]每次R++或L++延伸就可以得到答案. 实现:(1)next[],last[]--O(n): 1 #include<cstdio> 2 #include<cstdlib> 3 #include<cstring> 4 #include<iostream> 5 #include<algorithm> 6 using namespace std; 7 #define N (i…
滑动窗口挺有意思的,如果符合条件右端点一直向前走,不符合的话,左端点向前走. #include <bits/stdc++.h> using namespace std; set<int> Set; + ; int a[maxn]; int Scan() { //输入外挂 ; char ch; ') res = res * + (ch - '); return res; } int main() { //freopen("in.txt", "r"…
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 类似尺取法. 用set判断这段区间有没有重复的数字. 有的话,就把头节点的那个数字删掉,直到没有为止. [代码] /* 1.Shoud it use long long ? 2.Have you ever test several sample(at least therr) yourself? 3.Can you promise that the solution is right? At least,the main ide…
直接上代码... (另外也可以在递归的时候统计最优解,不过程序稍微复杂一点) #include <iostream> #include <string> #include <sstream> using namespace std; const int maxn=10000+10; int in_order[maxn],post_order[maxn],lch[maxn],rch[maxn]; int n; bool read_list(int *a){//输入一行用空…
是否可以把树上结点的编号,然后把二叉树存储在数组中呢?很遗憾如果结点在一条链上,那将是2^256个结点 所以需要采用动态结构 首先要读取结点,建立二叉树addnode()+read_input()承担这样的工作 然后遍历二叉树,读取结点编号输出bfs() 这道题有内存池应用的背景 附链接  http://blog.csdn.net/shawngucas/article/details/6574863 #include <cstdio> #include <cstring> #inc…
看着lrj的代码自己敲了一遍,还没调试成功.... 有时间再进行完善 /* 状态start到各个状态u1,u2,u3..... 的倒水量分别为u1.dist,u2.dist,u3.dist.... */ /* 按倒水量递增的顺序去寻找当前状态的v[0],v[1],v[2]是否为d 但是程序实现的时候我们寻找目标水量是根据 ans[d]>0,而不是对每一个状态的v[]进行遍历 为什么这样做呢?当然是因为麻烦,ans[d]>0很直接地说明了v[]有三者之一为d */ #include <cs…
滑动窗口这个方法名字非常形象, 先是窗口的右指针尽量往右滑, 滑不动了就滑窗口的左指针, 滑到右指针又可以开始滑动为止. 这道题是要记录滑的过程中最大的窗口长度, 限制条件是窗口中不能出现重复的值. 重复的值有两种判断方法. 一种是set, 其实就是开个vis数组, 但是数据有10的六次方, 数组肯定开不下, 所以用set来代替, 用时间换空间, set的查询是logn, 比数组要慢. 第二种是用map计算出一个last数组, 保存的是与当前数相同的前一个数的坐标. 两种方法大同小异. set版…
具体题解看大白书P316 #include <iostream> #include <algorithm> #include <vector> #include <string.h> #include <stack> #include <cstdio> using namespace std; struct Edge{int u,v;}; +; int pre[maxn],iscut[maxn],bccno[maxn],dfs_clo…
题目链接:https://uva.onlinejudge.org/external/115/11572.pdf 题意:找到一个尽量长的连续子序列 Al ~ AR ,使得该序列没有相同的元素. 分析:枚举超时,怎么优化呢? 当我不停的将右端点右移,当我移不动的时候,说明之前的 l ~ r  里面有一个和 r++的元素相同. 但是,不代表 l ~ r 就没有用了,他本身还是有作用的,只要将 l 右移即可.这样,单看这里,时间复杂度为O(n) , 然后就是查看 r++ 的元素是否和前面的相同,用 se…
个人感觉有点坑 add用的标记永久化 set用的标记下传 #include <iostream> #include <cstdio> #include <algorithm> #include <cstring> #define lson o<<1,l,m #define rson (o<<1)+1,m+1,r #define ls o<<1 #define rs (o<<1)+1 using namespac…