-
Cap Size - 17659Algorithm/BOJ 2020. 2. 28. 18:55123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104//17659 - cap size#include <iostream>using namespace std;int N, K;bool arr[1001];int lower, upper;int obv;void init(){cin >> N >> K;obv = -1for (int i = 0; i < 1001; ++i)arr[i] = false;int x;for (int i = 0; i < N; ++i){cin >> x;arr[x] = true;}lower = -1;upper = 100000;}void solve(int C){int x, y;int flag = true;for (int i = 0; i < K; ++i){cin >> x >> y;if (flag){if (y == 1){if (upper <= x){flag = false;continue;}if (lower < x)lower = x;}else if (y == -1){if (lower >= x){flag = false;continue;}if (upper > x)upper = x;}else{if (obv == -1 && x > lower && x < upper)obv = x;else if (obv == x)obv = x;else{flag = false;continue;}}}}cout << "Data Set " << C << ":\n";if (!flag){cout << "Inconsistent feedback\n\n";return;}int ans = 0;if (obv != -1)if (obv > lower && obv < upper){cout << 1 << "\n\n";return;}else{cout << "Inconsistent feedback\n\n";return;}for (int i = lower + 1; i < upper; ++i)if (arr[i])++ans;cout << ans << "\n\n";}int main(){int C;cin >> C;for (int tn = 0; tn < C; ++tn){init();solve(tn + 1);}}
cs https://www.acmicpc.net/problem/17659
17659번: Cap Size
Picking the right size of your cap is surprisingly difficult. If your cap is too small, it keeps digging into your head, or — even worse — you can’t even get it over your computer science filled head. And if it is too large, it keeps wiggling, and you know
www.acmicpc.net
Cap Size
예외처리만 잘 해주면 되는 문제 입니다.
'Algorithm > BOJ' 카테고리의 다른 글
동전 1 - 2293 (0) 2020.03.01 GPA - 17662 (0) 2020.02.28 Mangling Names - 17661 (0) 2020.02.28 계단 수 - 1562 (0) 2020.02.26 10844 - 쉬운 계단 수 (0) 2020.02.26