A 珂朵莉
#include using namespace std;typedef long long ll;const int maxn = 1e5+5;double dp[maxn];double sd[maxn];ll a[maxn],n,m;ll s[maxn],x;template inline void read(T &x){x=0;T f=1;char ch;do{ch=getchar();if(ch=='-')f=-1;}while(ch<'0'||ch>'9');do x=x*10+ch-'0',ch=getchar();while(ch<='9'&&ch>='0');x*=f;}template inline void read(A&x,B&y){read(x);read(y);}template inline void read(A&x,B&y,C&z){read(x);read(y);read(z);}template inline void read(A&x,B&y,C&z,D&w){read(x);read(y);read(z);read(w);}int main(){ //freopen("in.txt","r",stdin); ll Max=-INT_MAX; read(n,m); for(int i=1;i<=n;i++) read(a[i]),Max=max(Max,a[i]); s[n+1]=0; for(int i=n;i;i--) s[i]=a[i]+s[i+1]; for(int _=1;_<=m;_++){ read(x); if(x =1;i--){ while(s[i]-s[lst]>x)lst--; dp[i]=((sd[i+1]-sd[lst+1])*1.0/(lst-i))+1.0; sd[i]=sd[i+1]+dp[i]; } printf("%.2f\n",dp[1]); } return 0;}
B 遇见
#include using namespace std;typedef long long ll; template inline void read(T &x){x=0;T f=1;char ch;do{ch=getchar();if(ch=='-')f=-1;}while(ch<'0'||ch>'9');do x=x*10+ch-'0',ch=getchar();while(ch<='9'&&ch>='0');x*=f;} template inline void read(A&x,B&y){read(x);read(y);}template inline void read(A&x,B&y,C&z){read(x);read(y);read(z);}template inline void read(A&x,B&y,C&z,D&w){read(x);read(y);read(z);read(w);} ll n,m,k;ll Mx,Mn,x;const double eps = 1e-8;int dcmp(double x){ if(x>eps) return 1; if(x<-eps) return -1; return 0;} int main(){ //freopen("in.txt","r",stdin); read(n,m,k); if(n==0){ ll res = 18ll*k/(5ll*m); if(18ll*k%(5ll*m)) res++; printf("%lld %lld\n",res,res); } else { read(x);Mx=Mn=x; for(int i=1;i
C 位数差
#include using namespace std;typedef long long ll;const int N = 1e5 + 5;int sum[N], n, a[N], Rank[N], b[N];ll BIT[15];inline int lowbit(int x) { return x & (-x);}inline void add(int p) { while (p < N) { ++sum[p]; p += lowbit(p); }}inline int query(int p) { int res = 0; while (p) { res += sum[p]; p -= lowbit(p); } return res;}int main() { ll ans = 0; scanf("%d", &n); for (int i = 1; i <= n; ++i) { scanf("%d", a + i); b[i] = a[i]; } sort(b + 1, b + n + 1); BIT[1] = 0; BIT[2] = 10; for (int i = 3; i <= 10; ++i) BIT[i] = BIT[i - 1] * 10; for (int i = 1; i <= n; ++i) Rank[i] = lower_bound(b + 1, b + n + 1, a[i]) - b; for (int i = n; i >= 1; --i) { int now = a[i], bit = 0, flg; if (!now) bit = 1; while (now) { now /= 10; ++bit; } while (1) { ++bit; flg = BIT[bit] - a[i]; int DOWN = lower_bound(b + 1, b + n + 1, flg) - b - 1; if (DOWN == n) break; ans += query(n + 1) - query(DOWN); } add(Rank[i]); } cout << ans << endl; return 0;}
D Butterfly2
#include using namespace std;typedef long long ll; const int maxn = 505;char mp[maxn][maxn];int n,m;int dp[6][maxn][maxn]; int main(){ //freopen("in.txt","r",stdin); scanf("%d%d",&n,&m); for(int i=1;i<=n;i++) scanf("%s",mp[i]+1); int ans = 0; int tmp; //1 for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){//left up X if(mp[i][j]!='X') continue; dp[0][i][j]=1; ans=1; if(i!=1&&j!=1&&mp[i-1][j-1]=='X') dp[0][i][j]=dp[0][i-1][j-1]+1; } for(int j=m;j>=1;j--){//right up O if(mp[i][j]!='O') continue; dp[1][i][j]=1; if(i!=1&&j!=m&&mp[i-1][j+1]=='O') dp[1][i][j]=dp[1][i-1][j+1]+1; } } //2 for(int i=n;i>=1;i--){ for(int j=1;j<=m;j++){//left down X if(mp[i][j]!='X') continue; dp[2][i][j]=1; ans=1; if(i!=n&&j!=1&&mp[i+1][j-1]=='X') dp[2][i][j]=dp[2][i+1][j-1]+1; } for(int j=m;j>=1;j--){//right down O if(mp[i][j]!='O') continue; dp[3][i][j]=1; if(i!=n&&j!=m&&mp[i+1][j+1]=='O') dp[3][i][j]=dp[3][i+1][j+1]+1; } } for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ if(mp[i][j]!='X') continue; dp[4][i][j]=1; if(i!=1&&mp[i-1][j]=='X') dp[4][i][j]=dp[4][i-1][j]+1; } for(int j=1;j<=m;j++){ if(mp[i][j]!='O') continue; dp[5][i][j]=1; if(i!=1&&mp[i-1][j]=='O') dp[5][i][j]=dp[5][i-1][j]+1; } } // for(int i=1;i<=n;i++) // for(int j=1;j<=m;j++) // printf("%d\n",dp[0][i][j]); for(int i=1;i<=n;i++) for(int j=1;j<=m;j++){ if(i!=1&&i!=n&&j!=1&&j!=m&&mp[i][j]=='X'){ if(mp[i-1][j+1]!='O') continue; if(mp[i+1][j+1]!='O') continue; tmp=min(dp[0][i][j],dp[2][i][j]); tmp=min(tmp,dp[1][i-1][j+1]+1); tmp=min(tmp,dp[3][i+1][j+1]+1); for(int k=tmp-1;k>=0;k--){ if(dp[4][i+k][j-k]>=k+k+1&&dp[5][i+k][j+k]>=k+k+1) ans=max(ans,k+k+1); } } } cout< <