st

祖玛(Zuma)

你。 提交于 2019-11-30 00:47:00
祖玛(Zuma) Description Let's play the game Zuma! There are a sequence of beads on a track at the right beginning. All the beads are colored but no three adjacent ones are allowed to be with a same color. You can then insert beads one by one into the sequence. Once three (or more) beads with a same color become adjacent due to an insertion, they will vanish immediately. Note that it is possible for such a case to happen for more than once for a single insertion. You can't insert the next bead until all the eliminations have been done. Given both the initial sequence and the insertion series, you

HDU 2680

谁说胖子不能爱 提交于 2019-11-29 22:02:57
HDU - 2680 SPFA + 反向建图 #include <iostream> #include <cstring> #include <algorithm> #include <queue> using namespace std; const int N = 1e3 + 10,M = 4e4 + 10,INF = 0x3f3f3f3f; int e[M],ne[M],h[N],w[M],idx,dist[N],n,m,s; bool st[N]; void add(int a,int b,int c){ e[idx] = b; w[idx] = c; ne[idx] = h[a]; h[a] = idx ++; } void spfa(){ queue<int> q; q.push(s); dist[s] = 0; st[s] = 1; while(q.size()){ int t = q.front(); q.pop(); st[t] = 0; for(int j = h[t];j != -1;j = ne[j]){ int x = e[j]; if(dist[x] > dist[t] + w[j]){ dist[x] = dist[t] + w[j]; if(!st[x]){ q.push(x); st[x] = 1; } } } } } int main(){

Python--基础--字符串(string)

元气小坏坏 提交于 2019-11-29 15:08:35
字符串 创建字符串: a = "jia'jia'" 重复输出 print('hello'*10) 通过 2 [ ] , [ : ] 索引获取字符串中字符,这里和列表的切片相同 print('helloword'[2;]) 通过关键字“in”判断某一个字是否在字符串中 print('wo_guo_de_heng_hao' in [wo,guo,hen]) print(123456 in 89) 格式化字符 print('XiaoMin is a good teacher') print('%s is good teacher'%'xXiaoMin') 字符串拼接 #例1 a = 123 b = 'abc' c = a + b print(c) #例2 a = 123 b = 'abc' c = ''.join(a,b) # ''符号中加什么符号 就会将符号 加到拼接的字符中间 例添符号为 +++ 效果如 123+++abc print(c) 字符串的内置方法 st = 'helle kitty' print(st.count('l')) # 统计“l”的个数 print(st.capitalize()) # 将首字母大写 print(st.center(25,'-')) # 居中 50为字符串的长度 字符两边用‘-’补充 例:--------hello Kitty-------

Python基础(六)

别来无恙 提交于 2019-11-29 13:35:21
今日主要内容 驻留机制 小数据池 代码块 深浅拷贝 集合 一、 驻留机制 (一)== 和 is == :判断两边的内容是否相同 a = -6 b = -6 print(a == b) # True is :判断两边的内存地址是否相同 a = -6 b = -6 print(a is b) # Fales (二)什么是驻留机制 python中为了节省内存定义的一套规则,部分数据在重复定义的时候指向同一个内存空间,也就是内存地址是相同的 在驻留机制范围内的代码块和小数据池,在定义变量的时候都将履行驻留机制 代码块的优先级高于小数据池 (三)什么是代码块 一个py文件、一个函数、一个模块、一个类、终端中的每一行代码都是一个代码块 (四)小数据池和代码块的驻留范围 小数据池 数字: -5 ~ 256 字符串: 只包含数字、字母、下划线的全部字符串 在python3.6解释器中字符串使用乘的时候总长度不能超过20(只包含数字、字母、下划线) 在python3.7解释器中字符串使用乘的时候总长度不能超过4096(只包含数字、字母、下划线) 布尔值 True False 代码块 数字: -5 ~ 正无穷 字符串: 全部字符串(包含数字、字母、下划线、特殊字符、中文等) 使用乘的时候总长度不能超过20(只包含数字、字母、下划线) 布尔值 True False (五)指定驻留 指定任意字符串

We don't wanna work!

﹥>﹥吖頭↗ 提交于 2019-11-29 13:21:01
We don't wanna work! [JAG Asia 2016] 两个set,一个代表工作的,一个代表不工作的 其实是一个很简单的模拟,但是我竟然排序之前标号。。。。 检查代码的时候要从头开始检查。。 #include <bits/stdc++.h> using namespace std; const int maxn = 1e5+7; struct node { char s[25]; int ti,fen; bool operator<(const node&r)const { if(fen==r.fen) { return ti>r.ti; } return fen>r.fen; } } s[maxn],tmp; set<node>st,stt; set<node>::iterator it; map<string,int>mp; char str[25]; char op[5]; int p; void solve() { if(st.size()>p) { it=st.end(); --it; tmp=*it; cout<<tmp.s<<" is not working now."<<endl; st.erase(tmp); stt.insert(tmp); } else if(st.size()<p) { it=stt.begin(); tmp=*it;

