题目大意

  给你\(n,b\),还有一个数列\(a\)。

  对于每个\(i\)求\(f_i=\sum_{j=1}^{bi}\frac{a_ja_i}{i-j}\)。

  绝对误差不超过\(5\%\)就算对。

  \(0.01\leq b\leq 0.05,n\leq {10}^5\)  

题解

  我好像在以前的UR做过一道用误差来搞事情的题:【UER#7】天路

  这题网上很多代码算出来的答案误差太大了。比如说\(n={10}^5,b=0.35,a_1=a_n={10}^7,\)其他的是\(0\)。这些代码会给出\(f_n=1212121212.121212\),但实际上\(f_n=1000010000.1\)。

  这道题的正确做法也是对于每一个\(i\)把\(j\)分段,只不过不是分成\(1\)段,而是分成好几段。对于同一段内的\(j\)满足\(\frac{1}{i-j_1}<1.05\times\frac{1}{1-j_2}\),这样取\(j_1\)代替组内的\(j\)来计算误差就不会超过\(5\%\)了。(其实也可以让组内误差\(<\frac{1.05}{0.95}\))。

  时间复杂度:\(O(n)\)。

代码

  1. #include<cstdio>
  2. #include<cstring>
  3. #include<algorithm>
  4. #include<cstdlib>
  5. #include<ctime>
  6. #include<utility>
  7. #include<cmath>
  8. #include<functional>
  9. using namespace std;
  10. typedef long long ll;
  11. typedef unsigned long long ull;
  12. typedef pair<int,int> pii;
  13. typedef pair<ll,ll> pll;
  14. void sort(int &a,int &b)
  15. {
  16. if(a>b)
  17. swap(a,b);
  18. }
  19. void open(const char *s)
  20. {
  21. #ifndef ONLINE_JUDGE
  22. char str[100];
  23. sprintf(str,"%s.in",s);
  24. freopen(str,"r",stdin);
  25. sprintf(str,"%s.out",s);
  26. freopen(str,"w",stdout);
  27. #endif
  28. }
  29. int rd()
  30. {
  31. int s=0,c;
  32. while((c=getchar())<'0'||c>'9');
  33. do
  34. {
  35. s=s*10+c-'0';
  36. }
  37. while((c=getchar())>='0'&&c<='9');
  38. return s;
  39. }
  40. int upmin(int &a,int b)
  41. {
  42. if(b<a)
  43. {
  44. a=b;
  45. return 1;
  46. }
  47. return 0;
  48. }
  49. int upmax(int &a,int b)
  50. {
  51. if(b>a)
  52. {
  53. a=b;
  54. return 1;
  55. }
  56. return 0;
  57. }
  58. int b[100010];
  59. double c[100010];
  60. double a[100010];
  61. double s[100010];
  62. int main()
  63. {
  64. open("bzoj1011");
  65. int n;
  66. double x;
  67. scanf("%d%lf",&n,&x);
  68. int i,j;
  69. int m=floor(x*n);
  70. int t=0;
  71. for(i=0;i<=m;i++)
  72. c[i]=double(n)/(n-i);
  73. for(i=1;i<=m;i++)
  74. if(i==m||c[i]>c[b[t]]*1.04)
  75. b[++t]=i;
  76. for(i=1;i<=n;i++)
  77. {
  78. scanf("%lf",&a[i]);
  79. s[i]=s[i-1]+a[i];
  80. int last=0;
  81. double ans=0;
  82. for(j=1;j<=t;j++)
  83. {
  84. int now=floor(double(b[j])/n*i);
  85. now=min(now,i-1);
  86. ans+=a[i]*(s[now]-s[last])/(i-last-1);
  87. last=now;
  88. }
  89. printf("%.10lf\n",ans);
  90. }
  91. return 0;
  92. }

