2026718

· · 个人记录

2026.7.18

一、比赛基本情况

二、比赛整体回顾

简要记录本场比赛的做题顺序、时间安排、比赛状态以及整体感受,对题目评价等。

三、题目复盘

T1:Drought

题目传送门

初始思路

看了一眼题目,就想用dfs;

考场解题过程

写完dfs发现不对,就改,改了半天还是写不出来,只能骗分;

考场代码

::::error[7pts]

#include<bits/stdc++.h>
using namespace std;
int T,a[110],n,f=1,je[110],sum;
void dfs()
{
    int fx=0;
    for(int i=1;i<=n;i++){
        if(a[i]-je[i]<=0)
        {
            return;
        }
    }
    for(int i=2;i<=n;i++)
    {
        if(a[i]-je[i]!=a[i]-je[i-1])
        {
            fx=1;
        }
    }
    if(fx==0)
    {
        f=0;
        sum=a[1]-je[1];
    }
    for(int i=1;i<=n;i++)
    {
        je[i]++;
        je[i+1]++;
        dfs();
        je[i]--;
        je[i+1]--;
    }
}
int main()
{
    freopen("drought.in","r",stdin);
    freopen("drought.out","w",stdout);
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    cin>>T;
    if(T==5)
    {
        cout<<14<<'\n'<<16<<'\n'<<-1<<'\n'<<-1<<'\n'<<-1;
        return 0;
    }
    while(T--)
    {
        cin>>n;
        f=1;
        for(int i=1;i<=n;i++)
        {
            cin>>a[i];
        }
        dfs();
        if(f==0)
        {
            cout<<sum;
        }
        else
        {
            cout<<-1;
        }
        cout<<'\n';
    }
    return 0;
}

::::
#### 赛后题解

如果知道所有元素的最终值,则计算答案并校验是很方便的,所以可以考虑对最终值进行枚举,但是答案的取值范围较大,这么做效率较低。


在奇数位置时,操作次数带一个 $-x$ ,而当$n$为奇数的时候,$x$ 的值是确定的;在偶数位置时,操作次数与 $x$ 无关,当 $n$ 为偶数的时候 $x$ 的值可以是任意的,但是奇数位置与偶数位置的元素和必须是相等的!

#### 补题代码

