题目列表
A 100 [入门赛 #52] 中秋灯会 30
B 100 「WWOI R4」二五一十 未提交
C 100 Xterfusion 10
D 100 [山东省小学组体验营 2026] 中位数 未提交
A题
❌️
- 暴力直接枚举最初数量
❌️
- 30分
❌️
#include<bits/stdc++.h>
using namespace std;
int a[10010][10010];
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n,m;
cin>>n>>m;
int ans=0;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
cin>>a[i][j];
if(a[i-1][j]==a[i][j])
{
ans++;
}
if(a[i][j-1]==a[i][j])
{
ans++;
}
}
}
cout<<ans;
return 0;
}
✅️
- 每次还原+枚举更换点
✅️
#include<bits/stdc++.h>
using namespace std;
int a[110][110];
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n,m;
cin>>n>>m;
int ans=0;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
cin>>a[i][j];
}
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
int aaa=a[i][j];
for(int k=1;k<=3;k++)
{
a[i][j]=k;
int cnt=0;
for(int ii=1;ii<=n;ii++)
{
for(int jj=1;jj<=m;jj++)
{
if(a[ii][jj]==a[ii+1][jj])
{
cnt++;
}
if(a[ii][jj]==a[ii][jj+1])
{
cnt++;
}
}
}
ans=max(ans,cnt);
}
a[i][j]=aaa;
}
}
cout<<ans;
return 0;
}
B题
❌️
- 无
❌️
- 无
❌️
//无✅️
- 暴力一直删掉最后的零
✅️
#include<bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
cin>>t;
while(t--)
{
long long a;
cin>>a;
while(a%5==0)a/=5;
while(a%2==0)a/=2;
int cnt=0;
while(a)a/=10,cnt++;
cout<<cnt<<'\n';
}
return 0;
}
C题
❌️
- 骗分
❌️
- 骗分
❌️
//无、
#include<bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cout<<0;
return 0;
}
✅️
- 枚举dp
✅️
#include<bits/stdc++.h>
using namespace std;
int dp1[1010];
int dp2[1010];
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
cin>>n;
string s;
cin>>s;
s=' '+s;
int ans=0;
for(int d=1;d<=n;d++)
{
for(int i=1;i<=n;i++)
{
if(i>=2*d&&s[i]=='X')dp2[i]=dp2[i-2*d]+1;
else if(s[i]=='X')dp2[i]=1;
}
for(int i=n;i>=1;i--)
{
if(i+d<=n&&s[i]=='X')dp1[i]=dp1[i+d]+1;
else if(s[i]=='X')dp1[i]=1;
}
for(int i=1;i<=n;i++)
{
ans=max(ans,dp1[i]+dp2[i]-1);
}
}
cout<<ans;
return 0;
}
D题
❌️
- 无
❌️
- 无
❌️
//无✅️
- 用二分答案来找,找完后 就是答案。二分的范围就是 ~
✅️
#include<bits/stdc++.h>
using namespace std;
int n,a[100010];
int check(int x)
{
int cnt=0;
int l=1,r=1;
while(l<=n)
{
if(a[l]-x>=r)
{
l++;
r++;
cnt++;
}
else l++;
}
return cnt*2>n;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>n;
for(int i=1;i<=n;i++)cin>>a[i];
sort(a+1,a+n+1);
int l=-2e9,r=2e9;
while(l+1<r)
{
int mid=(l+r)>>1;
if(check(mid))l=mid;
else r=mid;
}
cout<<l;
return 0;
}