3.22模拟总结
芜湖一次AK
T1
固输样例就行了,二分会炸。。我怕有坑特判了个区间没零点的情况
#include<cstdio> #include<queue> #include<iostream> #include<cstring> #include<algorithm> #include<cmath> #include<cctype> #include<vector> #include<string> #define lalala using namespace std; int main(){ #ifdef lalala freopen("equation.in","r",stdin); freopen("equation.out","w",stdout); #endif double l,r; scanf("%lf%lf",&l,&r); double ans = 1.5071105957; if(r < ans || l > ans)printf("0.0000000000"); else printf("%.10lf",ans); }
根据标题,二分查找,所以我们这里采用倍增
#include<cstdio> #include<queue> #include<iostream> #include<cstring> #include<algorithm> #include<cmath> #include<cctype> #include<vector> #include<string> #define hahaha using namespace std; int n,a[1000005]; int main(){ #ifdef hahaha freopen("binary.in","r",stdin); freopen("binary.out","w",stdout); #endif scanf("%d",&n); for(int i=1;i<=n;++i)scanf("%d",a+i); int x; scanf("%d",&x); int ans = 0; for(int i=20;i>=0;--i){ if(ans + (1<<i) <= n) if(a[ans + (1<<i)] < x)ans += (1<<i); } if(a[ans+1] == x && ans < n)printf("%d",ans+1); else printf("-1"); }
树状数组+离散化,树状数组维护元素离散化后的下标。
#include<cstdio> #include<queue> #include<iostream> #include<cstring> #include<algorithm> #include<cmath> #include<cctype> #include<vector> #include<string> #define hahaha using namespace std; const int N = 5e5 + 5; int n,a[N],c[N],p[N],mx = -1; long long ans; inline int lowbit(int x){return x & (-x);} inline void update(int i,int x){ for(;i<=n;i+=lowbit(i))c[i] += x; } inline int query(int i){ int res = 0; for(;i;i-=lowbit(i)) res += c[i]; return res; } int main(){ #ifdef hahaha freopen("deseq.in","r",stdin); freopen("deseq.out","w",stdout); #endif scanf("%d",&n); for(int i=1;i<=n;++i)scanf("%d",a+i),mx = max(mx,a[i]); memcpy(p,a,sizeof(p)); sort(p+1,p+1+n); for(int i=1;i<=n;++i){ a[i] = lower_bound(p+1,p+1+n,a[i])-p; update(a[i],1); ans += query(n) - query(a[i]); } printf("%lld",ans); }
行,打眼一看,傻逼高精度。
先考虑位数,首先我们知道, $10^n$ 有 $n+1$ 位,$2^p$ 的位数和 $2^p-1$ 位数相同,那么我们就把底数 $ 2$ 变成 $10$ 呗,就变成 $2 = 10^{log_{10}(2)}$ 然后就弄完了,至于第二问,就快速幂乘就完事了,傻逼高精度
#include<cstdio> #include<queue> #include<iostream> #include<cstring> #include<algorithm> #include<cmath> #include<cctype> #include<vector> #include<string> #define hahaha using namespace std; const int N = 2500; int lc,a[N],b[N],p,c[N],la = 1,lb = 1; inline int mul1(){ memset(c,0,sizeof(c)); for(int i=1;i<=la;++i) for(int j=1;j<=lb;++j){ c[i+j-1] += a[i] * b[j]; c[i+j] += c[i+j-1] / 10; c[i+j-1] %= 10; } int lc = la + lb; while(c[lc] == 0)--lc; for(int i=1;i<=lc;++i)a[i] = c[i]; return lc > 500 ? 500 : lc; } inline int mul2(){ memset(c,0,sizeof(c)); for(int i=1;i<=lb;++i) for(int j=1;j<=lb;++j){ c[i+j-1] += b[i] * b[j]; c[i+j] += c[i+j-1] / 10; c[i+j-1] %= 10; } int lc = (lb<<1); while(c[lc] == 0)--lc; for(int i=1;i<=lc;++i)b[i] = c[i]; return lc > 500 ? 500 : lc; } inline void ksm(){ while(p){ if(p&1)la = mul1(); p >>= 1; lb = mul2(); } } int main(){ #ifdef hahaha freopen("mason.in","r",stdin); freopen("mason.out","w",stdout); #endif scanf("%d",&p); printf("%d\n",(int)(p*log10(2.0)+1)); a[1] = 1,b[1] = 2; ksm(); a[1]--; for(int i=500;i;--i){ printf("%d",a[i]); if(!((i-1)%50))putchar('\n'); } }