[백준/BOJ] 2457. 공주님의 정원 [Gold 3]

jychan99·2022년 5월 1일
0
post-thumbnail
  1. 공주님의 정원

문제출처 : https://www.acmicpc.net/problem/2457

참고블로그 출처 : https://j3sung.tistory.com/508

code

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

bool compare(const pair<int, int> &a, const pair<int, int> &b)
{
    if (a.first == b.first)
        return a.second > b.second;
    return a.first < b.first;
}
int main()
{
    ios::sync_with_stdio(false);

    int N, i, result = 0, start = 300, end = 301, day = 301;
    bool flag = true;
    cin >> N;
    vector<pair<int, int>> flower(N);

    for (i = 0; i < N; i++)
    {
        int bloom_month, bloom_day, fall_month, fall_day;
        cin >> bloom_month >> bloom_day >> fall_month >> fall_day;

        flower[i].first = bloom_month * 100 + bloom_day;
        flower[i].second = fall_month * 100 + fall_day;
    }

    for (int i = 0; i < N; i++)
    {
        if (flower[i].first < 301)
            flower[i].first = 301;
        if (flower[i].second > 1201)
            flower[i].second = 1201;
    }

    sort(flower.begin(), flower.end());

    for (int i = 0; i < N; i++)
    {
        if (flower[i].first>start && flower[i].first<= end)
        {
            if (day < flower[i].second)
                day = flower[i].second;
            if (flower[i].second == 1201)
            {
                result++;
                end = 1201;
                break;
            }
            continue;
        }
        else
        {
            if (end >= day)
                break;
        }
        result++;
        start = end;
        end = day;
        i--;
    }
    if (end == 1201)
        cout << result;
    else
        cout << 0;
    
    return 0;
}

한 이틀고민했는데, 하나에서 자꾸 막혀서 못풀었다 ㅠㅠ
하는 수 없이 블로그에쳐서 봤는데, 내가 한거랑 거의 비슷했다.근데 나는 start end변수를 쓸생각을 못했다... 변수 몇개 더 쓰는생각을 왜하지 못했던걸까.. ㅠㅠ

저번에도 블로그참고해서 이번에는 진짜 내실력으로 풀어보려고 노력했는데ㅠㅠ 너무 분하다.
다음에 더 재밌는 문제로 내가 직접 풀어봐야겠다.

profile
내가 지금 두려워 하고 있는 일이 바로 내가 지금 해야 할 일이다. 🐥

0개의 댓글