标签:ble pac mes type com names namespace show for
二分
二维前缀和
垃圾炸弹
https://www.lydsy.com/JudgeOnline/problem.php?id=1218
代码
#include<cstdio> #include<algorithm> using namespace std; const int maxn=5050; int sum[maxn][maxn]; int main(){ int n,r; int x,y,w; scanf("%d%d",&n,&r); for (int i=1;i<=n;i++){ scanf("%d%d%d",&x,&y,&w); sum[x+1][y+1]=w; } for (int i=1;i<=5001;i++) sum[1][i]=sum[1][i-1]+sum[1][i]; for (int i=1;i<=5001;i++) sum[i][1]=sum[i-1][1]+sum[i][1]; for (int i=2;i<=5001;i++){ for (int j=2;j<=5001;j++){ sum[i][j]=sum[i-1][j]+sum[i][j-1]+sum[i][j]-sum[i-1][j-1]; } } int ans=0; for (int i=r;i<=5001;i++){ for (int j=r;j<=5001;j++){ ans=max(ans,sum[i][j]-sum[i-r][j]-sum[i][j-r]+sum[i-r][j-r]); } } printf("%d",ans); return 0; }
前缀和
https://www.luogu.org/recordnew/show/11207133
#include<cstdio> #include<algorithm> using namespace std; typedef long long ll; const int maxn=100000+10; ll sum[maxn]; int main(){ int n,k,y; scanf("%d%d",&n,&k); for (int i=1;i<=n;i++){ scanf("%d",&y); sum[i]=sum[i-1]+y; } ll ans=0; for (int i=k;i<=n;i++) ans+=(sum[i]-sum[i-k]); printf("%lld",ans); return 0; }
快速幂
https://www.luogu.org/problemnew/show/P1226
#include<cstdio> #include<algorithm> using namespace std; typedef long long ll; ll mod; ll quickmod(ll a,ll b,ll mod){ ll ans=1%mod; for (;b;b>>=1){ if(b&1) ans=ans*a%mod; a=a*a%mod; } return ans%mod; } int main(){ ll a,b; scanf("%lld%lld%lld",&a,&b,&mod); printf("%lld^%lld mod %lld=%lld",a,b,mod,quickmod(a,b,mod)); return 0;
}
标签:ble pac mes type com names namespace show for
原文地址:https://www.cnblogs.com/lmjer/p/9715575.html