http://acm.hust.edu.cn/vjudge/contest/view.action?cid=98759#problem/B

题意:瓶子侧躺在数轴上,瓶底在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-;
const double pi=acos(-1.0);
const int inf=0x3f3f3f3f;
const int M=1e5+;
double a[M];
double b[M];
double xlow,xhigh,inc;
vector<double> answer;
int n;
void init_b(){
for(int i=;i<=n<<;i++){
b[i]=;
}
for(int i=;i<=n;i++){
for(int j=;j<=n;j++){
b[i+j]+=a[i]*a[j];
}
}
}
double f(double x){
double sum=;
for(int i=;i<=n<<;i++){
sum+=b[i]*pow(x,i+)/(i+);
}
return sum*pi;
}
double get(double x2,double x1){
return f(x2)-f(x1);
}
double solve(){
init_b();
return get(xhigh,xlow);
}
void solve_two(){
answer.clear();
for(int i=;i<=;i++){
double L=xlow,R=xhigh;
if(get(R,L)<inc*i) return ;
while(L+eps<R){
double mid=(L+R)*0.5;
if(get(mid,xlow)<inc*i){
L=mid;
}
else{
R=mid;
}
}
answer.push_back(L-xlow);
}
}
int main(){
#ifdef txtout
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
#endif
int cas=;
while(~scanf("%d",&n)){
for(int i=;i<=n;i++){
scanf("%lf",&a[i]);
}
scanf("%lf%lf%lf",&xlow,&xhigh,&inc);
printf("Case %d: ",cas++);
double result=solve();
printf("%.2f\n",result);
if(result<inc){
puts("insufficient volume");
continue;
}
solve_two();
int len=answer.size();
for(int i=;i<len;i++){
printf("%.2f%c",answer[i],i==len-?'\n':' ');
}
}
return ;
}

http://acm.hust.edu.cn/vjudge/contest/view.action?cid=98759#problem/D

题意:定义斐波那契字符串 f0=“0”  , f1=“1”  ,fi = f i-1  + f i-2 。输入n和一个01串,问在第n个斐波那契字符串中出现了几次这个01串。

解法:对于比较小的串,可以把第n个斐波那契串直接处理出来,然后kmp。预处理到26个,就已经有190000长度了。对于大于26的串,答案有3部分,一部分等于fn-2中匹配成功的次数,一部分等于fn-1中匹配成功的次数,一部分等于fn-1的后缀加上fn-2的前缀在这个区间内匹配成功的次数。对于前两部分可以直接由之前的结果得到,对于中间的每次只保留len-1长度的前缀和后缀,这样不重不漏。

 //#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-;
const double pi=acos(-1.0);
const int inf=0x3f3f3f3f;
const int M=2e5+;
struct G {
int len;
char str[M];
} g[];
struct S{
char prefix[M],suffix[M];
}A,B,C;
char a[M];
char buffer[M];
int res[M];
LL dp[];
int n;
class KMP { ///模式匹配(kmp)O(ls+lp)
typedef char typec;///文本元素的类型
static const int MV=1e6+;///字符串的长度
int next[MV];
public:///匹配串长度ls,str 存待匹配文本,模式串长度lp,pat 存模式串
int kmp(int ls,typec str[],int lp,typec pat[],int res[]) { ///返回匹配次数,res 中
// - 31 -
// 存储每个匹配的初始位置
int i=,j=-,cnt=;
next[]=-;
while(i<lp) {
if(j==-||pat[i]==pat[j]) {
next[++i]=++j;
continue;
}
j=next[j];
}
i=j=;
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[].len=;
strcpy(g[].str,"");
g[].len=;
strcpy(g[].str,"");
for(int i=; i<=; i++) {
g[i].len=g[i-].len+g[i-].len;
strcpy(g[i].str,g[i-].str);
strcat(g[i].str,g[i-].str);
}
}
int get_first_big_id(int len){
for(int i=;i<=;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=,j=g[id].len-la+;i<la-;i++,j++){
s.prefix[i]=g[id].str[i];
s.suffix[i]=g[id].str[j];
}
s.prefix[la-]=;
s.suffix[la-]=;
}
LL solve() {
int la=strlen(a);
if(n<=) {
return gx.kmp(g[n].len,g[n].str,la,a,res);
}
int id=get_first_big_id(la);
init_dp(id,A);
init_dp(id+,B);
id+=;
while(id<=n){
dp[id]=dp[id-]+dp[id-];
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[n];
}
int main() {
#ifdef txtout
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
#endif
init();
int cas=;
while(~scanf("%d%s",&n,a)) {
printf("Case %d: %lld\n",cas++,solve());
}
return ;
}

end

matrix_world_final_2012的更多相关文章

随机推荐

  1. 集群session的一致性

    一. 何为session 用户使用网站的服务,基本上需要浏览器和web服务器进行多次交互,web服务器如何知道哪些请求是来自哪个会话的? 具体方式为:在会话开始时,分配一个唯一的会话标识(sessio ...

  2. ThinkPHP之中的getField、Find、select、返回数据类型详解(ThinkPHP之中所有数据读取了)

    小李子:用于演示作用的数据库表:customers 官方解读: “ 读取数据集其实就是获取数据表中的多行记录(以及关联数据),使用select方法 ” $customers=D('customers' ...

  3. 修改 WordPress 文件上传目录

    WordPress 默认的上传目录位于 wp-content/uploads ,并且根据设置还可以按照年月归档.但是如果要上传一个头像,或者幻灯片的话,也跟附件混在一起总是不太好吧?幸好 WordPr ...

  4. java8新特性笔记

    1.forEach(),遍历数据结构中的元素,括号内可以带一个闭包的方法 2.双冒号用法:forEach(this::doSchedule),如果运行环境是闭包,java允许使用双冒号的写法来直接调用 ...

  5. CodeBlocks背景主题的设置

    来自:http://blog.csdn.net/gzshun/article/details/8294305 找了好几个CodeBlocks的背景色,都不太如人意.感觉下面这个还不错,所以转来给大家分 ...

  6. 主键、外键、超键、候选键的区别【Written By KillerLegend】

    先说一下属性的定义: 表的每一行对应一个元组,表的每一列对应一个域.由于域可以相同,为了加以区分,必须对每列起一个唯一的名字,称为属性(Attribute). 再来看看几个键的定义: 超键:在关系模式 ...

  7. SQL Server中查询结果拼接遇到的小问题

    前天的项目,刚接手,对于模块还不是很熟悉,其中有一个模块,涉及到4个表,其中主要的表就有两个,只要把这个弄清楚了就一切回归于“太平”了. 模块要求:把两个表的内容查询出来,结果连接在一起.大师说完,感 ...

  8. java android 访问DELPHI 的DATASNAP

    最新版的DELPHI开发DATASNAP非常简单便捷,DataSnap的REST风格和对JSON的支持,使之成为服务器端开发的神器. 一.DATASNAP服务器中的方法: TServerMethods ...

  9. GoogleMapApi 发布后提示安全问题

    今天日本那边发过来一个Bug说是Google Map打不开,提示安全问题. 最后发现,日本那边的发布路径如下: https:xxxxx.gspserver.co.jp 而Source中Google M ...

  10. JavaScrip拖动动画中的常见BUG

    经常我们在用JS辛苦写完一个拖动效果之后 ,发现有各种无法用JS解决的BUG.比如拖动时DOM元素中的内容会变蓝,鼠标的指示会变为一个小+号,或disable的样式,通常这种情况一发生,我们的拖动效果 ...