簡約摩登風:FILA / 斐樂男女情侶矽膠果凍手錶 99 元
阿新 • • 發佈:2022-01-27
以P1314為例
資料生成
#include <bits/stdc++.h> using namespace std; const long long a=1e8; int main(){ freopen("P1314.in","w",stdout); srand(time(0)); int n=rand()%100+1,m=rand()%100+1; long long s=(long long)rand()*rand()%a+1; printf("%d %d %lld\n",n,m,s); for(int i=1;i<=n;i++){ int w=(long long)rand()*rand()%10000+1; int v=(long long)rand()*rand()%10000+1; printf("%d %d\n",w,v); } for(int i=1;i<=m;i++){ int l=rand()%n+1; int r=rand()%n+1; if(l>r) swap(l,r); printf("%d %d\n",l,r); } return 0; }
對拍程式
#include <bits/stdc++.h> using namespace std; int main(){ for(int T=1;T<=10000;T++){ system("~/dtP1314"); double st=clock()/1000.0; system("~/P1314"); double ed=clock()/1000.0; system("~/bfP1314"); if(system("diff P1314.out P1314.ans")){ cout<<"WA"<<endl; return 0; } else{ if(ed-st>1){ printf("TLE %.0lfms\n",ed-st); return 0; } else printf("AC 用時 %.0lfms\n",ed-st); } } }
暴力
#include <bits/stdc++.h> #define int long long using namespace std; const int N=2e5+10; struct node{ int l,r; }in[N]; int f,l,n,m,y[N],sum,ans=1e9,s,w[N],v[N]; inline int read(){ int x=0,f=1;char ch=getchar(); while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+ch-'0';ch=getchar();} return x*f; } bool check(int mid){ int Y=0; for(int i=1;i<=m;++i){ int res1=0,res2=0; for(int j=in[i].l;j<=in[i].r;++j){ if(w[j]>=mid){ res1++; res2+=v[j]; } } y[i]=res1*res2; Y+=y[i]; } sum=abs(s-Y); if(Y>s) return 1; else return 0; } signed main(){ freopen("P1314.in","r",stdin); freopen("P1314.ans","w",stdout); n=read();m=read();s=read(); for(int i=1;i<=n;++i) w[i]=read(),v[i]=read(); for(int i=1;i<=m;++i){ in[i].l=read(); in[i].r=read(); } int l=0,r=1e6; while(l<=r){//二分w int mid=(l+r)>>1; if(check(mid)) l=mid+1; else r=mid-1; ans=min(ans,sum); } cout<<ans<<endl; return 0; }
被對拍的程式
#include <bits/stdc++.h>
#define int long long
using namespace std;
inline int read(){
int x=0,f=1;char ch=getchar();
while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}
return x*f;
}
const int N=2e5+10;
struct node{
int l,r;
}in[N];
int f,l,n,m,y[N],ans=0x3f3f3f3f3f3f3f3f,s,w[N],v[N],pre_n[N],pre_v[N],Y,sum,mn=1e15,mx=-10;
bool check(int mid){
Y=0,sum=0;
for(int i=1;i<=n;i++){
if(w[i]>=mid) pre_n[i]=pre_n[i-1]+1,pre_v[i]=pre_v[i-1]+v[i];
else pre_n[i]=pre_n[i-1],pre_v[i]=pre_v[i-1];
}
for(int i=1;i<=m;i++){
int pep=pre_n[in[i].r]-pre_n[in[i].l-1];
int val=pre_v[in[i].r]-pre_v[in[i].l-1];
Y+=pep*val;
}
sum=llabs(s-Y);
if(Y>s) return 1;
else return 0;
}
signed main(){
freopen("P1314.in","r",stdin);
freopen("P1314.out","w",stdout);
n=read();m=read();s=read();
for(int i=1;i<=n;++i){
w[i]=read(),v[i]=read();
mx=max(mx,w[i]);
mn=min(mn,w[i]);
}
for(int i=1;i<=m;++i){
in[i].l=read();
in[i].r=read();
}
int l=mn-1,r=mx+2;
while(l<=r){//二分w
int mid=(l+r)>>1;
if(check(mid)) l=mid+1;
else r=mid-1;
ans=min(ans,sum);
}
cout<<ans<<endl;
return 0;
}