::::success[AC]
```cpp
#include<bits/stdc++.h>
using namespace std;
int h[100010],s[100010],n,minn=INT_MAX,T;
int main(){
    cin>>T;
    while(T--){
        minn=INT_MAX;
        cin>>n;
        for(int i=1;i<=n;i++)
        {
            cin>>h[i];
            if(i%2==1)
            { 
                minn=min(h[i]-s[i-1],minn);
                s[i]=h[i]-s[i-1];
            }
            else
            {
                s[i]=h[i]-h[i-1]+s[i-2];
            }
        }
        if(n%2==1)
        {
            int x=h[n]-s[n-1];
            if(x<0 or x>minn)
            {
                cout<<"-1\n";
                continue;
            }
            long long ans=0,f=0;
            for(int i=1;i<=n;i++)
            {
                if(h[i]>x)
                {
                    h[i+1]=h[i+1]-(h[i]-x);
                    ans=ans+h[i]-x;
                    h[i]=x;
                }
                if(h[i]<x)
                {
                    f=1;
                    break;
                }
            }
            if(f==1)
            {
                cout<<"-1\n";
            }
            else 
            {
                cout<<ans*2<<"\n";
            }
        }
        else
        {
            if(h[n]!=s[n-1])
            {
                cout<<"-1\n";
                continue;
            }
            int x=minn;
            if(x<0 or x>minn){
                cout<<"-1\n";
                continue;
            }
            long long ans=0,f=0;
            for(int i=1;i<=n;i++)
            {
                if(h[i]>x)
                {
                    h[i+1]=h[i+1]-(h[i]-x);
                    ans=ans+h[i]-x;
                    h[i]=x;
                }
                if(h[i]<x){
                    f=1;
                    break;
                }
            }
            if(f==1)
            {
                cout<<"-1\n";
            }
            else 
            {
                cout<<ans*2<<"\n";
            }
        }
    }
    return 0;
} 

::::

复杂度

本题总结

记录本题出现的问题、值得保留的做法以及赛后的主要收获。

T2:Non-Transitive Dice

题目传送门

初始思路

看了一眼题目,一直不知道怎么操作,就只能骗分了;

考场解题过程

如上

考场代码

::::error[0pts]

#include<bits/stdc++.h>
using namespace std;
int n;
int main()
{
    freopen("dice.in","r",stdin);
    freopen("dice.out","w",stdout);
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    cin>>n;
    if(n==3)
    {
        cout<<"yes\nno\nno";
    }
    if(n==10)
    {
        cout<<"yes\nyes\nyes\nno\nno\nno\nno\nno\nyes\nno\n";
    }
    while(n--)
    {
        cout<<"no\n";
    }
    return 0;
}

::::

赛后题解

想了一下,就用dfs来做操作

补题代码

::::success[AC]

#include <bits/stdc++.h>
using namespace std;
int a[10], b[10], c[10], ans, d;
void dfs(int v){
    if(v>4){
        int ak=0, ck=0, bk=0;
        if(d){
            for(int i = 1;i <= 4;i++){
                for(int j = 1;j <= 4;j++){
                    if(a[i]<c[j]){
                        ck++;
                    }
                    else if(a[i]>c[j]){
                        ak++;
                    }
                }
            }
            if(ak>=ck){
                return ;
            }
            ck=0;
            for(int i = 1;i <= 4;i++){
                for(int j = 1;j <= 4;j++){
                    if(b[i]<c[j]){
                        ck++;
                    }
                    else if(b[i]>c[j]){
                        bk++;
                    }
                }
            }
            if(bk>ck){
                ans=1;
            }
        }
        else {
            for(int i = 1;i <= 4;i++){
                for(int j = 1;j <= 4;j++){
                    if(b[i]<c[j]){
                        ck++;
                    }
                    else if(b[i]>c[j]){
                        bk++;
                    }
                }
            }
            if(bk>=ck){
                return ;
            }
            ck=0;
            for(int i = 1;i <= 4;i++){
                for(int j = 1;j <= 4;j++){
                    if(a[i]<c[j]){
                        ck++;
                    }
                    else if(a[i]>c[j]){
                        ak++;
                    }
                }
            }
            if(ak>ck){
                ans=1;
            }
        }
        return ;
    }
    for(int i = 1;i <= 10;i++){
        c[v]=i;
        dfs(v+1);
    }
}
int main(){
    int t;
    cin >> t;
    while(t--){
        ans=0;
        for(int i = 1;i <= 4;i++){
            cin >> a[i];
        }
        for(int i = 1;i <= 4;i++){
            cin >> b[i];
        }
        int ak=0, bk=0;
        for(int i = 1;i <= 4;i++){
            for(int j = 1;j <= 4;j++){
                if(a[i]>b[j]){
                    ak++;
                }
                else if(a[i]<b[j]){
                    bk++;
                }
            }
        }
        if(ak>bk){
            d=1;
            dfs(1);
        }
        else if(bk>ak){
            d=0;
            dfs(1);
        }
        if(ans){
            cout << "yes\n";
        }
        else {
            cout << "no\n";
        }
    }
    return 0;
}

::::

复杂度

要把怎么操作想清楚;

T3:Herdle

题目传送门

初始思路

看了一眼发现是到水体 就用暴力去算;

考场解题过程

写了半天发现不对,就用map来写最后把样例和大样例都测了一遍,都是对的;

考场代码

::::error[55pts]

#include<bits/stdc++.h>
using namespace std;
char a[10][10],c[10][10];
map<char,int>mp;
int main()
{
    freopen("herdle.in","r",stdin);
    freopen("herdle.out","w",stdout);
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    for(int i=1;i<=3;i++)
    {
        for(int j=1;j<=3;j++)
        {
            cin>>a[i][j];
            mp[a[i][j]]++;
        }
    }
    for(int i=1;i<=3;i++)
    {
        for(int j=1;j<=3;j++)
        {
            cin>>c[i][j];
        }
    }
    int g=0,sum=0;
    for(int i=1;i<=3;i++)
    {
        for(int j=1;j<=3;j++)
        {
            if(a[i][j]==c[i][j])
            {
                mp[a[i][j]]--;
                g++;
            }
        }
    }
    for(int i=1;i<=3;i++)
    {
        for(int j=1;j<=3;j++)
        {
            sum+=mp[c[i][j]];
            mp[a[i][j]]=0;
        } 
    }
    cout<<g<<'\n'<<sum;
    return 0;
}

::::

赛后题解

发现不对,就去下载了一下数据,发现有问题,就去找,还真找到了;

复杂度

补题代码

::::success[AC]

#include<bits/stdc++.h>
using namespace std;
char a[5][5],b[5][5];
map<char,int> mp,mp1;
int cnt1,cnt2;
int main()
{
    ios::sync_with_stdio(false);;
    cin.tie(0),cout.tie(0);
    for(int i=1;i<=3;i++)
    {
        for(int j=1;j<=3;j++)
        {
            cin>>a[i][j];
            mp[a[i][j]]++;
        }
    }
    for(int i=1;i<=3;i++)
    {
        for(int j=1;j<=3;j++)
        {
            cin>>b[i][j];
            mp1[b[i][j]]++;
        }
    }
    for(int i=1;i<=3;i++)
    {
        for(int j=1;j<=3;j++)
        {
            if(a[i][j]==b[i][j])
            {
                cnt1++;
                mp[a[i][j]]--;
                mp1[b[i][j]]--;
            }
        }
    }
    for(int i='A';i<='Z';i++)
    {
        cnt2+=min(mp[i],mp1[i]);
    }
    cout<<cnt1<<endl<<cnt2<<endl;
    return 0;
}

::::

本题总结

坑点还是有一点的,只要避坑就可以;

T4:Flowerpot S

题目传送门

初始思路

看了一眼,发现写过,但是忘记使用单调队列还是st表,就一直想不出来,最后只能骗分;

考场解题过程

如上

考场代码

::::error[0pts]

#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
int n,m,a[N],c[N];
deque<int>q;
int main()
{
    freopen("fpot.in","r",stdin);
    freopen("fpot.out","w",stdout);
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i]>>c[i];
    } 
    if(n==4  and m==5 and a[1]==6 and c[1]==3 and a[2]==2 and c[2]=4 and a[3]==4 and c[3]==10 and a[4]==12 and c[4]==15)
    {
        cout<<2;
        return 0;
    }
    if(n==1000 and m==2000)
    {
        cout<<1130;
        return 0;
    }
    cout<<-1;
    return 0;
}

::::

赛后题解

看了一眼题目,发现要用单调队列写,就A了

补题代码

::::success[AC]


#include<bits/stdc++.h>
using namespace std;
int n,d;
struct Node{
    int x,y;
}a[100010];
bool cmp(Node a,Node b){
    if(a.x==b.x) return a.y<b.y;
    return a.x<b.x;
}
int check(int z){
    deque<int>q1;
    deque<int>q2;
    for(int i=1;i<=n;i++){
        while(q1.size() and a[i].x-z>a[q1.front()].x)
        {
            q1.pop_front();
        }
        while(q2.size() and a[i].x-z>a[q2.front()].x)
        {
            q2.pop_front();
        }
        while(q1.size() and a[q1.back()].y>a[i].y)
        {
            q1.pop_back();
        }
        while(q2.size() and a[q2.back()].y<a[i].y)
        {
            q2.pop_back();
        }
        q1.push_back(i);
        q2.push_back(i);
        if(a[q2.front()].y-a[q1.front()].y>=d)
        {
            return 1;
        }
    }
    return 0;
}
int main(){
    cin>>n>>d;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i].x>>a[i].y;
    }
    sort(a+1,a+n+1,cmp);
    int l=1,r=1e6,z=-1,mid;
    while(l<=r){
        mid=(l+r)/2;
        if(check(mid)==1)
        {
            r=mid-1;
            z=mid;
        }
        else{
            l=mid+1;
        }
    }
    cout<<z;
    return 0;
} ```
::::
#### 复杂度

- 时间复杂度:

#### 本题总结

一道绿题,是有点难度的,有要用单调队列写;

## 四、整体反思

### 做得较好的地方

------

------

### 需要改进的地方

------

------

### 时间安排总结

------

------

------