【BZOJ1011】【HNOI2008】遥远的行星 误差分析的更多相关文章

  1. BZOJ 1011 [HNOI2008]遥远的行星 (误差分析)

    1011: [HNOI2008]遥远的行星 Time Limit: 10 Sec  Memory Limit: 162 MBSec  Special JudgeSubmit: 4974  Solved ...

  2. bzoj1011 [HNOI2008]遥远的行星

    1011: [HNOI2008]遥远的行星 Time Limit: 10 Sec  Memory Limit: 162 MBSec  Special JudgeSubmit: 2480  Solved ...

  3. BZOJ1011 [HNOI2008]遥远的行星 【奇技淫巧】

    1011: [HNOI2008]遥远的行星 Time Limit: 10 Sec  Memory Limit: 162 MBSec  Special Judge Submit: 5058  Solve ...

  4. BZOJ1011:[HNOI2008]遥远的行星(乱搞)

    Description 直线上N颗行星,X=i处有行星i,行星J受到行星I的作用力,当且仅当i<=AJ.此时J受到作用力的大小为 Fi->j=Mi*Mj/(j-i) 其中A为很小的常量, ...

  5. [bzoj1011](HNOI2008)遥远的行星(近似运算)

    Description 直 线上N颗行星,X=i处有行星i,行星J受到行星I的作用力,当且仅当i<=AJ.此时J受到作用力的大小为 Fi->j=Mi*Mj/(j-i) 其中A为很小的常量, ...

  6. 【bzoj1011】[HNOI2008]遥远的行星

    1011: [HNOI2008]遥远的行星 Time Limit: 10 Sec  Memory Limit: 162 MBSec  Special JudgeSubmit: 3711  Solved ...

  7. BZOJ 1011 [HNOI2008]遥远的行星

    1011: [HNOI2008]遥远的行星 Time Limit: 10 Sec  Memory Limit: 162 MBSec  Special JudgeSubmit: 2559  Solved ...

  8. 1011: [HNOI2008]遥远的行星

    1011: [HNOI2008]遥远的行星 Time Limit: 10 Sec  Memory Limit: 162 MBSec  Special JudgeSubmit: 2241  Solved ...

  9. [HNOI2008]遥远的行星

    题目描述 直线上N颗行星,X=i处有行星i,行星J受到行星I的作用力,当且仅当i<=AJ.此时J受到作用力的大小为 Fi->j=Mi*Mj/(j-i) 其中A为很小的常量,故直观上说每颗行 ...

  10. 【BZOJ】1011: [HNOI2008]遥远的行星(近似)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1011 题意:$f[i] = \sum_{j=1}^{i-1} \frac{M[i]M[j]}{i-j ...

随机推荐

  1. (第十三周)Final阶段用户调查报告

    项目名:食物链教学工具 组名:奋斗吧兄弟 组长:黄兴 组员:李俞寰.杜桥.栾骄阳.王东涵 用户调查报告 调查时间:2016年12月1日  21:00——2016年12月3日  12:00 项目分享链接 ...

  2. Day2 Numerical simulation of optical wave propagation之标量衍射理论基本原理(二)

    2.麦克斯韦方程组的简单行波解 讨论通过线性.各向同性.均匀.无色散.无限电荷和电流的电介质材料的光波传输.在这种情况下,介质具有如下属性: (1)推导获得波动方程( 由麦克斯韦方程组导出的.描述电磁 ...

  3. PS调出冷绿色电影画面风格

    原图 一.按照惯例先磨皮,我修照片的习惯是,先拉一层色阶,使直方图平均分配,画面会显得没那么灰,当然,这只是个人喜好,先加后加都没所谓. 二.由于脸部的亮度不够,显得有点脏.所以这一步主要是通过拉曲线 ...

  4. UITableView加载数据,没有数据,没有网络界面处理

    https://blog.csdn.net/chmod_r_755/article/details/53231461 俗话说的好,傻逼的APP都是相似的,牛逼的APP各有各的牛逼...但是UITabl ...

  5. 多线程系列之八:Thread-Per-Message模式

    一,Thread-Per-Message模式 翻译过来就是 每个消息一个线程.message可以理解为命令,请求.为每一个请求新分配一个线程,由这个线程来执行处理.Thread-Per-Message ...

  6. Java 学习使用常见的开源连接池

    目录 连接池介绍 自定义连接池 JDBC Tomcat Pool DBCP(DataBase Connection Pool) 使用配置文件来设置DBCP C3P0 Druid 连接池介绍 在说连接池 ...

  7. Golang的类型断言

    类型断言即判断一个变量是不是某个类型的实例,这个经常用在判断接口的类型,基本的格式: y, ok := x.(type) 上面的语句用于判断变量x是不是type类型,有两种结果: x是type类型的变 ...

  8. marMariaDB & MYSQL flexviews

    Using Flexviews - part one, introduction to materialized views - Percona Database Performance Bloght ...

  9. 二、npm scripts

    一.执行原理 安装npm 包,会将其package.json bin 字段添加到node_modules bin 里面,创建对应的.cmd文件,因此: 例如: "scripts": ...

  10. IdentityServer4【QuickStart】之设置和概述

    设置和概述 有两个基本的方式来开启一个新的IdentityServer项目: 从头开始 从asp.net Identity模板开始 如果你从头开始,我们提供了一些基于内存中构建的存储,所以你不必一开始 ...