學長學姐們的測試-2
學長學姐們覺得出測試題很有趣呢!於是剛剛返校的我們就又迎來了一次測試。
考試難度:隊列;出題人:Cansult,Slr,Milky-way。
當然這個難度是不用信的,因為它並不靠譜...
T1:寬嫂的小裙子
題意概述:Cansult得到了一塊m*n的布,要把它裁成一個個正方形做裙子,還要對每一塊剪開的布進行鎖邊(只鎖一邊就可以),最小化這個代價。
看起來像個貪心,事實上也是,每次按照最大的裁,裁到裁完為止...然後我就爆0啦!因為沒開longlong,果然一個中考過去什麽都忘了...
# include <cstdio> # includeskirt<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; }mem(40pts)
正解是枚舉$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; }中位數(80pts)
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; }crystal
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; }cxy(40pts)
學長學姐們的測試-2