2026.8.21 模拟赛14
一、比赛基本情况
比赛日期:2026.8.21
比赛时长: ~
比赛得分:
比赛排名:
二、比赛整体回顾
开题顺序:(约) - (约)
三、题目复盘
T1:P16695 [CSPro 29] 垦田计划
本题得分:
初始思路:
没看出来这是个啥
考场解题过程:
无
考场代码:
无
赛后题解:
二分答案
二分开垦这些田的所需时间。
判断能不能通过资源让所有位置的时间都小于等于
补题代码:
#include<bits/stdc++.h>
#define int long long
#define ull unsigned long long
#define endl '\n'
using namespace std;
const int N=1e5+5;
int n,m,k;
int maxi=-1e18;
int t[N];
int c[N];
int check(int x){
int sum=0;
for(int i=1;i<=n;i++){
if(t[i]>x){
sum+=(t[i]-x)*c[i];
}
}
return sum<=m;
}
void find(){
int l=k-1,r=maxi+1;
while(l+1<r){
int mid=(l+r)/2;
if(check(mid)){
r=mid;
}else{
l=mid;
}
}
cout<<r;
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n>>m>>k;
for(int i=1;i<=n;i++){
cin>>t[i]>>c[i];
maxi=max(maxi,t[i]);
}
find();
return 0;
}T2: P17015 [GESP202606 七级] 消消乐
本题得分:
初始思路:
看出来是区间dp,但是状态转移方程错了,就写了暴力。
贪心,最后消除最大值,先把最大值左右两边的之消掉
考场解题过程:
模拟
考场代码:
#include<bits/stdc++.h>
#define int long long
#define ull unsigned long long
#define endl '\n'
using namespace std;
const int N=105;
int n;
int cnt;
int ans;
int maxi,id;
int a[N];
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n;
cnt=n;
for(int i=1;i<=n;i++){
cin>>a[i];
}
while(cnt!=1){
maxi=-1e18;
for(int i=1;i<=n;i++){
if(a[i]>maxi){
maxi=a[i];
id=i;
}
}
for(int i=1;i<=n;i++){
// if(a[i]==-1){
// continue;
// }
if(i+1==id){
// cout<<i<<' '<<a[i+1]<<' '<<a[i-1]<<endl;
ans+=a[i+1]+a[i-1];
a[i]=-1;
}
if(i-1==id){
// cout<<i<<' '<<a[i+1]<<' '<<a[i-1]<<endl;
ans+=a[i+1]+a[i-1];
a[i]=-1;
}
}
for(int i=1;i<=n;i++){
if(a[i]==-1){
// cout<<i<<' ';
cnt--;
for(int j=i-1;j>=1;j--){
a[j+1]=a[j];
}
for(int j=1;j<=n-cnt;j++){
a[j]=0;
}
// for(int j=1;j<=n;j++){
// cout<<a[j]<<' ';
// }
// cout<<endl;
}
}
}
cout<<ans;
return 0;
}赛后题解:
区间dp
定义为消除到的最大得分。
对于先消掉中间位置,
补题代码:
#include<bits/stdc++.h>
#define int long long
#define ull unsigned long long
#define endl '\n'
using namespace std;
const int N=105;
int n;
int a[N];
int dp[N][N];
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i];
}
for(int i=1; i<=n; i++){
dp[i][i]=a[i-1]+a[i+1];
}
for(int len=2;len<=n;len++){
for(int i=1;i+len-1<=n;i++){
int j=i+len-1;
for(int k=i;k<=j;k++){
dp[i][j]=max(dp[i][j],dp[i][k-1]+dp[k+1][j]+a[i-1]+a[j+1]);
}
}
}
cout<<dp[1][n];
return 0;
}T3: B4339 [中山市赛 2023] 树的改造
本题得分:
初始思路:
没写
考场解题过程:
无
考场代码:
无
赛后题解:
分为两种边
-
原先没有的边
-
原先有的边,在消除的同时恢复即可
然后用LCA做即可
补题代码:
#include<bits/stdc++.h>
#define int long long
#define ull unsigned long long
#define endl '\n'
using namespace std;
const int N=1e6+5;
int n;
int ans;
int val[N],sub[N];
int dep[N];
int st[N][35];
vector<int> G[N];
void pre(int x,int ff){
dep[x]=dep[ff]+1;
st[x][0]=ff;
for(int i=1;i<=30;i++){
st[x][i]=st[st[x][i-1]][i-1];
}
for(int i=0;i<G[x].size();i++){
int v=G[x][i];
if(v==ff){
continue;
}
pre(v,x);
}
}
void dfs(int x,int ff){
val[x]=sub[x];
for(int i=0;i<G[x].size();i++){
int v=G[x][i];
if(v==ff){
continue;
}
dfs(v,x);
val[x]+=val[v];
}
}
int LCA(int x,int y){
if(dep[x]<=dep[y]){
swap(x,y);
}
for(int i=30;i>=0;i--){
if(dep[st[x][i]]>=dep[y]){
x=st[x][i];
}
}
if(x==y){
return x;
}
for(int i=30;i>=0;i--){
if(st[x][i]!=st[y][i]){
x=st[x][i];
y=st[y][i];
}
}
return st[x][0];
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n;
for(int i=1;i<=n-1;i++){
int u,v;
cin>>u>>v;
G[u].push_back(v);
G[v].push_back(u);
}
pre(1,0);
for(int i=1;i<=n-1;i++){
int u,v;
cin>>u>>v;
if(st[u][0]==v||st[v][0]==u){
continue;
}
sub[st[u][0]]++;
sub[st[v][0]]++;
int lca=LCA(u,v);
sub[lca]--;
sub[st[lca][0]]--;
}
dfs(1,0);
for(int i=1;i<=n;i++){
if(val[i]){
ans++;
}
}
cout<<ans;
return 0;
}T4:
本题得分:
初始思路:
类似于埃氏筛,先选出大于等于的完全平方数,然后选出这个完全平方数的倍数标记即可。
考场解题过程:
按思路
考场代码:
#include<bits/stdc++.h>
#define int long long
#define ull unsigned long long
#define endl '\n'
using namespace std;
const int N=1e6+5;
int a,n;
vector<int> p;
void init(int x){
int st=sqrt(x);
for(int i=st;;i++){
if(i*i>=1000001){
break;
}
if(i*i>=a){
p.push_back(i*i);
for(int j=2*i*i;;j+=i*i){
p.push_back(j);
if(j>=1000001){
break;
}
}
}
}
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>a>>n;
init(a);
sort(p.begin(),p.end());
while(n--){
int x;
cin>>x;
int pos=lower_bound(p.begin(),p.end(),x)-p.begin();
if(p[pos]==x){
cout<<"lucky"<<endl;
}else{
cout<<p[pos]<<endl;
}
}
return 0;
} 赛后题解:
雀食可以这样写,
but,
预处理边界约为左右
∴WA了一个点
补题代码:
#include<bits/stdc++.h>
#define int long long
#define ull unsigned long long
#define endl '\n'
using namespace std;
const int N=1e7+5;
int a,n;
vector<int> p;
void init(int x){
int st=1;
for(int i=st;;i++){
if(i*i>=1002005){
break;
}
if(i*i>=a){
p.push_back(i*i);
for(int j=2*i*i;;j+=i*i){
if(j>=1002005){
break;
}
p.push_back(j);
}
}
}
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>a>>n;
init(a);
sort(p.begin(),p.end());
while(n--){
int x;
cin>>x;
int pos=lower_bound(p.begin(),p.end(),x)-p.begin();
if(p[pos]==x){
cout<<"lucky"<<endl;
}else{
cout<<p[pos]<<endl;
}
}
return 0;
}