B 智乃的瓷砖
思路:
按行数和列数进行划分。
代码:
cpp
void solve()
{
int n,m;
cin>>n>>m;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
if(i%2==1&&j%2==1)cout<<"/";
else if(i%2&&j%2!=1)cout<<"\\";
else if(i%2!=1&&j%2)cout<<"\\";
else if(i%2!=1&&j%2!=1)cout<<"/";
}
cout<<endl;
}
}
D 智乃的果子
思路:
和合并石子类似,用小根堆来存,从小往大合并。每次取最轻的处理,两两合并,如果只有一个,那就取下个组的一个合并。
代码:
cpp
void solve()
{
int n;
cin>>n;
int ans=0;
int cnt=0;
priority_queue<PII,vector<PII>,greater<PII>> p;
for(int i=0;i<n;i++)
{
int c,w;
cin>>c>>w;
p.push({w,c});
cnt+=c;
}
while(cnt>1){
auto [w,c]=p.top();
p.pop();
if(c>1){
int k=c/2;
int r=c%2;
int ww=w*2;
ans=(ans+(k%MOD)*(ww%MOD)%MOD)%MOD;
p.push({ww,k});
if(r)p.push({w,r});
cnt-=k;
}else{
auto [ww,cc]=p.top();
p.pop();
int www=ww+w;
ans=(ans+www%MOD)%MOD;
if(cc>1)p.push({ww,cc-1});
p.push({www,1});
cnt-=1;
}
}
cout<<ans%MOD<<endl;
}
G 智乃的箭头魔术
思路:
模拟吧,把每种情况的操作用数组写一下就能过。代码中用 ax[i] 数组来记录此时状态为 i 执行第 x 种操作后的状态。
最终结果为
cpp
3132333010010310230010130130330130312312210210010321300120122322322101123223211001003013030031210332
代码:
cpp
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int a0[4]={3,2,1,0};
int a1[4]={0,3,2,1};
int a2[4]={1,0,3,2};
int a3[4]={2,1,0,3};
int a4[4]={1,2,3,0};
int a5[4]={3,0,1,2};
void solve()
{
string s;
cin>>s;
int state=0;
for(int i=0;i<s.size();i++)
{
if(s[i]=='0')
{
cout<<a0[state];
state=a0[state];
continue;
}
if(s[i]=='1')
{
cout<<a1[state];
state=a1[state];
continue;
}
if(s[i]=='2')
{
cout<<a2[state];
state=a2[state];
continue;
}
if(s[i]=='3')
{
cout<<a3[state];
state=a3[state];
continue;
}
if(s[i]=='4')
{
cout<<a4[state];
state=a4[state];
continue;
}
if(s[i]=='5')
{
cout<<a5[state];
state=a5[state];
continue;
}
}
}
signed main(){
IOS
int t=1;
while(t--)
{
solve();
}
}
G 智乃的幻方
思路:
也是模拟吧,暴力检查。
代码:
cpp
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define endl '\n'
int a[5][5];
int b[10];
void solve()
{
bool flag=false;
int c1=0,c2=0,c3=0;
int h1=0,h2=0,h3=0;
for(int i=1;i<=3;i++)
{
for(int j=1;j<=3;j++)
{
cin>>a[i][j];
if(!b[a[i][j]])b[a[i][j]]++;
else break;
}
}
for(int i=1;i<=3;i++){
c1+=a[1][i];
c2+=a[2][i];
c3+=a[3][i];
h1+=a[i][1];
h2+=a[i][2];
h3+=a[i][3];
}
int d1=a[1][1]+a[2][2]+a[3][3];
int d2=a[1][3]+a[2][2]+a[3][1];
if(c1==c2&&c2==c3&&c3==h1&&h1==h2&&h2==h3&&h3==d1&&d1==d2)flag=true;
if(flag)cout<<"Yes";
else cout<<"No";
}
signed main(){
IOS
int t=1;
while(t--)
{
solve();
}
}
F 智乃的算法竞赛群友
思路:
假设我们使用 x 个 qcjjkkt,y 个 td。重叠的越多越节省长度,最多重叠 min(x,y) 个。那么就有:
最小长度{7x+yx≥y6x+2yx<y最小长度\begin{cases} 7x+y& \text{x≥y}\\ 6x+2y & \text{x<y} \end{cases}最小长度{7x+y6x+2yx≥yx<y
我们要使 ax+byax+byax+by 最大,固定 x,我们去找 y,可能取 0、⌊n/8⌋\lfloor n/8 \rfloor⌊n/8⌋、⌊n/7⌋\lfloor n/7 \rfloor⌊n/7⌋ 。
代码:
cpp
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define endl '\n'
int n,a,b;
int check(int x)
{
if(x<0)return 0;
if(7*x>n)return 0;
int y=min(x,n-7*x),z=max((n-7*x-y)/2,0LL);
return a*x+b*(y+z);
}
void solve()
{
cin>>n>>a>>b;
int ans=0;
ans=max(ans,check(0));
ans=max(ans,check(n/8+1));
ans=max(ans,check(n/8-1));
ans=max(ans,check(n/8));
ans=max(ans,check(n/7));
cout<<ans<<endl;
}
signed main(){
IOS
int t;
cin>>t;
//int t=1;
while(t--)
{
solve();
}
}
状态不好结束补题。😭