• <div><p>Code like this is more a case of showing off one's C++ knowledge, rather than using it adequately, IMHO. <p><strong>First loop (std::generate)</strong></p> <p>Iterators are ...
• I noticed that the cryptwindow targets only files in the designated folder and I was wondering how you would go about changing that to cascade down any sub directories recursively in a more ...
• 以下消息来自幻影论坛[Ph4nt0m]邮件组 Since the early days of ASP.NET there has been a heavy reliance on the request validation performed to mitigate cross-site scripting issues as many of the ...

以下消息来自幻影论坛[Ph4nt0m]邮件组

Since the early days of ASP.NET there has been a heavy reliance on the request validation performed to mitigate cross-site scripting issues as many of the WebControls do not perform any encoding.  In ASP.NET v1.1 the request validation performed was fairly restrictive.  It looked for tags, expressions, on strings (onClick, etc), javascript:, and "&#".  After reviewing an ASP.NET 2.0 site I found these protections have been simplified to just look for tags and "&#".<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
This has a number of interesting security impacts as any 1.1 site which relies on these protections as mitigation’s to security issues will find themselves vulnerable once they upgrade.  It would be interesting to know Microsoft’s reasons for removing these checks.  I would assume it caused to many customer issues, perhaps interfered with <?xml:namespace prefix = st1 ns = "urn:schemas-microsoft-com:office:smarttags" />AJAX in some way.
To recap, asp.net v1.1 performed the following checks:
Look for "&#"
Look for ‘<’ then alphas or ! or / (tags)
Look for "script:"
Look for on handlers (onXXX=)
Look for “expression(“
Skip elements named "__VIEWSTATE" While asp.net v2.0 and higher performs the following:
Look for &#
Look for ‘<’ then alphas or ! or / (tags)
Skip elements with names prefixed with double underscore (__) As you can see the 2.0 version is much weaker than 1.1.
Enjoy!

转载于:https://blog.51cto.com/netwalk/73431
展开全文
• (Sure, it seems pointless to set something up only to knock it down again, but you have some strange hobbies) The tricky thing about setting dominos, however, is that if you make a mistake and knock ...
• i have my dotfiles hosted in a github repo (jayceekay/dotfiles) and i simply want to start by just pulling those down and installing them on my local. i thought this would be a use case for this tool...
• Description You are trying to set up a straight line of dominos, standing on end, to be pushed over later for your entertainment. (Sure, it seems pointless to set something up only to knock it down

Description

You are trying to set up a straight line of dominos, standing on end, to be pushed over later for your entertainment. (Sure, it seems pointless to set something up only to knock it down again, but you have some strange hobbies)
The tricky thing about setting dominos, however, is that if you make a mistake and knock one over as you place it, it will knock down any adjacent line of consecutive dominos on one side of it, partially ruining your work.

For instance, if you've already placed dominos in the pattern
DD__DxDDD_D, and you try placing a domino at position x, there is a chance it will fall and knock over the domino to the left or the three dominos to its right, forcing you to place them again.

This human error is somewhat unavoidable, but you can make the odds somewhat more favourable by using a domino-placing technique that leads to dominos falling in one direction more often than in the other.

Given the number of dominos you are trying to set up, and the probability that you'll knock over any individual domino either to the left or to the right while placing it, determine the average number of dominos you'll need to place before you finish. Assume
that you're using an optimal placement strategy.

Input

Input will consist of up to 100 cases. Each case consists of one line of input. It will contain the number of dominos to place, n, 1 <= n <= 1000, followed by nonnegative values Pl and Pr, indicating the probability of any domino
falling to the left or to the right when placed. You may assume 0 < Pl + Pr <= 0.5.

The last test case is followed by a line containing a single 0.

Output

For each case, output the expected number of dominos that will need to be placed before you finish, accurate to two digits after the decimal.

Sample Input

10 0.25 0.25
10 0.1 0.4
10 0.0 0.5
0

Sample Output

46.25
37.28
20.00

Source

Waterloo local 2003.07.05

解题思路： 概率DP，首先设dp[i]表示长度为i的多米诺骨牌摆放次数的期望，然后我们枚举最后一个牌的放置位置，这个牌有pl的概率向左，pr的概率向右,1-pl-pr的概率不偏。
则我们摆放最后一颗牌时最少需要1/(1-pl-pr)次才能放正。加入向左偏，则左边的牌需要重新摆放，向右偏，右边的牌需要重新摆放，因此我们不难得出状态转移方程为:
dp[i] = (dp[l]+1)*pl/(1-pl-pr) + (dp[r]+1)*pr/(1-pl-pr) +(1-pl-pr)*(dp[l]+dp[r]+1)/(1-pl-pr)，化简后最终得dp[i]=(1-pr)*dp[l]/(1-pl-pr)+(1-pl)*dp[r]/(1-pl-pr)+1/(1-pl-pr)。很显然复杂度为O(n^2)。
优化方案：

可以根据动态规划时候，dp[i]这个数组在找寻最小值的时候，其实方程是满足一个下凹函数的，所以这步实际上可以利用三分求解，复杂度为O(nlog(n))，然后实际上，对于下凹函数，那么其实对于下次找最小值的位置，是不会减小的，因此如果每次维护记录下上次找到答案的位置，这样均摊下来，时间复杂度就能优化到O(n)
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
const int maxn = 1010;
double dp[maxn];
int n;
double pl, pr;

double cal(int l, int r) {
return  (1-pr)/(1-pl-pr)*dp[l] + (1-pl)/(1-pr-pl)*dp[r] + 1/(1-pl-pr);
}

int main() {

//freopen("aa.in", "r", stdin);

while(scanf("%d", &n) && n) {
scanf("%lf %lf", &pl, &pr);
dp[0] = 0;
dp[1] = 1.0 / (1 - pl - pr);
/*
for(int i = 2; i <= n; ++i) {
dp[i] = cal(0, i - 1);
for(int j = 1; j < i; ++j) {
dp[i] = min(dp[i], cal(j, i - j - 1));
}
}
*/
// 优化后的状态转移方程

int lp = 0;  // 记录上次找到最优值的位置
for(int i = 2; i <= n; ++i) {
dp[i] = cal(lp, i - lp - 1);
for(int j = lp + 1; j < i; ++j) {
double t = cal(j, i - j - 1);
if(dp[i] >= t) {
dp[i] = t;
lp = j;
} else {
break;
}
}
}

printf("%.2lf\n", dp[n]);
}
return 0;
}



展开全文
• <p>My concern is that if I get down below 5%, I might have a situation where the rpi wakes up and is immediately shut down in the middle of boot up, risking corruption. <p>However, if the wake-on-...
• 题目描述 You are trying to set up a straight line of dominos, standing on end, to be pushed over later for your ... (Sure, it seems pointless to set something up only to knock it down aga...

题目描述
You are trying to set up a straight line of dominos, standing on end, to be pushed over later for your entertainment. (Sure, it seems pointless to set something up only to knock it down again, but you have some strange hobbies) The tricky thing about setting dominos, however, is that if you make a mistake and knock one over as you place it, it will knock down any adjacent line of consecutive dominos on one side of it, partially ruining your work. For instance, if you've already placed dominos in the pattern DD__DxDDD_D, and you try placing a domino at position x, there is a chance it will fall and knock over the domino to the left or the three dominos to its right, forcing you to place them again. This human error is somewhat unavoidable, but you can make the odds somewhat more favourable by using a domino-placing technique that leads to dominos falling in one direction more often than in the other. Given the number of dominos you are trying to set up, and the probability that you'll knock over any individual domino either to the left or to the right while placing it, determine the average number of dominos you'll need to place before you finish. Assume that you're using an optimal placement strategy.
输入
Input will consist of up to 100 cases. Each case consists of one line of input. It will contain the number of dominos to place, n, 1 <= n <= 1000, followed by nonnegative values Pl and Pr, indicating the probability of any domino falling to the left or to the right when placed. You may assume 0 < Pl + Pr <= 0.5. The last test case is followed by a line containing a single 0.
输出
For each case, output the expected number of dominos that will need to be placed before you finish, accurate to two digits after the decimal.

题意:你试图把一些多米诺骨牌排成直线，然后推倒它们。但是如果你在放骨牌的时候不小心把刚放的骨牌碰倒了，它就会把相临的一串骨牌全都碰倒，而你的工作也被部分的破坏了。 比如你已经把骨牌摆成了DD__DxDDD_D的形状，而想要在x这个位置再放一块骨牌。它可能会把左边的一块骨牌或右边的三块骨牌碰倒，而你将不得不重新摆放这些骨牌。 这种失误是无法避免的，但是你可以应用一种特殊的放骨牌方法来使骨牌更多的向一个方向倒下。 给出你要摆放的骨牌数目，以及放骨牌时它向左和向右倒的概率，计算你为完成任务摆放的骨牌数目的平均数。假设你使用了最佳的摆放策略。 输入将包含至多100个测试点，每个测试点占一行，包含需要摆放的骨牌数目n (1≤n≤1000)，以及两个非负实数Pl, Pr，表示骨牌向左和向右倒的概率。保证1＜Pl+Pr≤0.5。 最后一个测试点包含一个数0。对于每个测试点输出题目要求的数目，保留两位小数。

思路:我们想成功的放置1块骨牌所需要的次数的期望是多少呢? 1/(1-pl-pr) 也就是说我们平均每放1/(1-pl-pr)个能成功一个
dp[i]表示成功放置长度为i的骨牌所需要次数的期望

用dp的思想我们之前已经得到dp[1]~dp[n-1]
我们假设长度为n的骨牌最后一块放置在i位置上
那么dp[n]=min(E[i]+dp[i-1]+dp[n-i]) 1<=i<=n就是枚举最后放的i位置 其中E[i]表示第i块能放成功的期望
现在我们处理E[i],也就是说在i位置放置成功我们平均需要几次呢?
1.直接放成功 这样我只要成功1次
2.放下之后向左倒了,首先发生这件事的概率是pl,之前成功放置i-1块的期望是dp[i-1]次,我们把dp[i-1]毁掉的概率是pl,对于向左倒,我们毁掉的块数的期望是dp[i-1]*pl
3.放下之后向右边倒,同理我们这时毁掉的块数的期望是pr*dp[n-i]
我们在i位置放置成功所需次数的期望是1+pl*dp[i-1]+pr*dp[n-i]
那么成功这么多次,我们又需要放几次呢? 注意到我们平均每放1/(1-pl-pr)个能成功一个
那么显然是(1+pl*dp[i-1]+pr*dp[n-i])/(1-pl-pr)次啊
这个地方比较绕...我们可以反向考虑
假如dp[i-1]=10,pl=0.4,那么我们放置i的时候如果向左倒,我们平均的就要多放置4个
dp[n-i]=20,pr=0.1那么我们放置i的时候如果向右倒,我们平均的就要多放置2个
也就是说我们先成功放置4个这样他就不会向左倒,再成功放置2个他就不会向右倒,我们此时再放置一个他就一定不会倒
这样我们需要成功放置4+2+1=7次,每次成功都需要1/(1-pl-pr)次放置
那么期望E[i]显然是(1+pl*dp[i-1]+pr*dp[n-i])/(1-pl-pr)
然后就n^2出答案了,网上有优化成O(n)的...

1 #include <bits/stdc++.h>
2
3 using namespace std;
4 const int maxn = 1100;
5 int n;
6 double l,r;
7 double dp[maxn];
8 double calc (int n,int x)
9 {
10     return (1.0+l*dp[x-1]+r*dp[n-x])/(1-l-r)+dp[x-1]+dp[n-x];
11 }
12 int main()
13 {
14     //freopen("de.txt","r",stdin);
15     while (~scanf("%d",&n)){
16         if (n==0) break;
17         scanf("%lf%lf",&l,&r);
18         dp[0]=0;
19         dp[1]=1.0/(1-r-l);
20         for (int i=2;i<=n;++i){
21             dp[i]=calc(i,i);
22             for (int j=1;j<=i;++j)
23                 dp[i]=min(dp[i],calc(i,j));
24         }
25         printf("%.2f\n",dp[n]);
26     }
27     return 0;
28 }

优化成O(n)

1 #include<iostream>
2 #include<cstdio>
3 using namespace std;
4 double f[100005];
5 double pl,pr,ans;
6 int n;
7 inline double cal(int n,int i){
8     return (pl*f[i-1]+pr*f[n-i]+1)/(1.0-pl-pr)+f[i-1]+f[n-i];//计算期望
9 }
10 int main(){
11     cin>>n;
12     int i,j,x=1;
13     cin>>pl>>pr;
14     f[0]=0;f[1]=1.0/(1.0-pl-pr);//初始化，0张牌期望为0，一张牌期望为既不左倒也不右倒的概率
15     for(i=2;i<=n;i++){
16         f[i]=cal(i,x);
17         while(x<i&&cal(i,x+1)<f[i]){f[i]=cal(i,x+1);x++;}//更优的决策点一定在上一次决策点之后
18     }
19     printf("%.2lf",f[n]);//保留两位
20     return 0;
21 }

转载于:https://www.cnblogs.com/agenthtb/p/7487788.html
展开全文
• (Interwoven: jumping around between GitHub issues and StackOverflow)</li><li>Tear down cluster. Repeat.</li></ul> <p>I have read the README and subsection on AWS, looked at many issues, and cannot ...
• <p>Specifically, if I comment out the line: G1 X240.076 Y107.988 E1709.90273 it carries on as normal, but with that line enabled, it shuts down the driver every time. I've confirmed it's not ...
• app, this took startup <strong>from 5.5 seconds to load app.js down to ~400-500ms</strong> for me. For reference, Android takes roughly ~217ms. <p>The general theme here is to: - Make use of an index...
• <p>as a user, i want status updates input form autocompletes to be keyed up and down with my keyboard, so i dont have to use my dumb mouse. <h3>Why Is this Needed <p><em>Summary</em>: <h3>Description ...
• vb.net 切换应用程序Well, my Hanselman.com email (as well as for all my Hanselman relatives) has been down with DNS and dumb problems since Friday, so it's official. I'm switching. I'm switching to ...
vb.net 切换应用程序Well, my Hanselman.com email (as well as for all my Hanselman relatives) has been down with DNS and dumb problems since Friday, so it's official.  I'm switching.  I'm switching to ORCSWeb.  I'll move all my domains there, including www.hanselman.com, www.diabeticbooks.com, www.glucopilot.com and www.computerzen.com.  Expect some weird DNS and silliness over the next few days, possibly this week.  I'm a huge believer in the permalink, so if I do it right, everything will work as before.
好吧，自上周五以来，我的Hanselman.com电子邮件(以及我所有的Hanselman亲戚)一直都存在DNS和愚蠢的问题，因此是正式的。 我要切换。 我正在切换到ORCSWeb 。 我将把我所有的域名都移到那里，包括www.hanselman.com ， www.diabeticbooks.com ， www.glucopilot.com和www.computerzen.com 。 预计未来几天(可能是本周)会出现一些奇怪的DNS和愚蠢行为。 我是永久链接的忠实拥护者，因此，如果我做对了，一切都会照常进行。
After the dust has settled, I'll likely move from Radio to DasBlog.

尘埃落定之后，我可能会从Radio转到DasBlog 。翻译自: https://www.hanselman.com/blog/switching-all-providersvb.net 切换应用程序
展开全文
• textedit设置水印Compared to Notepad, TextEdit is far more fully-... We have to deliberately “dumb it down” in order to work to our purposes. First, run TextEdit. You can find it under System / Appli...
• <div><p>Can someone dumb this down for me? I drag setup.py into the git and....? Nothing happens</p><p>该提问来源于开源项目：RicterZ/nhentai</p></div>
• <div><p>Dumb it down. Moonboots shouldn't add routes or anything, just generate files and filenames. Also a CLI util to go with it would be cool.</p><p>该提问来源于开源项目：HenrikJoreteg/...
• 1.Slow down. The more you understand, the less you have to memorize.  2.Do the exercises. Write your own notes.  3.Read the “There are No Dumb Questions.”  4.Make this the last thing you...
• <div><p>Might be a dumb thing to ask, but since "hourly" build is ever evolving and gets new version, isn't it would be nice to have pinned thread with new features written down in it?</p>...
• <div><p>The readme is a little unclear.... Is there anyway someone can dumb it down for a begginer like myself?</p><p>该提问来源于开源项目：Wizcorp/phonegap-facebook-plugin</p></div>
• m a visual leaner and I need someone to dumb it down for me. This is too complicated for me and i just need someone to send me a link on a video on how to do this. I just want to play The Arrival on ...
• <div><p>This began as a stab at #259, but...t want to dumb it down or remove content; I want to explain concepts more exactly. <p>:eggplant: </p><p>该提问来源于开源项目：railsbridge/docs</p></div>
• <div><p>Every time I had a dumb or possibly-not-dumb-but-definitely-crazy idea for a font, I reach for TTX with a small font file and then strip down the converted XML to then start hacking on the ...

...