2026.8.9 模拟赛4
2026.8.9 模拟赛4
一、比赛基本情况
比赛日期:2026.8.9
比赛时长:
比赛得分:
比赛排名:
二、比赛整体回顾
开题顺序:
三、题目复盘
T1: [USACO22DEC] Cow College B
本题得分:100pts!!!
I AC T1!!!
T2: P7911 [CSP-J 2021] 网络连接
本题得分:65pts
初始思路:
模拟
考场解题过程:
模拟
考场代码:
#include<bits/stdc++.h>
#define int long long
#define ull unsigned long long
#define endl '\n'
using namespace std;
const int N=1005;
int n;
string lx,s;
map<string,int> mp;
signed main(){
// freopen("network.in","r",stdin);
// freopen("network.out","w",stdout);
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n;
for(int ask=1;ask<=n;ask++){
cin>>lx>>s;
s='#'+s+'#';
int len=s.size();
bool allzero=0,numflag=0,zero=1;
int id=1,num=0,dian=0,mao=0;
for(int i=1;i<=len;i++){
if(s[i]>='0'&&s[i]<='9'){
num=num*10+(s[i]-'0');
zero=(zero&&i==0);
}else if(s[i]=='.'){
dian++;
if(zero==1){
allzero=1;
}
if((id<=4&&num>255)||(id==5&&num>65535)){
numflag=1;
}
id++;
zero=1;
num=0;
}else if(s[i]==':'){
mao++;
if(zero==1){
allzero=1;
}
if((id<=4&&num>255)||(id==5&&num>65535)){
numflag=1;
}
id++;
zero=1;
num=0;
}else{
if((id<=4&&num>255)||(id==5&&num>65535)){
numflag=1;
}
}
}
// cout<<allzero<<' '<<numflag<<' '<<id<<' '<<dian<<' '<<mao;
if(allzero==1||numflag==1||id!=5||dian!=3||mao!=1){
cout<<"ERR"<<endl;
continue;
}
if(lx=="Server"){
if(mp[s]==0){
mp[s]=ask;
cout<<"OK"<<endl;
}else{
cout<<"FAIL"<<endl;
}
}else{
if(mp[s]!=0){
cout<<mp[s]<<endl;
}else{
cout<<"FAIL"<<endl;
}
}
}
return 0;
}
//20min
赛后题解:
模拟
补题代码:
#include<bits/stdc++.h>
// #define int long long
// #define ull unsigned long long
#define endl '\n'
using namespace std;
int n;
string lx,s;
map<string,int> mp;
bool ck1(int x){
return x>=0&&x<=255;
}
bool ck2(int x){
return x>=0&&x<=65535;
}
int get(int x){
int cnt=0;
if(x==0){
return 1;
}
while(x!=0){
cnt++;
x/=10;
}
return cnt;
}
bool check(string s){
int a,b,c,d,e;
if(sscanf(s.c_str(),"%d.%d.%d.%d:%d",&a,&b,&c,&d,&e)!=5){
// cout<<a<<' '<<b<<' '<<c<<' '<<d<<' '<<e;
return 0;
}
if(ck1(a)==0||ck1(b)==0||ck1(c)==0||ck1(d)==0||ck2(e)==0){
// cout<<ck1(a)<<' '<<ck1(b)<<' '<<ck1(c)<<' '<<ck1(d)<<' '<<ck2(e);
// cout<<a<<' '<<b<<' '<<c<<' '<<d<<' '<<e;
return 0;
}
return get(a)+get(b)+get(c)+get(d)+get(e)+4==s.size();
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n;
for(int i=1;i<=n;i++){
cin>>lx>>s;
if(check(s)==0){
cout<<"ERR"<<endl;
continue;
}
if(lx=="Server"){
if(mp[s]!=0){
cout<<"FAIL"<<endl;
}else{
cout<<"OK"<<endl;
}
if(mp[s]==0){
mp[s]=i;
}
}else{
if(mp[s]==0){
cout<<"FAIL"<<endl;
}else{
cout<<mp[s]<<endl;
}
}
}
// check("192.168.1.1:8080");
return 0;
}
//20min
T3: P2466 [SDOI2008] Sue 的小球
本题得分:0pts
初始思路:
没写
考场解题过程:
无
考场代码:
无
赛后题解:
一道dp题。
定义
初始思路:
树形dp,没跳出来
考场解题过程:
树形dp
考场代码:
无
赛后题解:
dp
定义
不难发现,一个子树的最大毛毛虫节点个数就等于这个子树(不包括根节点)的最大毛毛虫节点个数和次大毛毛虫节点个数用根节点连起来并加上根节点其他的孩子个数。
补题代码:
#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,m;
int ans=-1e18;
vector<int> G[N];
int dp[N];
void pre(int x,int ff){
if(G[x].size()==1&&x!=1){
dp[x]=1;
return ;
}
int maxi=0;
for(int i=0;i<G[x].size();i++){
int v=G[x][i];
if(v==ff){
continue;
}
pre(v,x);
maxi=max(maxi,dp[v]);
}
if(x==1){
dp[x]=maxi+G[x].size();
}else{
dp[x]=maxi+G[x].size()-1;
}
}
void dfs(int x,int ff){
if(G[x].size()==1&&x!=1){
ans=max(ans,1ll);
return ;
}
int maxi=0;
int caxi=0;
for(int i=0;i<G[x].size();i++){
int v=G[x][i];
if(v==ff){
continue;
}
dfs(v,x);
if(dp[v]>maxi){
caxi=maxi;
maxi=dp[v];
}else if(dp[v]>caxi){
caxi=dp[v];
}
}
if(maxi==0){
ans=max(ans,1ll);
}else if(caxi==0){
ans=max(ans,maxi+1);
}else{
ans=max(ans,(int)(maxi+caxi+G[x].size()-1));
}
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n>>m;
for(int i=1;i<=m;i++){
int u,v;
cin>>u>>v;
G[u].push_back(v);
G[v].push_back(u);
}
pre(1,1);
dfs(1,1);
cout<<ans;
return 0;
}