hack 12 篇题解

P2827 [NOIP2016 提高组] 蚯蚓

@[_RSY_](/user/46197) @[Maxmilite](/user/274993)
by nr0628 @ 2023-12-15 19:48:02


@[nr0628](/user/934924) 说说原理()
by Wf_yjqd @ 2023-12-15 19:50:45


好厉害%%%
by Liquefyx @ 2023-12-15 19:51:14


@[nr0628](/user/934924) 是因为DOUBLE的精度问题吗
by XP3301_Pipi @ 2023-12-16 10:32:09


@[nr0628](/user/934924) Added, thx. 题解请联系题解审核志愿者撤下。
by Maxmilite @ 2023-12-17 01:54:19


@[Wf_yjqd](/user/526094) $\texttt{double}$ 精度比较低,换成 $\texttt{long double}$ 可以过。 @[XP3301_Pipi](/user/1066579) 你说得对。
by nr0628 @ 2023-12-18 15:41:26


@[Acoipp](/user/674469) @[_•́へ•́╬_](/user/90693) @[N_z_](/user/320087) 请求撤下上述 12 篇题解。
by nr0628 @ 2023-12-18 15:42:30


@[nr0628](/user/934924) 可以解释一下原理吗?因为我完全没用 `double` 或者 `long double` 都被 Hack 了。 ```cpp #include<bits/stdc++.h> #define ll long long using namespace std; ll n,m,q,u,v,t,i,ci; struct node{ll now,zj;}a[100005],t2,t3,t1; queue<node> op,op1,op2; bool cmp(node a,node b){return a.now>b.now;} inline ll js(ll a,ll b){return a+(ci-b-1)*q;} node cs(){ ll a1=0,b1=0,c1=0; if(op.size()) a1=js(op.front().now,op.front().zj); if(op1.size()) b1=js(op1.front().now,op1.front().zj); if(op2.size()) c1=js(op2.front().now,op2.front().zj); if(a1>=b1&&a1>=c1) return op.front(); else if(b1>=a1&&b1>=c1) return op1.front(); else return op2.front(); } int main(){ scanf("%lld%lld%lld%lld%lld%lld",&n,&m,&q,&u,&v,&t); for(i=1;i<=n;i++) scanf("%lld",&a[i].now); sort(a+1,a+n+1,cmp); for(i=1;i<=n;i++) op.push(a[i]); for(ci=1;ci<=m;ci++){ t1 = cs(); if(t1.now==op.front().now&&t1.zj==op.front().zj) op.pop(); else if(t1.now==op1.front().now&&t1.zj==op1.front().zj) op1.pop(); else op2.pop(); t2.now = floor((t1.now+(ci-t1.zj-1)*q)*1.0*u/v); t2.zj = ci; t3.now = (t1.now+(ci-t1.zj-1)*q)-t2.now; t3.zj = ci; op1.push(t2); op2.push(t3); if(ci%t==0) printf("%lld ",(t1.now+(ci-t1.zj-1)*q)); } putchar('\n'); ll si = op.size()+op1.size()+op2.size(); for(i=1;i<=si;i++){ t1 = cs(); if(t1.now==op.front().now&&t1.zj==op.front().zj) op.pop(); else if(t1.now==op1.front().now&&t1.zj==op1.front().zj) op1.pop(); else op2.pop(); if(i%t==0) printf("%lld ",(t1.now+(ci-1-t1.zj)*q)); } return 0; } ```
by Acoipp @ 2023-12-18 15:50:55


@[Acoipp](/user/674469) 您好,在您的代码第 $28$ 行,将 `int` $\times 1.0$,默认转换成了 `double`。改成 `t2.now = floor((t1.now+(ci-t1.zj-1)*q)*(long double)1.0*u/v);` 就过了。
by nr0628 @ 2023-12-18 15:53:42


@[nr0628](/user/934924) 看错了,是吧 `long long` $\times1.0$ 转了 double
by nr0628 @ 2023-12-18 15:54:20


| 下一页