清北刷题冲刺 10-29 a.m
遭遇
/* 因为选的楼是个集合,与顺序无关 而且总花费=c[1]+c[2]+c[3]+|h[1]-h[2]|+|h[2]-h[3]| 我们规定走的顺序从高到低,那么绝对值就可以去掉 所以就可以约掉中间的 枚举起点终点就行了 */ #include<iostream> #include<cstdio> #include<algorithm> #include<cmath> #include<cstdlib> #define maxn 51 using namespace std; int n,t,Ans; struct node{ int c,h; bool operator < (const node b)const{ return c<b.c; } }q[maxn]; int main(){ freopen("meet.in","r",stdin);freopen("meet.out","w",stdout); // freopen("Cola.txt","r",stdin); scanf("%d",&n); for(int i=1;i<=n;i++)scanf("%d",&q[i].c); for(int i=1;i<=n;i++)scanf("%d",&q[i].h); scanf("%d",&t); sort(q+1,q+n+1); for(int i=1;i<=n;i++){ for(int j=i+1;j<=n;j++){//枚举起点和终点 int now=t; int mx=max(q[i].h,q[j].h),mn=min(q[i].h,q[j].h); now-=abs(q[i].h-q[j].h)+q[i].c+q[j].c; if(now<0)continue; int ans=2; for(int k=1;k<=n;k++){ if(k==i||k==j||q[k].h>mx||q[k].h<mn)continue; if(now-q[k].c<0)continue; now-=q[k].c;ans++; } Ans=max(Ans,ans); } } if(Ans==0&&q[1].c<=t)Ans=1; printf("%d",Ans); } /* 10 19076 5807 413 6068 16699 28657 21980 12842 1668 21332 15929 15552 10742 29857 14248 14255 1464 29941 4132 25874 60081 */
都市
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #define mod 47680453 using namespace std; int n,s,a[1226],q[10],q1[10],b[1226],nn; struct node{ int x1,x2,x3,x4,x5; }ans[1000]; bool vis[50000000]; int has(){ int res=1; for(int i=1;i<=n;i++){ res=(res*37+q1[i])%mod; } return res; } void check(){ int t=0; for(int i=1;i<=n;i++){ for(int j=i+1;j<=n;j++){ b[++t]=q[i]+q[j]; } } sort(b+1,b+nn+1); for(int i=1;i<=nn;i++){ if(b[i]!=a[i])return; } for(int i=1;i<=n;i++)q1[i]=q[i]; sort(q1+1,q1+n+1); node now;now.x1=q1[1];now.x2=q1[2];now.x3=q1[3];now.x4=q1[4];now.x5=q1[5]; int ha=has(); if(!vis[ha]){ vis[ha]=1; ans[++s]=now; } } void dfs(int pos){ if(pos==n+1){ check(); return; } for(int i=10;i>=1;i--){ q[pos]=i; dfs(pos+1); } } bool cmp(node u,node v){ if(u.x1!=v.x1)return u.x1>v.x1; if(u.x2!=v.x2)return u.x2>v.x2; if(u.x3!=v.x3)return u.x3>v.x3; if(u.x4!=v.x4)return u.x4>v.x4; if(u.x5!=v.x5)return u.x5>v.x5; } int main(){ freopen("city.in","r",stdin);freopen("city.out","w",stdout); // freopen("Cola.txt","r",stdin); scanf("%d",&n);nn=n*(n-1)/2; for(int i=1;i<=nn;i++)scanf("%d",&a[i]); sort(a+1,a+nn+1); dfs(1); printf("%d\n",s); sort(ans+1,ans+s+1,cmp); for(int i=1;i<=s;i++){ if(n==5)printf("%d %d %d %d %d\n",ans[i].x1,ans[i].x2,ans[i].x3,ans[i].x4,ans[i].x5); if(n==4)printf("%d %d %d %d\n",ans[i].x1,ans[i].x2,ans[i].x3,ans[i].x4); if(n==3)printf("%d %d %d\n",ans[i].x1,ans[i].x2,ans[i].x3); if(n==2)printf("%d %d\n",ans[i].x1,ans[i].x2); if(n==1)printf("%d\n",ans[i].x1); } return 0; }
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #define maxn 310 using namespace std; int n,m,res[maxn],ans[maxn][maxn],z[maxn*maxn],cnt; bool use[maxn*maxn]; void check(int p){ memset(use,0,sizeof(use)); if((z[1]+z[2]+z[p])&1)return; res[1]=(z[1]+z[2]+z[p])/2-z[p]; res[2]=z[1]-res[1]; res[3]=z[2]-res[1]; use[1]=use[2]=use[p]=1; for(int i=4,j=3;i<=n;i++){ while(j<=m&&use[j])j++; if(j>m)return; res[i]=z[j]-res[1]; use[j]=1; for(int k=2;k<i;k++){ if(res[k]>res[i])return; int v=res[k]+res[i]; int p=lower_bound(z+1,z+m+1,v)-z; if(z[p]!=v)return; int px=p; while(px&&z[px]==z[p])px--; px++; while(px<=m&&z[px]==z[p]&&use[px])px++; if(z[px]!=z[p]||use[px])return; p=px; use[p]=1; } } cnt++; for(int i=1;i<=n;i++)ans[cnt][i]=res[i]; } int main(){ freopen("city.in","r",stdin);freopen("city.out","w",stdout); scanf("%d",&n);m=n*(n-1)/2; for(int i=1;i<=m;i++)scanf("%d",&z[i]); sort(z+1,z+m+1); for(int i=3;i<=m;){ check(i); int j=i; while(j<=m&&z[j]==z[i])j++; i=j; } printf("%d\n",cnt); for(int i=1;i<=cnt;i++) for(int j=1;j<=n;j++){ printf("%d",ans[i][j]); if(j==n)printf("\n"); else printf(" "); } return 0; }
街灯
#include<iostream> #include<cstdio> #define maxn 100010 using namespace std; int n,m,a[maxn]; struct node{ int l,r,p,v; }q[maxn]; bool flag=1; int main(){ freopen("light.in","r",stdin);freopen("light.out","w",stdout); scanf("%d%d",&n,&m); for(int i=1;i<=n;i++)scanf("%d",&a[i]); for(int i=1;i<=m;i++){ scanf("%d%d%d%d",&q[i].l,&q[i].r,&q[i].p,&q[i].v); } for(int i=1;i<=m;i++){ int ans=0; for(int j=q[i].l;j<=q[i].r;j++){ if(a[j]%q[i].p==q[i].v)ans++; } printf("%d\n",ans); } }
#include<cstdio> #include<cstring> #include<algorithm> #define maxn 100010 #define maxv 10000 using namespace std; int n,m,a[maxn],vb[110][110],ve[110][110]; int xb[maxn],xe[maxn]; int i_buf[maxn*110*2],tib; void pre(){ memset(ve,0,sizeof(ve)); memset(xe,0,sizeof(xe)); for(int i=1;i<=n;i++)xe[a[i]]++; for(int i=0;i<=maxv;i++){ xb[i]=tib; tib+=xe[i]; xe[i]=xb[i]; } for(int i=1;i<=n;i++)i_buf[xe[a[i]]++]=i; for(int m=1;m<=100;m++){ for(int i=1;i<=n;i++)ve[m][a[i]%m]++; for(int i=0;i<m;i++){ vb[m][i]=tib; tib+=ve[m][i]; ve[m][i]=vb[m][i]; } for(int i=1;i<=n;i++) i_buf[ve[m][a[i]%m]++]=i; } } int queryb(int l0,int r0,int p,int k){ if(vb[p][k]==ve[p][k])return 0; int *x1=lower_bound(i_buf+vb[p][k],i_buf+ve[p][k],l0); int *x2=upper_bound(i_buf+vb[p][k],i_buf+ve[p][k],r0); return x2-x1; } int querys(int v,int l0,int r0){ if(xb[v]==xe[v])return 0; int *x1=lower_bound(i_buf+xb[v],i_buf+xe[v],l0); int *x2=lower_bound(i_buf+xb[v],i_buf+xe[v],r0); return x2-x1; } int querya(int l0,int r0,int p,int k){ int ans=0; for(int i=k;i<=maxv;i+=p)ans+=querys(i,l0,r0); return ans; } int main(){ freopen("light.in","r",stdin);freopen("light.out","w",stdout); scanf("%d%d",&n,&m); tib=0; for(int i=1;i<=n;i++)scanf("%d",&a[i]); pre(); while(m--){ int l,r,p,k; scanf("%d%d%d%d",&l,&r,&p,&k); if(p<=100)printf("%d\n",queryb(l,r,p,k)); else printf("%d\n",queryb(l,r,p,k)); } }
预计得分100+30+30 实际得分100+30+30 三个题写的都不是正解,其中T1是化简式子之后胡邹的一个算法 T2T3都是暴力 这次模拟赛暴力虽然打的没什么技巧,但是不该丢的分都没有丢