题意非常easy:

对于长度为n的数。做n-1遍。生成的新数列:

b1=a2-a1   b2=a3-a2  b3=a4-a3

c1=b2-b1   c2=b3-b2

ans=c2-c1

最后推出公式:  为n所在行的杨辉三角

对于例子:

3

1 2 3

ans=1*1-2*2+1*3=0

4

1 5 7 2

ans=-1*1+3*5-3*7+1*2=-5

求杨辉三角每一个数的时候能够优化一下,后一个数由前一个各乘除一次就好了

JAVA用大数秒A。

BUT 不会JAVA  - -#

蛋疼用C++模拟大数。。

#include "stdio.h"
#include "string.h"
int a[3010];
__int64 mark[3010],ans[3010],c[3010];
int Max(int a,int b)
{
if (a<b) return b;else return a;
} void make_mul(int x)
{
int i;
for (i=1;i<=mark[0];i++)
mark[i]*=x; for (i=1;i<=mark[0];i++)
{
mark[i+1]+=mark[i]/1000000;
mark[i]%=1000000;
}
while (mark[mark[0]+1]!=0)
{
mark[0]++;
mark[mark[0]+1]=mark[mark[0]]/1000000;
mark[mark[0]]%=1000000;
} } void make_div(int x)
{
int i;
for (i=mark[0];i>=2;i--)
{
mark[i-1]+=(mark[i]%x)*1000000;
mark[i]/=x;
}
mark[1]/=x;
while (mark[mark[0]]==0) mark[0]--;
} void make_add()
{
int i,op;
if (ans[0]>0)
{
for (i=1;i<=mark[0];i++)
{
ans[i]+=mark[i];
ans[i+1]+=ans[i]/1000000;
ans[i]%=1000000;
}
while (ans[ans[0]+1]!=0)
{
ans[0]++;
ans[ans[0]+1]=ans[ans[0]]/1000000;
ans[ans[0]]%=1000000;
}
return ;
}
else
{
if (-ans[0]>mark[0]) op=-1;
else if (-ans[0]<mark[0]) op=1;
else
{
for (i=mark[0];i>=1;i--)
if (mark[i]>ans[i]) { op=1;break;}
else if (mark[i]<ans[i]) { op=-1; break;} if (i==0)
{
memset(ans,0,sizeof(ans));
ans[0]=1;
return ;
}
} if (op==1)
{
for (i=1;i<=mark[0];i++)
{
ans[i]=mark[i]-ans[i];
if (ans[i]<0)
{
mark[i+1]--;
ans[i]+=1000000;
}
}
ans[0]=-ans[0];
while (ans[ans[0]]==0) ans[0]--;
}
else
{
for (i=1;i<=-ans[0];i++)
{
ans[i]=ans[i]-mark[i];
if (ans[i]<0)
{
ans[i+1]--;
ans[i]+=1000000;
}
}
while (ans[-ans[0]]==0) ans[0]++;
} }
} void make_red()
{
int i,op;
if (ans[0]<0)
{
for (i=1;i<=mark[0];i++)
{
ans[i]+=mark[i];
ans[i+1]+=ans[i]/1000000;
ans[i]%=1000000;
}
while (ans[-ans[0]+1]!=0)
{
ans[0]--;
ans[-ans[0]+1]=ans[-ans[0]]/1000000;
ans[-ans[0]]%=1000000;
}
return ;
}
else
{
if (ans[0]>mark[0]) op=1;
else if (ans[0]<mark[0]) op=-1;
else
{
for (i=mark[0];i>=1;i--)
if (mark[i]>ans[i]) { op=-1;break;}
else if (mark[i]<ans[i]) { op=1; break;} if (i==0)
{
memset(ans,0,sizeof(ans));
ans[0]=1;
return ;
}
} if (op==1)
{
for (i=1;i<=mark[0];i++)
{
ans[i]=ans[i]-mark[i];
if (ans[i]<0)
{
ans[i+1]--;
ans[i]+=1000000;
}
}
while (ans[ans[0]]==0) ans[0]--;
}
else
{
for (i=1;i<=mark[0];i++)
{
ans[i]=mark[i]-ans[i];
if (ans[i]<0)
{
mark[i+1]--;
ans[i]+=1000000;
}
}
ans[0]=mark[0];
while (ans[ans[0]]==0) ans[0]--;
ans[0]=-ans[0];
} } }
int main()
{
int t,n,i,x,y,j,m,op;
scanf("%d",&t);
while (t--)
{
scanf("%d",&n);
for (i=1;i<=n;i++)
scanf("%d",&a[i]); memset(ans,0,sizeof(ans));
ans[0]=1;
if (i==1)
{
printf("%d\n",a[1]);
continue;
}
memset(mark,0,sizeof(mark));
mark[0]=1;
mark[1]=1;
if (n%2==1) ans[1]=a[1];
else ans[1]=-a[1];
x=1;
y=n-1;
for (i=2;i<=n;i++)
{
make_mul(y);
y--;
make_div(x);
x++;
memcpy(c,mark,sizeof(mark)); make_mul(a[i]);
if (n%2==1)
{
if (i%2==1) make_add();
else make_red();
}
else
{
if (i%2==0) make_add();
else make_red();
}
memcpy(mark,c,sizeof(c)); } if (ans[0]>0)
{
printf("%I64d",ans[ans[0]]);
for (i=ans[0]-1;i>=1;i--)
printf("%06I64d",ans[i]);
printf("\n");
}
else
{
printf("-");
printf("%I64d",ans[-ans[0]]);
for (i=-ans[0]-1;i>=1;i--)
printf("%06I64d",ans[i]);
printf("\n");
} }
return 0;
}

