标签:写法 print closed imp har .com zoj pac void
学长学姐们觉得出测试题很有趣呢!于是刚刚返校的我们就又迎来了一次测试。
考试难度:队列;出题人:Cansult,Slr,Milky-way。
当然这个难度是不用信的,因为它并不靠谱...
T1:宽嫂的小裙子
题意概述:Cansult得到了一块m*n的布,要把它裁成一个个正方形做裙子,还要对每一块剪开的布进行锁边(只锁一边就可以),最小化这个代价。
看起来像个贪心,事实上也是,每次按照最大的裁,裁到裁完为止...然后我就爆0啦!因为没开longlong,果然一个中考过去什么都忘了...
# include <cstdio> # include <iostream> using namespace std; int t; long long a,b,r,ans=0; int main() { freopen("skirt.in","r",stdin); freopen("skirt.out","w",stdout); scanf("%d",&t); for (int i=1;i<=t;++i) { ans=0; scanf("%lld%lld",&a,&b); if(a<b) swap(a,b); while (b!=0) { r=a/b; ans+=r*b; a=a%b; swap(a,b); } printf("%lld\n",ans); } fclose(stdin); fclose(stdout); return 0; }
T2:宽嫂的缝纫
bzoj原题生成树:https://www.lydsy.com/JudgeOnline/problem.php?id=2467
算是个结论题?首先从每个五边形中都得删掉一条,然后还可以再从任意一个里面删一条...就没啦,可是考试的时候1h也没想出来qwq
T3:宽嫂的初中回忆
题意概述:给定$a$,$b$,$c$,$k$,求$f[x]^{a}*b+c=x,0<=x<=k$的根的个数;
当然先打个暴力啦:
# include <cstdio> # include <iostream> using namespace std; int t; long long p; int a,b,c,k,f,J; int q[1000000]; int h=0,ans=0; int main() { freopen("mem.in","r",stdin); freopen("mem.out","w",stdout); scanf("%d",&t); for (int i=1;i<=t;i++) { scanf("%d%d%d%d",&a,&b,&c,&k); ans=0; for (int j=0;j<=k;++j) { f=0; J=j; while (J) { f+=J%10; J=J/10; } p=1; for (int x=1;x<=a;x++) p=(long long)p*f; p*=b; p+=c; if(p==j) ans++,q[++h]=j; } if(ans==0) { printf("0\n-1\n"); continue; } printf("%d\n",ans); for (int j=1;j<=h;j++) printf("%d ",q[j]); h=0; printf("\n"); } fclose(stdin); fclose(stdout); return 0; }
正解是枚举$f[x]$,因为$k<=10^{9}$,所以$f[x]$并不会很大。
T4:宽嫂的军训
CQOI原题:https://www.luogu.org/problemnew/show/P1627
打了一个略微优秀的暴力水了80,赛后知道我的写法是枚举i,j,其实可以枚举i,把j的值先存起来,就可以A了,感觉很亏...
# include <cstdio> # include <iostream> using namespace std; int t; long long p; int a,b,c,k,f,J; int q[1000000]; int h=0,ans=0; int main() { freopen("mem.in","r",stdin); freopen("mem.out","w",stdout); scanf("%d",&t); for (int i=1;i<=t;i++) { scanf("%d%d%d%d",&a,&b,&c,&k); ans=0; for (int j=0;j<=k;++j) { f=0; J=j; while (J) { f+=J%10; J=J/10; } p=1; for (int x=1;x<=a;x++) p=(long long)p*f; p*=b; p+=c; if(p==j) ans++,q[++h]=j; } if(ans==0) { printf("0\n-1\n"); continue; } printf("%d\n",ans); for (int j=1;j<=h;j++) printf("%d ",q[j]); h=0; printf("\n"); } fclose(stdin); fclose(stdout); return 0; }
T5:宽嫂的水晶项链
usaco原题:https://www.luogu.org/problemnew/show/P3143
首先从前往后扫,维护一个以i结尾的区间内,可以放到一条裙子上的最多项链,再倒着扫一次,枚举断点即可。
# include <cstdio> # include <iostream> # include <algorithm> using namespace std; long long rf,rx,a[500005],k; int n; int dp1[500005],dp2[500005]; char rc; long long read() { rc=getchar(); rf=1; rx=0; while (!isdigit(rc)) { if(rc==‘-‘) rf=-rf; rc=getchar(); } while (isdigit(rc)) { rx=(rx<<3)+(rx<<1)+(rc^48); rc=getchar(); } return rx*rf; } int main() { freopen("crystal.in","r",stdin); freopen("crystal.out","w",stdout); scanf("%d%lld",&n,&k); for (int i=1;i<=n;i++) a[i]=read(); sort(a+1,a+1+n); int j=1; for (int i=1;i<=n;i++) { while (a[i]-a[j]>k) j++; dp1[i]=max(i-j+1,dp1[i-1]); } j=n; for (int i=n;i>=1;i--) { while (a[j]-a[i]>k) j--; dp2[i]=max(j-i+1,dp2[i+1]); } int ans=0; for (int i=1;i<=n;i++) ans=max(ans,dp1[i]+dp2[i+1]); cout<<ans; fclose(stdin); fclose(stdout); return 0; }
T6:宽嫂的学妹
题意概述:有n块积木,每块积木的高度给出,搭两座塔,要求高度一致,求最大高度
考到最后没有时间了,就写了一个大爆搜:
# include <cstdio> # include <iostream> using namespace std; int n; int ans=0; int a[10005]; int s[10005]; void dfs(int x,int l,int r) { if(x==n+1) { if(l==r) ans=max(ans,l); return ; } if(l+s[x]<r) return; if(r+s[x]<l) return; dfs(x+1,l+a[x],r); dfs(x+1,l,r+a[x]); dfs(x+1,l,r); } int main() { // freopen("cxy.in","r",stdin); // freopen("cxy.out","w",stdout); scanf("%d",&n); for (int i=1;i<=n;i++) scanf("%d",&a[i]); for (int i=n;i>=1;i--) s[i]=s[i+1]+a[i]; dfs(1,0,0); if(ans==0) printf("Impossible"); else printf("%d",ans); // fclose(stdin); // fclose(stdout); return 0; }
标签:写法 print closed imp har .com zoj pac void
原文地址:https://www.cnblogs.com/shzr/p/9206312.html