T1 超市抢购
https://gxyzoj.com/d/hzoj/p/3765
仔细读懂数据生成器,就能看出来,实际上物品肯定是够用的
因为只能从右向左搬运物品,所以我们只需要对于每一个i,i+1的间隔,考虑有多少个物资需要从右边搬到左边去,把这个贡献累加即可
代码:
#include<cstdio>
#include<algorithm>
#define ll long long
using namespace std;
const int maxn=1e7+5;
int a[maxn],b[maxn],n;
int randseed;
unsigned int rnd()
{
unsigned int r;
r = randseed = randseed * 1103515245 + 12345;
return (r << 16) | ((r >> 16) & 0xFFFF);
}
int main()
{
scanf("%d%d",&n,&randseed);
int sum=0;
for (int i=n;i>=1;i--)
{
a[i]=rnd()%1000,b[i]=rnd()%1000;
if (sum+(a[i]-b[i])<0) swap(a[i],b[i]);
sum+=(a[i]-b[i]);
}
ll x=0,ans=0;
for(int i=1;i<=n;i++)
{
// printf("%d %d %d\n",a[i],b[i],x);
int tmp=a[i]-b[i];
ans+=x;
if(tmp>0) x=max(1ll*0,x-tmp);
else x-=tmp;
}
printf("%lld",ans);
return 0;
}
T2 核酸检测
https://gxyzoj.com/d/hzoj/p/3766
别乱开long long!考试最后10分钟不要动代码!!!
T3 七龙珠
https://gxyzoj.com/d/hzoj/p/3767
标签:总结,gxyzoj,比赛,int,20240709,randseed,maxn,long,https From: https://www.cnblogs.com/wangsiqi2010916/p/18292642