본문 바로가기

UCPC

[20/05/17] C. MaratonIME eats japanese food

 

[기억하면 좋을 것들]

 

벡터에서 j번째 값을 지우고 싶다면

v.erase(v.begin() + j);

 

문자 하나를 입력 받을 때 string으로 입력 받고 [0]에 접근하면 실수를 줄일 수 있다.

 

이렇게도 가능하다!

 

pair형 벡터에 값을 넣으려면 v.emplace(x, y);

 

#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <functional>
#include <string>
#include <queue>
#include <stack>
#include <set>
 
using namespace std;
using i64 = long long;
using ii = pair<int, int>;

int     main()
{
    int n;
    char tmp;
    scanf("%d", &n);
    
    vector<ii> pos;
    vector<int> radius;
    for (int i = 0; i < n; i++)
    {
        string type;
        int x, y, r;
        cin >> type >> x >> y >> r;
        
        if (type[0] == 'A')
        {
            bool check = true;
            
            for (int j = 0; j < pos.size(); j++)
            {
                if ((r + radius[j])*(r + radius[j]) > (x - pos[j].first)*(x - pos[j].first) + (y - pos[j].second)*(y - pos[j].second))
                {
                    check = false;
                    break;
                }
            }
            if (check)
            {
                pos.emplace_back(x, y);
                radius.push_back(r);
                printf("Ok\n");
            }
            else
                printf("No\n");
        }
        else
        {
            bool check = false;
            
            for (int j = 0; j < pos.size(); j++)
            {
                if (r == radius[j] && x == pos[j].first && y == pos[j].second)
                {
                    pos.erase(pos.begin() + j);
                    radius.erase(radius.begin() + j);
                    check = true;
                    break;
                }
            }
            if (check)
            {
                printf("Ok\n");
            }
            else
                printf("No\n");
        }
    }

    return 0;
}