HDU 4927 大数的更多相关文章

  1. HDU 4927 大数运算

    模板很重要 #include <cstdio> #include <cstring> #include <cstdlib> #include <iostrea ...

  2. HDU 4927 Series 1(推理+大数)

    HDU 4927 Series 1 题目链接 题意:给定一个序列,要求不断求差值序列.直到剩一个,输出这个数字 思路:因为有高精度一步.所以要推理一下公式,事实上纸上模拟一下非常easy推出公式就是一 ...

  3. 多校第六场 HDU 4927 JAVA大数类+模拟

    HDU 4927 −ai,直到序列长度为1.输出最后的数. 思路:这题实在是太晕了,比赛的时候搞了四个小时,从T到WA,唉--对算组合还是不太了解啊.如今对组合算比較什么了-- import java ...

  4. hdu 4927 java求组合数(大数)

    import java.util.Scanner; import java.math.BigInteger; public class Main { private static int [] a = ...

  5. HDU 4927 Series 1(高精度+杨辉三角)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4927 解题报告:对于n,结果如下: C(0,n-1) *A[n] - C(1,n-1) * A[n-1 ...

  6. HDU 4927

    http://acm.hdu.edu.cn/showproblem.php?pid=4927 直接模拟会超时,要在纸上写写推公式 A[n]*C(0,n-1)  - A[n-1]*C(1,n-1) + ...

  7. hdu 4927 组合+公式

    http://acm.hdu.edu.cn/showproblem.php?pid=4927 给定一个长度为n的序列a,每次生成一个新的序列,长度为n-1,新序列b中bi=ai+1−ai,直到序列长度 ...

  8. hdu 1002大数(Java)

    A + B Problem II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  9. hdu 5047 大数找规律

    http://acm.hdu.edu.cn/showproblem.php?pid=5047 找规律 信kuangbin,能AC #include <stdio.h> #include & ...

随机推荐

  1. linux系统负载状态检查脚本

    为了便于分析问题,编写了一个linux状态检查脚本,脚本可放置任意目录,脚本执行检测后会输出日志记录到当前目录下.直接执行脚本可用于一次检测,可通过日志进行分析.如果需要长时间监测,可执行-x参数,脚 ...

  2. Codeforces Round #364 (Div. 2) D 数学/公式

    D. As Fast As Possible time limit per test 1 second memory limit per test 256 megabytes input standa ...

  3. UVA 11991 vector

    Though Rujia Liu usually sets hard problems for contests (for example, regional contests likeXi’an 2 ...

  4. jquery 跳转页面传值的问题

    关于 跳转页面传值的问题 1. 目前最多的是使用 ajax 方法 //举例 ajax 传值,举例: $.ajax({ type : "post", url : "save ...

  5. Repeater用ul li,一行显示多条数据

    原文发布时间为:2009-08-26 -- 来源于本人的百度文章 [由搬家工具导入] .rep {         width:680px;         float:left;         l ...

  6. SQL存储过程基础

    什么是存储过程呢?存储过程就是作为可执行对象存放在数据库中的一个或多个SQL命令. 通俗来讲:存储过程其实就是能完成一定操作的一组SQL语句. 那为什么要用存储过程呢?1.存储过程只在创造时进行编译, ...

  7. JavaScript变量提升和函数声明预解析

    1.首先理解函数作用域 在JavaScript中,变量的定义并不是以代码块作为作用域的,而是以函数作用作用域的.也就是说,如果变量是在某个函数中定义的,那么它在函数以外的地方是不可见的.而如果该变量是 ...

  8. Django之model F/Q以及多对多操作

    model之F/Q操作 F操作,使用查询条件的值 打个比方吧,有一张表,保存着公司员工的工资,公司普涨工资,如何在model中操作,这就用到了F,首先需要导入此模块: from django.db.m ...

  9. Android自定义Dialog多选对话框(Dialog+Listview+CheckBox)

    先放效果截图 项目中需要有个Dialog全选对话框,点击全选全部选中,取消全选全部取消.下午查了些资料,重写了一下Dialog对话框.把代码放出来. public class MainActivity ...

  10. SVG描边动画实现过程

    准备工具:Adobe AI+PS 1.确定SVG画布的大小,在PS中切出需要描边效果的区域,以此区域的大小做为SVG容器的大小.   2.将PS中切好的图片直接拖拽到AI中     3.使用AI中的钢 ...