救,写的算法不知道是什么算法

P1047 [NOIP2005 普及组] 校门外的树

nibuxvyaozhidao @ 2023-11-17 19:37:26

#include <bits/stdc++.h>
using namespace std;
#define DEBUGOUTPUT 0
int main()
{
    vector<pair<int, int>> qvjian;
    int maxs, itimes;
    cin >> maxs >> itimes;
    for (int i = 0; i < itimes; i++)
    {
        int a, b;
        cin >> a >> b;
        auto j = qvjian.begin();
        for (; j != qvjian.end(); j++)
        {
            if (a <= j->first && b >= j->second)
            {
                if (DEBUGOUTPUT)
                    cout << "{" << j->first << "," << j->second << "}->";
                j->first = a;
                j->second = b;
                if (DEBUGOUTPUT)
                    cout << "{" << j->first << "," << j->second << "}\n";
                break;
            }
            else if (a >= j->first && b <= j->second)
            {
                if (DEBUGOUTPUT)
                    cout << "not inserted\n";
                break;
            }
            else if (b >= j->first && a <= j->first)
            {
                if (DEBUGOUTPUT)
                    cout << "{" << j->first << "," << j->second << "}->";
                j->first = a;
                if (DEBUGOUTPUT)
                    cout << "{" << j->first << "," << j->second << "}\n";
                break;
            }
            else if (a <= j->second && b >= j->second)
            {
                if (DEBUGOUTPUT)
                    cout << "{" << j->first << "," << j->second << "}->";
                j->second = b;
                if (DEBUGOUTPUT)
                    cout << "{" << j->first << "," << j->second << "}\n";
                break;
            }
        }
        if (j == qvjian.end())
        {
            qvjian.push_back(make_pair(a, b));
            if (DEBUGOUTPUT)
                cout << "inserted {" << a << "," << b << "}\n";
        }
        else
        {
            auto j2 = qvjian.begin();
            for (; j2 != qvjian.end(); j2++)
            {
                if (j == j2)
                {
                    continue;
                }
                if (j->first <= j2->first && j->second >= j2->second)
                {
                    if (DEBUGOUTPUT)
                        cout << "{" << j2->first << "," << j2->second << "}->";
                    j2->first = j->first;
                    j2->second = j->second;
                    if (DEBUGOUTPUT)
                        cout << "{" << j2->first << "," << j2->second << "}\n";
                    break;
                }
                else if (j->first >= j2->first && j->second <= j2->second)
                {
                    if (DEBUGOUTPUT)
                        cout << "not merged\n";
                    break;
                }
                else if (j->second >= j2->first && j->first <= j2->first)
                {
                    if (DEBUGOUTPUT)
                        cout << "{" << j2->first << "," << j2->second << "}->";
                    j2->first = j->first;
                    if (DEBUGOUTPUT)
                        cout << "{" << j2->first << "," << j2->second << "}\n";
                    break;
                }
                else if (j->first <= j2->second && j->second >= j2->second)
                {
                    if (DEBUGOUTPUT)
                        cout << "{" << j2->first << "," << j2->second << "}->";
                    j2->second = j->second;
                    if (DEBUGOUTPUT)
                        cout << "{" << j2->first << "," << j2->second << "}\n";
                    break;
                }
            }
            if (j2 != qvjian.end())
            {
                qvjian.erase(j);
            }
        }
    }
    if (DEBUGOUTPUT)
    {
        for (int i = 0; i < qvjian.size(); i++)
        {
            cout << "{" << qvjian[i].first << "," << qvjian[i].second << "},";
        }
        cout << endl;
    }
    int anx = maxs + 1;
    for (int i = 0; i < qvjian.size(); i++)
    {
        anx -= qvjian[i].second - qvjian[i].first + 1;
    }
    cout << anx;
    return 0;
}

我不知道我写的什么算法(我乱写的,但能AC)


by nibuxvyaozhidao @ 2023-11-17 19:39:13

我当时以为模拟会MLE,所以写了这个答辩算法


by zhongshizhao1 @ 2023-11-17 20:02:52

请问阁下为什么不开个数组统计,怎么会MLE?而且这是个入门题,你这个算法不好评价


by nibuxvyaozhidao @ 2023-11-17 20:06:54

@zhongshizhao1 我以为会MLE是因为我没看数据范围。


by Kaikai23 @ 2023-11-17 20:10:03

啊这这这。。。

也泰你普勒巴
(也太离谱了吧)

源代码:

**啊这这这。。。**

|~~**_也泰你普勒巴_**~~|
|:-:|
|**(也太离谱了吧)**|

by zhongshizhao1 @ 2023-11-17 20:13:51

已阅


by xyy_xxyy @ 2023-11-18 14:40:54

6


|