【BZOJ1011】【HNOI2008】遥远的行星 误差分析
2017-11-24 15:52
225 查看
题目大意
给你n,b,还有一个数列a。对于每个i求fi=∑bij=1ajaii−j。
绝对误差不超过5%就算对。
0.01≤b≤0.05,n≤105
题解
我好像在以前的UR做过一道用误差来搞事情的题:【UER#7】天路这题网上很多代码算出来的答案误差太大了。比如说n=105,b=0.35,a1=an=107,其他的是0。这些代码会给出fn=1212121212.121212,但实际上fn=1000010000.1。
这道题的正确做法也是对于每一个i把j分段,只不过不是分成1段,而是分成好几段。对于同一段内的j满足1i−j1<1.05×11−j2,这样取j1代替组内的j来计算误差就不会超过5%了。(其实也可以让组内误差<1.050.95)。
时间复杂度:O(n)。
代码
#include<cstdio> #include<cstring> #include<algorithm> #include<cstdlib> #include<ctime> #include<utility> #include<cmath> #include<functional> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int,int> pii; typedef pair<ll,ll> pll; void sort(int &a,int &b) { if(a>b) swap(a,b); } void open(const char *s) { #ifndef ONLINE_JUDGE char str[100]; sprintf(str,"%s.in",s); freopen(str,"r",stdin); sprintf(str,"%s.out",s); freopen(str,"w",stdout); #endif } int rd() { int s=0,c; while((c=getchar())<'0'||c>'9'); do { s=s*10+c-'0'; } while((c=getchar())>='0'&&c<='9'); return s; } int upmin(int &a,int b) { if(b<a) { a=b; return 1; } return 0; } int upmax(int &a,int b) { if(b>a) { a=b; return 1; } return 0; } int b[100010]; double c[100010]; double a[100010]; double s[100010]; int main() { open("bzoj1011"); int n; double x; scanf("%d%lf",&n,&x); int i,j; int m=floor(x*n); int t=0; for(i=0;i<=m;i++) c[i]=double(n)/(n-i); for(i=1;i<=m;i++) if(i==m||c[i]>c[b[t]]*1.04) b[++t]=i; for(i=1;i<=n;i++) { scanf("%lf",&a[i]); s[i]=s[i-1]+a[i]; int last=0; double ans=0; for(j=1;j<=t;j++) { int now=floor(double(b[j])/n*i); now=min(now,i-1); ans+=a[i]*(s[now]-s[last])/(i-last-1); last=now; } printf("%.10lf\n",ans); } return 0; }
相关文章推荐
- BZOJ 1011 [HNOI2008]遥远的行星 (误差分析)
- bzoj1011 [HNOI2008]遥远的行星
- bzoj1011 [HNOI2008]遥远的行星
- BZOJ.1011.[HNOI2008]遥远的行星(思路 枚举)
- 【BZOJ 1011】[HNOI2008]遥远的行星
- bzoj1011: [HNOI2008]遥远的行星
- [bzoj] 1011: [HNOI2008]遥远的行星
- bzoj1011: [HNOI2008]遥远的行星
- BZOJ_1011_[HNOI2008]_遥远的行星_(近似)
- BZOJ 1011 [HNOI2008]遥远的行星
- 【BZOJ】1011: [HNOI2008]遥远的行星(近似)
- [BZOJ]1011 遥远的行星(HNOI2008)
- bzoj1011 [HNOI2008]遥远的行星(分块+瞎搞)
- 【BZOJ1011】【HNOI2008】遥远的行星(乱搞)
- 【BZOJ1011】【HNOI2008】遥远的行星
- 【bzoj1011】[HNOI2008]遥远的行星
- 【BZOJ】【1011】【HNOI2008】遥远的行星
- HYSBZ/BZOJ 1011 [HNOI2008] 遥远的行星 - 模糊答案&暴力
- 【估计】BZOJ1011(HNOI2008)[遥远的行星]题解
- BZOJ 1011: [HNOI2008]遥远的行星