java集合List的遍历方式

耗尽温柔 提交于 2019-11-29 10:32:29
  循序渐进学习java 集合的遍历方式:   一、先以list集合为例:   package com.test; import java.util.ArrayList; import java.util.Iterator; import java.util.List; public class testing { public static void main(String[] args) { // TODO Auto-generated method stub List<String> list=new ArrayList<String>(); list.add("a"); list.add("b"); list.add("c"); list.add("d"); list.add("e"); //方法一:(迭代器(1)) for(Iterator<String> iterator=list.iterator();iterator.hasNext();){ String st=iterator.next(); System.out.println("遍历方法一的list的输出的String 是"+st); } //方法二:for循环(1) for(int i=0;i<list.size();i++){ String st=list.get(i); System.out

leetcode907 Sum of Subarray Minimums

时光总嘲笑我的痴心妄想 提交于 2019-11-29 08:24:06
思路: 对于每个数字A[i],使用单调栈找到A[i]作为最小值的所有区间数量,相乘并累加结果。时间复杂度O(n)。 实现: 1 class Solution 2 { 3 public: 4 int sumSubarrayMins(vector<int>& A) 5 { 6 int res = 0; 7 stack<int> st; 8 int n = A.size(); 9 const int MOD = 1e9 + 7; 10 for (int i = 0; i < n; i++) 11 { 12 while (!st.empty() && A[i] < A[st.top()]) 13 { 14 int tmp = st.top(); st.pop(); 15 int last = st.empty() ? -1 : st.top(); 16 res = (res + (i - tmp) * (tmp - last) % MOD * A[tmp] % MOD) % MOD; 17 } 18 st.push(i); 19 } 20 while (!st.empty()) 21 { 22 int tmp = st.top(); st.pop(); 23 int last = st.empty() ? -1 : st.top(); 24 res = (res + (n - tmp) *

CodeForces 280B Maximum Xor Secondary 单调栈

血红的双手。 提交于 2019-11-29 07:26:55
这道题思路真的不好想呀。。看了Leaderboard,发现大佬们的代码如此简练Orz 怎么想出来的我就不晓得了,模拟一下他们的过程加深理解吧。。以样例中的5 2 1 4 3为例: stack:5 a[i]:2 ans=5^2 stack:5 2 a[i]:1 1<2, ans=1^2(对应序列[2,1]的最大次大值,[5,2,1]相当于[5,2],因此此时2不出栈,构成 单调递减栈 ) stack:5 2 1 a[i]:4 4>1, ans=4^1( [1,4] ), 1出栈;4>2, ans=4^2( [2,1,4] ), 2出栈;4<5, ans=4^5( [5,2,1,4] ) stack:5 4 a[i]:3 3<4, ans=3^4( [4,3] ) 这样模拟之后就会发现把所有可能的情况都算了一遍,从中挑选最大值。附上AC代码: #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #include<stack> using namespace std; const int INF=0x3f3f3f3f; const int MAX=1e5+5; int n,a[MAX]; stack<int>st; int main() { while(scanf("%d",&n)==1) {

Codeforces Round #583 (Div.1+Div.2)

 ̄綄美尐妖づ 提交于 2019-11-29 07:01:06
不太友好的一场。 题目链接: https://codeforces.com/contest/1214 A: 想了很久优美做法,发现还不如直接一发暴力正确。 1 /* basic header */ 2 #include <bits/stdc++.h> 3 /* define */ 4 #define ll long long 5 #define dou double 6 #define pb emplace_back 7 #define mp make_pair 8 #define sot(a,b) sort(a+1,a+1+b) 9 #define rep1(i,a,b) for(int i=a;i<=b;++i) 10 #define rep0(i,a,b) for(int i=a;i<b;++i) 11 #define eps 1e-8 12 #define int_inf 0x3f3f3f3f 13 #define ll_inf 0x7f7f7f7f7f7f7f7f 14 #define lson (curpos<<1) 15 #define rson (curpos<<1|1) 16 /* namespace */ 17 using namespace std; 18 /* header end */ 19 20 int n, d, e; 21 22 int main()

CCF-买菜

陌路散爱 提交于 2019-11-29 06:26:32
分析:将各自时间段分多钟情况匹配即可 #include<iostream> #include<cstdio> #include<algorithm> using namespace std; struct Time { int st; int ed; }; bool sort1(Time x, Time y) { return x.st<y.st; } int main() { int n; Time TH[5000]; Time TW[5000]; cin>>n; for(int i = 0; i < n; i++)cin>>TH[i].st>>TH[i].ed; for(int i = 0; i < n; i++)cin>>TW[i].st>>TW[i].ed; sort(TH,TH+n,sort1); sort(TW,TW+n,sort1); ///以H为基础审核W时间段 int indexh = 0; int indexw = 0; int ans = 0; while(indexh<n&&indexw<n) { /// [W] [H] if(TH[indexh].st>=TW[indexw].ed) { indexw++; continue; } /// [H] [W] if(TH[indexh].ed<=TW[indexw].st) { indexh++;