学习,分享,总结
wq611403 · 共 34 篇文章
IE下substr()函数截取末尾字符时的问题
var str = "abc"; alert(str.substr(-1, 1)); 这段代码在IE和Chrome下的结果是不同的,希望得到的是c,Chrome下表现正常;但跑到IE下,显示abc,不是期望的结果。看来IE在处理substr()第一个参数为负数的情况处理方式不一样。 改用substring()函数代替substr() var str = "abc"; var len = str.length; alert(str.substring(len - 1, len)); 参考文章: Using Slice(), Substring(), And Substr() In Javasc…
2014-09-07T09:46:30Z · Web前端 · 评论(0)
ACM 2050 折线分割平面
分析: 主要看新加折线后 新加的折线被分成的线段多少,可以得出 F(N) = F(N-1) + 4(N-1) +1 代码如下: #include <stdio.h> int main() { int n,i,c; double a[10001]; a[0]=1; a[1]=2; for (i=2; i<10001; i++) { a[i]=a[i-1]+4*i-3; } scanf("%d",&c); while (c--) { scanf("%d",&n); printf("%.0f\n",a[n]); } return 0; }
2012-11-27T13:33:50Z · 编程语言 · 评论(0)
ACM 2190 重建希望小学
分析过程: 考虑第N格,如果N-1排好了,第N只有3个1X1一种排法,如果N-2排好了,有3种排法,有1种在N-1的情况包括了, 所以F(N) = F(N-1) + 2F(N-2) 代码如下: #include <stdio.h> int main() { int n,i,c; double a[31]; a[0]=1; a[1]=1; a[2]=3; for (i=3; i<=30; i++) { a[i]=a[i-1]+2*a[i-2]; } scanf("%d",&c); while (c--) { scanf("%d",&n); printf("%.0f\n",a[n]); } re…
2012-11-27T13:33:40Z · 编程语言 · 评论(0)
ACM 2501 Tiling_easy version
递推之后得出: F(N)=F(N-1)+2*F(N-2) 代码如下: #include <stdio.h> int main() { int i,N,T; double a[31]; a[0]=1; a[1]=1; a[2]=3; for (i=3; i<=30; i++) { a[i]=a[i-1]+2*a[i-2]; } scanf("%d",&T); while (T--) { scanf("%d",&N); printf("%.0f\n",a[N]); } return 0; }
2012-11-27T13:33:26Z · 编程语言 · 评论(0)
ACM 2563 统计问题
分析: A(N)表示第N步向上走的,B(N)表示第N步向左右走的 F(N) = A(N)+B(N) A(N) = A(N-1)+B(N-1) B(N) = 2*A(N-1) + B(N-1) =>F(N) = 3*A(N-1) + 2*B(N-2) = 2*F(N-1) + A(N-1) = 2*F(N-1) + A(N-2) + B(N-2) = 2*F(N-1) + F(N-2) #include <stdio.h> int main() { int i,N,T; double a[21]; a[0]=1; a[1]=3; a[2]=7; for (i=3; i<=20; i++) { …
2012-11-27T13:33:14Z · 编程语言 · 评论(0)
ACM 2018 母牛的故事
分析: 年 母牛 1年大的牛 2年大的牛 3年大的牛 第一年 1 0 0 0 第二年 1 1 0 0 第三年 1 1 1 0 第四年 1 1 1 1 第五年之后是 有一头小牛变成母牛后就相当与第二年的情况了 所以可以推出F(N) = F(N-1) + F(N-3) 代码如下: #include <stdio.h> int main() { int n,i; double a[61]; a[0]=1; a[1]=1; a[2]=2; a[3]=3; for (i=4; i<=60; i++) { a[i]=a[i-1]+a[i-3]; } while (scanf("%d",&n)&&(n!=…
2012-11-27T13:32:57Z · 编程语言 · 评论(0)
ACM 2046 骨牌铺方格
http://acm.hdu.edu.cn/showproblem.php?pid=2046 分析第N位,有两种形式1.竖着(F(N-1)),2横着(F(N-2) 所以F(N) = F(N-1) + F(N-2) N<=50 这里应该用double 代码如下: #include <stdio.h> int main() { int n,i; double a[60]; a[0]=1; a[1]=1; a[2]=2; for (i=3; i<54; i++) { a[i]=a[i-1]+a[i-2]; } while (scanf("%d",&n)!=EOF) { printf("%.0f\n…
2012-11-26T20:18:34Z · 编程语言 · 评论(0)
ACM 2045 不容易系列之(3)—— LELE的RPG难题
http://acm.hdu.edu.cn/showproblem.php?pid=2045 分析过程: 1)如果前F(N-1)是符合要求的涂发,即N-1和第一位是不同的,则N位只有一种颜色可以用 F(N-1) 2)如果前N-1是不符合要求的 即N-1和第一位相同,则除掉N-1后之前N-2个是符合要求的,这种情况下有N可以有两种涂发 所以 2*F(N-2) 发现 F(N) = F(N-1) + 2*F(N-2) 因为N<=50 用long类型不行,溢出了,应该用double 代码如下: #include <stdio.h> int main() { int n,i; double a[100…
2012-11-26T20:13:24Z · 编程语言 · 评论(0)
ACM 2044 一只小蜜蜂
http://acm.hdu.edu.cn/showproblem.php?pid=2044 分析: 从a到b的可能路线等价于1到b-a的可能路线。 1到N蜂房的路径算法公式是: F(N) = F(N-1)+F(N-2) F(1)=1 F(2)=1 F(3)=2 注意:c中int long float double的表示范围 代码如下: #include <stdio.h> int main() { int n,A,B,i; double a[50]; a[0]=1; a[1]=1; for (i=2; i<50; i++) { a[i]=a[i-1]+a[i-2]; } scanf("%d…
2012-11-26T12:50:56Z · 编程语言 · 评论(0)
ACM 2041 超级楼梯
http://acm.hdu.edu.cn/showproblem.php?pid=2041 分析: 在第N级阶梯,可能是N-1级一步跨到N级或者N-2级跨两布到N,所以 F(N) = F(N-1)+F(N-2); 注意1<=M<=40 所以超出了int的存储范围,可以用long int 用数组存储代替递归实现 代码如下: #include <stdio.h> int main() { int n,m,i; long int a[41]; a[0]=1; a[1]=1; a[2]=1; for (i=3; i<41; i++) { a[i]=a[i-1]+a[i-2]; } scanf("%…
2012-11-26T12:21:42Z · 编程语言 · 评论(0)
ACM 1297 Children’s Queue
http://acm.hdu.edu.cn/showproblem.php?pid=1297 分析过程: 设:F(n)表示n个人的合法队列,则: 按照最后一个人的性别分析,他要么是男,要么是女,所以可以分两大类讨论: 1、如果n个人的合法队列的最后一个人是男,则对前面n-1个人的队列没有任何限制,他只要站在最后即可,所以,这种情况一共有F(n-1); 2、如果n个人的合法队列的最后一个人是女,则要求队列的第n-1个人务必也是女生,这就是说,限定了最后两个人必须都是女生,这又可以分两种情况; 2.1、如果队列的前n-2个人是合法的队列,则显然后面再加两个女生,也一定是合法的,这种情况有F(n-…
2012-11-26T12:12:57Z · 编程语言 · 评论(0)
几个有意思的学习网站
最近发现很多好玩的学习网站,整理一下: 1.Linux学习网站 http://www.linuxcast.net/ 2. JavaScript & Ruby & Python http://www.learnstreet.com/
2012-11-23T12:12:11Z · 互联网 · 评论(0)
推荐下mac上的软件(持续更新)
整理下mac上的好软件,推荐下: 1.Alfred-Mac下最好的快速启动工具 Alfred, 可以快速的搜索本地程序、使用搜索引擎搜索,查询词典等功能,十分强大, 推荐★★★★☆ 下面的链接有详细的介绍 http://www.cnbeta.com/articles/203640.htm Alfred 官网
2012-11-23T11:10:35Z · 非技术 · 评论(0)
Ubuntu常见问题和常见快捷键汇总
Ubuntu常见问题 1.设置Ubuntu下的分辨率。 本人电脑分辨率是1280x800的,但是在VBOX下安装的Ubuntu默认没有这个分辨率,添加方式如下: (参考http://askubuntu.com/questions/63863/unknown-monitor-intel-driver-want-to-set-vga-resolution-to-widescreen-tv) alvenwang@alvenwang-VirtualBox:~$xrandr -q Screen 0: minimum 64 x 64, current 1280 x 800, maximum 32000 …
2012-05-01T09:17:05Z · 操作系统 · 评论(0)
PAT 1023. Have Fun with Numbers (20)
Notice that the number 123456789 is a 9-digit number consisting exactly the numbers from 1 to 9, with no duplication. Double it we will obtain 246913578, which happens to be another 9-digit number consisting exactly the numbers from 1 to 9, only in a different permutation. Check to see the result i…
2012-03-16T09:30:38Z · 编程语言 · 评论(0)