SMU Summer 2024 Contest Round 2
1.Minimum Width
原题链接:
http://162.14.124.219/contest/1006/problem/C
二分一行最大容量,如果check小于等于总行数就扩大,反之则缩小
查看代码
#include <bits/stdc++.h>
#define int long long
using namespace std;
int n,m;
int a[1000000],b[1000000];
bool check(int x)
{
int now=a[1],ans=1;
for(int i=2;i<=n;i++)
{
if(now+1+a[i]>x)ans++,now=a[i];
else now+=a[i]+1;
}
return ans<=m;
}
signed main()
{
cin>>n>>m;
int left=0,right=1e15;
for(int i=1;i<=n;i++)
{
cin>>a[i];
left=max(left,a[i]);
}
int p=0;
while(left<=right)
{
int mid=left+right>>1;
if(check(mid))right=mid-1,p=mid;
else left=mid+1;
}
cout<<p<<endl;
return 0;
}
2.Sierpinski carpet
原题链接:
http://162.14.124.219/contest/1006/problem/A
确定‘.’的位置并修改,按题意输出即可
查看代码
#include<bits/stdc++.h>
using namespace std;
char ans[1000][1000];
signed main(){
int n;
cin>>n;
if(n==0)cout<<"#";
else {
int m=pow(3,n);
for(int i=1;i<=m;i++){
for(int j=1;j<=m;j++){
ans[i][j]='#';
}
}
for(int i=1;i<=n;i++){
int h=pow(3,i-1);
int endj=h+h;
int u=pow(3,i);
for(int o=0;o<m/u;o++){
for(int j=h+1+u*o;j<=endj+u*o;j++){
for(int r=0;r<m/u;r++){
for(int k=h+1+u*r;k<=endj+u*r;k++){
ans[j][k]='.';
}
}
}
}
}
for(int i=1;i<=m;i++){
for(int j=1;j<=m;j++){
cout<<ans[i][j];
}
cout<<endl;
}
}
return 0;
}