st

httpservletrequest对象详解

匿名 (未验证) 提交于 2019-12-03 00:22:01
找ctx代表什么。假如:pageContext.setAttribute("ctx", application.getContextPath());从上面的解说可以知道System.out.println(request.getContextPath())得出的是/news。故完整路径为:/news/admin/category/create.do。至于参数则根据实际研究。 可看到上路径为.do结尾。Spring MVC与Struts从原理上很相似(都是基于MVC架构),都有一个控制页面请求的Servlet,处理完后跳转页面。spring会自动扫描找到该路径对应的controller,如下图所示: 当前对应的路径为CategoryController类下的showCreate方法 String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; 输出: path:/E_WuLiu basePath:http://localhost:8080/E_WuLiu/ getContextPath():得到当前应用的根目录 getScheme()

ListIterator与Iterator迭代关系

匿名 (未验证) 提交于 2019-12-03 00:19:01
直接上代码: ListIterator是List集合中特有的迭代器,但是没有什么太大的用处,原因是,使用ListIterator迭代元素,必须使用while(lt.hasNext()){System.out.println(lt.next()); }迭代后再使用ListIterator。ListIterator是倒序迭代,所以在遍历集合元素时一般不会使用。 但是也有它的作用: 发生ConcurrentModificationException异常时,可以避免此异常发生。具体请看ConcurrentModificationException文章概述。 package list . arraylist ; import java . util . ArrayList ; import java . util . List ; import java . util . ListIterator ; /* * ListIterator listIterator():List集合特有迭代器 * boolean hasPrevious():判断集合中是否含有元素,相当于hasNext(); * E previous():获取元素,并将指针指向下一个元素,相当于next(); */ public class ListIteratorDome { public static void main (

142. Linked List Cycle II(链表)

匿名 (未验证) 提交于 2019-12-03 00:19:01
https://leetcode.com/problems/linked-list-cycle-ii/description/ 题目:如果链表有环,返回环的入口,负责返回NULL. 思路:快慢指针,考虑下面的链表环,其中4->2表示4的下一元素为2。 1 -> 2 -> 3 -> 4 -> 2 。 ft st flag 1 1 0 3 2 0 2 3 0 4 4 1 当flag为 1 时, ft 与st指向同一元素: 4 其中 ft 遍历的路径为: 1 -> 2 -> 3 -> 4 -> 2 -> 3 -> 4 ,路径长度为 6 st 遍历的路径为: 1 -> 2 -> 3 -> 4 路径长度为 3 ft 的路径长度刚好为st的两倍,st回到head,继续 ft st flag 4 1 1 2 2 1 其中 ft 遍历的路径为: 4 -> 2 , 路径长度为 1 st 遍历的路径为: 1 -> 2 路径长度为 1 路径长度相等,再次相遇即为入口地址。 class Solution { public : ListNode * detectCycle(ListNode * head) { ListNode * ft = head, * st = head; bool flag = 0 ; while ( ft && ft -> next){ st = st -> next; ft =

142. Linked List Cycle II(链表)

匿名 (未验证) 提交于 2019-12-03 00:18:01
https://leetcode.com/problems/linked-list-cycle-ii/description/ 题目:如果链表有环,返回环的入口,负责返回NULL. 思路:快慢指针,考虑下面的链表环,其中4->2表示4的下一元素为2。 1 -> 2 -> 3 -> 4 -> 2 。 ft st flag 1 1 0 3 2 0 2 3 0 4 4 1 当flag为 1 时, ft 与st指向同一元素: 4 其中 ft 遍历的路径为: 1 -> 2 -> 3 -> 4 -> 2 -> 3 -> 4 ,路径长度为 6 st 遍历的路径为: 1 -> 2 -> 3 -> 4 路径长度为 3 ft 的路径长度刚好为st的两倍,st回到head,继续 ft st flag 4 1 1 2 2 1 其中 ft 遍历的路径为: 4 -> 2 , 路径长度为 1 st 遍历的路径为: 1 -> 2 路径长度为 1 路径长度相等,再次相遇即为入口地址。 class Solution { public : ListNode * detectCycle(ListNode * head) { ListNode * ft = head, * st = head; bool flag = 0 ; while ( ft && ft -> next){ st = st -> next; ft =

2019-2020 ICPC, NERC, Southern and Volga Russian Regional Contest (Online Mirror, ICPC Rules, Teams Preferred)【A题 类型好题】

匿名 (未验证) 提交于 2019-12-03 00:15:02
A. Berstagram Polycarp recently signed up to a new social network Berstagram. He immediately published n posts there. He assigned numbers from 1 to n to all posts and published them one by one. So, just after publishing Polycarp's news feed contained posts from 1 to n ― the highest post had number 1, the next one had number 2, ..., the lowest post had number n. After that he wrote down all likes from his friends. Likes were coming consecutively from the 1-st one till the m-th one. You are given a sequence a1,a2,…,am (1≤aj≤n), where aj is the post that received the j-th like. News feed in

Codeforces 1221F. Choose a Square

匿名 (未验证) 提交于 2019-12-03 00:09:02
传送门 对于某个点 $(x,y)$ ,不妨设 $x<y$ 因为如果 $x>y$ 直接按 $y=x$ 对称一下即可 当且仅当正方形左下角 $(a,a)$ 满足 $a<=x$,右上角 $(b,b)$ 满足 $b>=y$ ,才能得到这个点的价值 所以发现其实是个二维偏序的问题,直接把 $(a,b)$ 看成另一个平面上的点,$(x,y)$ 放到那个平面上 这样就问题变成选一个点 $(a,b)$ ,你得到的价值为所有 $x>=a$ 并且 $y<=b$ 的点 $(x,y)$ 的价值和再减去 $a,b$ 之间的差值 考虑把点按第一关键字 $x$ 从大到小,按第二关键字 $y$ 从小到大排序,维护一个线段树表示当前 $a=x$ 的情况下 $y$ 取各个值时能够得到的最大价值 因为当前 $a=x$ 的情况下,所有 $x>a$ 的点的代价都加入了,每次加入一个点以后直接查询线段树上 $b>=y$ 和下一个点 $b<=y'-1$ 之间的那一段的最大价值,当然如果下一个点的 $x$ 和当前点不同,那么查询直接查询当前点到线段树最大位置的值即可 发现这样是有问题的,因为对于不同的 $b=y$ ,直接取点的值最大还不行,因为代价还要考虑 $-(y-x)$,所以线段树上维护的应该是点值和再减 $y$ 以后的最大值,当然要随便维护一下取最大值时 $b$ 的值 然后就没了,代码因为主体是比赛时写的,可能比较丑

leetcode 20. Valid Parentheses

匿名 (未验证) 提交于 2019-12-03 00:09:02
Given a string containing just the characters '(' , ')' , '{' , '}' , '[' and ']' , determine if the input string is valid. An input string is valid if: Open brackets must be closed by the same type of brackets. Open brackets must be closed in the correct order. Note that an empty string is also considered valid. Example 1: Input : "()" Output : true Example 2: Input : "()[]{}" Output : true Example 3: Input : "(]" Output : false Example 4: Input : "([)]" Output : false Example 5: Input : "{[]}" Output : true 思路:栈实现 1 class Solution { 2 public : 3 bool isValid ( string s ) { 4 stack <char> st

bzoj 4237 稻草人

匿名 (未验证) 提交于 2019-12-03 00:02:01
bzoj 这个矩形有三个限制,分别是右上角点的横纵坐标分别大于左下角 废话 ,并且中间区域没有点.那么可以先按横坐标排序,然后枚举左边的点和右边的点匹配.为了保证复杂度,这里每次把点集一分为二,先递归处理两边,然后处理两端点分别在左右两边的情况 这里把两边的点分别按纵坐标排序,然后枚举右边的点,每次把左边纵坐标小于右端点的点加进来.然后考虑中间区域没有点的限制,如果左边某个点在某个时刻右上方有点,那么这个点就不能作为端点.左侧可以维护一个从左往右纵坐标单调递减的单调栈.然后考虑右侧其他点对当前右端点的影响,如果有个点在右端点左下方,那么比那个点纵坐标小的左边的点就不能作为左端点.所以如果右边维护一个从左往右纵坐标单调递增的单调栈,那么就可以二分出那个左下的点,推出左端点的纵坐标最小是多少.再在左边单调栈二分出纵坐标最小的满足条件的左端点的位置,那么这个位置到栈顶之间的点都可以作为左端点 #include<bits/stdc++.h> #define LL long long #define uLL unsigned long long #define db double using namespace std; const int N=2e5+10; int rd() { int x=0,w=1;char ch=0; while(ch<'0'||ch>'9'){if(ch=='-'

D2. RGB Substring (hard version) ( Codeforces Round #575 )

匿名 (未验证) 提交于 2019-12-02 23:55:01
The only difference between easy and hard versions is the size of the input. s n R', ' G' or ' B'. k s k s s, and is also a substring of the infinite string " RGBRGBRGB ...". a b i a 1 = b i a 2 = b i + 1 a 3 = b i + 2 a | a | = b i + | a | 1 GBRG", " B", " BR" are substrings of the infinite string " RGBRGBRGB ..." while " GR", " RGR" and " GGG" are not. q Input q 1 ≤ q ≤ 2 10 5 q n k 1 ≤ k ≤ n ≤ 2 10 5 s s n R', ' G' and ' B'. n 2 10 5 ∑ n ≤ 2 10 5 Output s k s RGBRGBRGB ...". #include<bits/stdc++.h> using namespace std; const int maxn = 2e5+7; int n,k; string ori = "RGB"; string s; int a

插头DP总结

匿名 (未验证) 提交于 2019-12-02 23:52:01
   struct hashmap { long long val [ mod ]; int fr [ mod ], tt ; node s [ mod ]; void clear () { memset ( val , 0 , sizeof ( val )); memset ( s , 0 , sizeof ( s )); tt = 0 ; memset ( fr , 0 , sizeof ( fr )); } long long & operator []( const int st ) { int i ; for ( i = fr [ st % mod ]; i && s [ i ]. st != st ; i = s [ i ]. pr ); if (! i ) { s [++ tt ]. st = st ; s [ tt ]. pr = fr [ st % mod ]; fr [ st % mod ]= tt ; i = tt ; } return val [ i ]; } } f [ 2 ]; 转载请标明出处: 插头DP总结 文章来源: 插头DP总结