aga

【PAT甲级】1086 Tree Traversals Again (25 分)(树知二求一)

六月ゝ 毕业季﹏ 提交于 2019-12-04 19:19:22
题意: 输入一个正整数N(<=30),接着输入2*N行表示栈的出入(入栈顺序表示了二叉搜索树的先序序列,出栈顺序表示了二叉搜索树的中序序列),输出后序序列。 代码: #define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> using namespace std; stack<int>st; int a[37],b[37]; int ans[37]; void build(int n,int*a,int*b,int*ans){ if(!n) return ; int x=find(b,b+n,a[0])-b; build(x,a+1,b,ans); build(n-x-1,a+x+1,b+x+1,ans+x); ans[n-1]=a[0]; } int main(){ ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n; cin>>n; int cnt1=0,cnt2=0; for(int i=1;i<=n+n;++i){ string s; cin>>s; int x; if(s[1]=='u') cin>>x; if(s[1]=='u'){ a[cnt1++]=x; st.push(x); } else{ b[cnt2++]=st.top(); st

Rails greater_than model validation against model attribute

匿名 (未验证) 提交于 2019-12-03 02:56:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I've got a Trip model, which among other attributes has a start_odometer and end_odometer value. In my model, i'd like to validate that the end odometer is larger than the starting odometer. The end odometer can also be blank because the trip may not have finished yet. However, I can't figure out how to compare one attribute to another. In trip.rb: comparing against the symbol: validates_numericality_of :end_odometer, :greater_than => :start_odometer, :allow_blank => true gives me the error: ArgumentError in TripsController#index :greater

Unlink of file Failed. Should I try again?

匿名 (未验证) 提交于 2019-12-03 02:12:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Something wrong is going on with one of the files in my local git repository. When I'm trying to change the branch it says: Unlink of file 'templates/media/container.html' failed. Should I try again? (y/n) What could that mean? 回答1: This could mean that another program is using the file, which is preventing git from "moving" the file into or out of the working directory when you are attempting to change branches. I have had this happen on Windows Vista where eclipse is the program "using" the file. The file may not be actually open in

Converting String to Date (and back again) iOS

匿名 (未验证) 提交于 2019-12-03 01:49:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: How would I convert an NSString like " 01/02/10 " (meaning 1st February 2010) into an NSDate ? And how could I turn the NSDate back into a string? 回答1: Swift 4 and later Updated: 16th November 2017 String to Date var dateString = "02-03-2017" var dateFormatter = DateFormatter() // This is important - we set our input date format to match our input string // if the format doesn't match you'll get nil from your string, so be careful dateFormatter.dateFormat = "dd-MM-yyyy" //`date(from:)` returns an optional so make sure you unwrap when using.

@codeforces - 1205E@ Expected Value Again

北慕城南 提交于 2019-11-28 08:25:56
目录 @description@ @solution@ @part - 1@ @part - 2@ @part - 3@ @solution@ @details@ @description@ 给定两个数 n, k,令 s 是一个字符集大小为 k 的随机字符串。 定义 f(s) 表示满足 s 长度为 i 的前缀 = s 长度为 i 的后缀的 i 的数量,要求 1 ≤ i < |s|。 求 f(s)^2 的期望。 Input 只有一行,包含两个整数 n, k(1≤n≤10^5, 1≤k≤10^9),含义如上。 Output 输出期望 mod 10^9 + 7。 Examples Input 2 3 Output 333333336 Input 1 5 Output 0 Input 100 1 Output 9801 Input 10 10 Output 412377396 @solution@ @part - 1@ 其实题目所说的前后缀相等,就是 border 的数量。 因为长度为 k 的 border 等价于长度为 n - k 的周期,为了方便下面的讨论,我们不妨去计算周期的数量。 考虑令随机变量 \(g_i(s)\) ,当 s 含有长度为 i 的周期时为 1,否则为 0。 则可以得到 \(f(s) = \sum_{i=1}^{n-1}g_i(s)\) ,即考虑每种长度的周期的贡献。