matrix_world_final_2012
2015-11-08 14:56
357 查看
B http://acm.hust.edu.cn/vjudge/contest/view.action?cid=98759#problem/B
题意:瓶子侧躺在数轴上,瓶底在xlow,瓶口在xhigh,瓶身的曲线是多项式函数,给出a0--an是多项式系数,求瓶子的体积,和每增加 inc 体积的刻度值,最多输出8个。
解法:体积用积分求,刻度值用二分求。
View Code
end
题意:瓶子侧躺在数轴上,瓶底在xlow,瓶口在xhigh,瓶身的曲线是多项式函数,给出a0--an是多项式系数,求瓶子的体积,和每增加 inc 体积的刻度值,最多输出8个。
解法:体积用积分求,刻度值用二分求。
//#define debug //#define txtout #include<cstdio> #include<cstdlib> #include<cstring> #include<cmath> #include<cctype> #include<ctime> #include<iostream> #include<algorithm> #include<vector> #include<queue> #include<stack> #include<map> #include<set> #define mt(a,b) memset(a,b,sizeof(a)) using namespace std; typedef long long LL; const double eps=1e-8; const double pi=acos(-1.0); const int inf=0x3f3f3f3f; const int M=2e5+10; struct G { int len; char str[M]; } g[32]; struct S{ char prefix[M],suffix[M]; }A,B,C; char a[M]; char buffer[M]; int res[M]; LL dp[128]; int n; class KMP { ///模式匹配(kmp)O(ls+lp) typedef char typec;///文本元素的类型 static const int MV=1e6+10;///字符串的长度 int next[MV]; public:///匹配串长度ls,str 存待匹配文本,模式串长度lp,pat 存模式串 int kmp(int ls,typec str[],int lp,typec pat[],int res[]) { ///返回匹配次数,res 中 // - 31 - // 存储每个匹配的初始位置 int i=0,j=-1,cnt=0; next[0]=-1; while(i<lp) { if(j==-1||pat[i]==pat[j]) { next[++i]=++j; continue; } j=next[j]; } i=j=0; while(i<ls) { while(j!=lp&&str[i]==pat[j]) { i++; j++; } if(!j) { i++; continue; } if(j==lp) { res[cnt++]=i-j; } j=next[j]; } return cnt; } } gx; void init() { g[0].len=1; strcpy(g[0].str,"0"); g[1].len=1; strcpy(g[1].str,"1"); for(int i=2; i<=26; i++) { g[i].len=g[i-1].len+g[i-2].len; strcpy(g[i].str,g[i-1].str); strcat(g[i].str,g[i-2].str); } } int get_first_big_id(int len){ for(int i=0;i<=26;i++){ if(g[i].len>=len) return i; } } void init_dp(int id,S &s){ int la=strlen(a); dp[id]=gx.kmp(g[id].len,g[id].str,la,a,res); for(int i=0,j=g[id].len-la+1;i<la-1;i++,j++){ s.prefix[i]=g[id].str[i]; s.suffix[i]=g[id].str[j]; } s.prefix[la-1]=0; s.suffix[la-1]=0; } LL solve() { int la=strlen(a); if(n<=26) { return gx.kmp(g .len,g .str,la,a,res); } int id=get_first_big_id(la); init_dp(id,A); init_dp(id+1,B); id+=2; while(id<=n){ dp[id]=dp[id-1]+dp[id-2]; strcpy(buffer,B.suffix); strcat(buffer,A.prefix); dp[id]+=gx.kmp(strlen(buffer),buffer,la,a,res); strcpy(C.prefix,B.prefix); strcpy(C.suffix,A.suffix); A=B; B=C; id++; } return dp ; } int main() { #ifdef txtout freopen("in.txt","r",stdin); freopen("out.txt","w",stdout); #endif init(); int cas=1; while(~scanf("%d%s",&n,a)) { printf("Case %d: %lld\n",cas++,solve()); } return 0; }
View Code
end
相关文章推荐
- Light oj1354:IP Checking
- view getwidth() 和getMeasuredWidth()区别
- java中线程安全的讲解
- 程序猿书单--转载
- 转自一个CG大神的文章
- D3.js数据可视化(三)——地图可视化
- 二叉树的各种遍历算法的递归和非递归实现
- S3C2440 NAND Flash的使用
- C++实现动态绑定代码分享
- 一个关于二维指针的问题
- 数据结构实验之栈八:栈的基本操作
- Property's synthesized getter follows Cocoa naming convention for returning
- nyoj62笨小熊
- python之模块calendar(汇集了日历相关的操作)
- C++中静态变量、常量、静态整型常量、静态非整型常量、引用变量的初始化方法
- 数据结构实验之栈七:出栈序列判定
- 第二章 运算和数据类型
- Concordion test
- 欢迎使用CSDN-markdown编辑器
- ubuntu10.4NFS挂载到mini2440相关问题