随笔分类 -  hdoj

hdoj记录
摘要:#include <iostream> #include <algorithm> #include <stack> #define MAX 1000 using namespace std; struct mice { int index; int weight; int speed; }; mice mices[MAX+1]; int f[MAX+1]; int flag[MAX+1]; bool cmp(const mice mice1,const mice mice2) { if(mice1.weight!=mice2.weight) { ... 阅读全文
posted @ 2013-02-27 17:16 茉莉花茶 阅读(160) 评论(0) 推荐(0)
摘要:#include<iostream>#include<cstdio>#include<cstring>using namespace std;int min(int a,int b){ if(a>b) return b; else return a;}int main(){ long int a[5888]; long int s1,s2,s3,s4,t,n; s1 = s2 = s3 = s4 =1; a[1] = 1; for(int i=2;i<5888;i++) { ... 阅读全文
posted @ 2013-02-25 15:45 茉莉花茶 阅读(237) 评论(0) 推荐(0)
摘要:最长上升子序列(不连续)#include<iostream>using namespace std;int main(){ int n,max; int a[1000]={0},f[1000]={0}; while(cin>>n&&n!=0) { for(int k=0;k<n;k++) { cin>>a[k]; f[k] = a[k]; } ... 阅读全文
posted @ 2013-02-23 15:48 茉莉花茶 阅读(154) 评论(0) 推荐(0)
摘要:最基础的dp,dp就是YY。。:-)#include<iostream>using namespace std;int max(int a,int b){ if(a>b) return a; else return b;}int main(){ int c,n; int a[102][102]={0},f[102][102]={0}; cin>>c; for(int k=0;k<c;k++) { cin>>n; for(int i=1;i... 阅读全文
posted @ 2013-02-23 14:34 茉莉花茶 阅读(146) 评论(0) 推荐(0)
摘要:卡特兰数:1 通项公式:h(n)=C(n,2n)/(n+1)=(2n)!/((n!)*(n+1)!)2递推公式:h(n)=((4*n-2)/(n+1))*h(n-1); h(n)=h(0)*h(n-1)+h(1)*h(n-2)+...+h(n-1)*h(0).3前几项为:h(0)=1,h(1)=1,h(2)=2,h(3)=5,h(4)=14,h(5)=42,......4应用场景:a.括号化问题。 矩阵链乘:P=a1×a2×a3×……×an,依据乘法结合律,不改变其顺序,只用括号表示成对的乘积,试问有几种括号化的方案?(h(n)种)b.出栈次序问题。 一 阅读全文
posted @ 2013-02-22 20:38 茉莉花茶 阅读(252) 评论(0) 推荐(0)
摘要:#include<iostream>using namespace std;int main(){ int T,N; long long f[30] = {0}; f[1] = 1; f[2] = 3; for(int i=3;i<=30;i++) { f[i] = f[i-1] + f[i-2]*2; } cin>>T; for(int i=0;i<T;i++) { cin>>N; ... 阅读全文
posted @ 2013-02-22 15:57 茉莉花茶 阅读(160) 评论(0) 推荐(0)
摘要:#include<iostream>using namespace std;int main(){ int n,f[40],m; f[1]=1;f[2]=3; for(int i=3;i<=40;i++) { f[i]=f[i-1]+2*f[i-2]; } cin>>n; for(int j=0;j<n;j++) { cin>>m; cout<<f[m]<<endl; } return 0;} 阅读全文
posted @ 2012-11-10 01:08 茉莉花茶 阅读(132) 评论(0) 推荐(0)
摘要:#include<iostream>using namespace std;int main(){ int n,f[60]; f[0]=1;f[1]=2;f[2]=3;f[3]=4; for(int i=4;i<=60;i++) { f[i]=f[i-1]+f[i-3]; } while(cin>>n) { if(n==0) break; cout<<f[n-1]<<endl; } return 0;}3年内的幼崽不能生,其余都是翻倍 阅读全文
posted @ 2012-11-09 22:58 茉莉花茶 阅读(352) 评论(0) 推荐(0)
摘要:#include <iostream>using namespace std;int main() { long long n,a[60]; a[1]=1;a[2]=2; for(int j=3;j<=60;j++) { a[j] = a[j-1]+a[j-2]; } while(cin>>n) { cout<<a[n]<<endl; } return 0;}居然又是Fibonacci Sequence。。。。。。。这果然是个神奇的公式2×(n-2)之后的部分按这样考虑,及可得出f[i]=f[i-1]+f[i-2] 阅读全文
posted @ 2012-11-08 21:08 茉莉花茶 阅读(205) 评论(0) 推荐(0)
摘要:#include <iostream>using namespace std;int main() { long long n,f[60]; f[1]=3;f[2]=6;f[3]=6; for(int i=4;i<=60;i++) f[i]=2*f[i-2]+f[i-1]; while(cin>>n) { cout<<f[n]<<endl; } return 0;}静心思考。。。考虑为5个空格R P G P GR P R G P P G这两种可能(及4个空格下满足的情况)后面都只能再跟一种可能,正好等于f[4]R P... 阅读全文
posted @ 2012-11-08 20:13 茉莉花茶 阅读(266) 评论(0) 推荐(0)
摘要:#include <iostream>using namespace std;int main() { long long m,a,b,f[60]; cin>>m; f[1]=1;f[2]=2; for(int i=3;i<60;i++) { f[i]=f[i-1]+f[i-2]; } for(int i=0;i<m;i++) { cin>>a>>b; cout<<f[b-a]<<endl; } return 0;}自信满满的一交,就wa了,结果居然是long long 的原因。。。。要牢记... 阅读全文
posted @ 2012-11-08 19:17 茉莉花茶 阅读(116) 评论(0) 推荐(0)
摘要:#include <iostream>using namespace std;int main() { int m,n,a[40]; cin>>m; for(int i=0;i<m;i++) { cin>>n; a[n+1]=3; for(int j=n;j>0;j--) { a[j]=2*(a[j+1]-1); } cout<<a[1]<<endl; } return 0;}简单dp,学习YY思维 阅读全文
posted @ 2012-11-08 18:59 茉莉花茶 阅读(118) 评论(0) 推荐(0)
摘要:#include <iostream>using namespace std;int main() { int m,n,a[50]; a[1]=1;a[2]=2; for(int j=3;j<=50;j++) { a[j] = a[j-1]+a[j-2]; } cin>>m; for(int i=0;i<m;i++) { cin>>n; cout<<a[n-1]<<endl; } return 0;}及其简单的dp,先打表节约时间。 阅读全文
posted @ 2012-11-08 18:42 茉莉花茶 阅读(129) 评论(0) 推荐(0)
摘要:#include <iostream>using namespace std;int main() { int a,b,c=1; while(cin>>a>>b) { if(a==0&&b==0) break; for(int i=0;i<b;i++) { c=a*c; if(c>999) c=c%1000; } cout<<c<<endl; c=1; } return 0;}简单题啊。。。。。。。结果我硬把这题当1042写了。。。可惜w... 阅读全文
posted @ 2012-11-07 19:57 茉莉花茶 阅读(149) 评论(0) 推荐(0)
摘要:#include <iostream>#include<string>using namespace std;int main() { string str; int p,m,d,day,y; int month[]={0,31,28,31,30,31,30,31,31,30,31,30,31}; while(cin>>str) { p=0;y=0; int length =str.size(); for(int i=0;i <length;i++) { if(str[i+1]=='/'... 阅读全文
posted @ 2012-11-06 21:01 茉莉花茶 阅读(211) 评论(0) 推荐(0)
摘要:#include <iostream>using namespace std;int main() { char a,b,c,t1,t2,t3; while(cin>>a>>b>>c) { if(c<min(a,b)) t1=c; else { t1=min(a,b); if(a>b) t2=a; else t2=b; } if(c>max(a,b)) t3=c; else ... 阅读全文
posted @ 2012-11-06 18:54 茉莉花茶 阅读(249) 评论(0) 推荐(0)
摘要:#include <iostream>#include<cmath> #include <iomanip>using namespace std;int main() { float x1,x2,y1,y2,count; while(cin >> x1>>y1>>x2>> y2) { count = sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)); cout <<setprecision(2) << setiosflags(ios::fixed | ios:: 阅读全文
posted @ 2012-11-06 14:59 茉莉花茶 阅读(151) 评论(0) 推荐(0)