오늘 다 할 생각이었는데 에바였다 ㅎㅎ
내일 ucpc도 있으니 종강 후 돌아오겠음
종강 했다! 26일날 딱 맞춰 돌아왔네ㅋㅋ
이 문제는 여러번 틀림ㅋㅋ..
처음에는 문제 이해 잘못해서 n 순서대로 처리하는 줄 알았는데 그냥 n개의 공격 type 중에서 공격하면 된다.
이걸 늦게 알아서 코드 다 짜고 다시 다 지움 ㅂㄷ
공격 횟수를 최소한으로 하려면 d-h 가 가장 큰 공격만 공격하면 된다.
그래서 pair로 값을 받은 뒤 d-h가 가장 큰 걸 선택해서 공격했다.
이거 딱 보니 달팽이 문제라서 그냥 비슷하게 풀었다. 근데 틀림ㅋㅋㅋ
내가 놓친 부분이 있었는데 이거 막타는 h를 생각 안 해도 된다.
막타를 가장 큰 걸로 치면 값이 최소가 됨!
그래서 맨 처음 막타를 계산하는 조건을 추가했다.
그래도 틀렸는데 (ㅎㅎ) 이거 조건 생각없이 달팽이 조건 그대로 들고와서 문제였다.
차분히 조건 다시 구해서 넣었더니 이번에는 맞았음 예헤이~
내가 맞아서 그런 건 아니고 이게 왜 E번이지? C번 같은 E번이었음
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <functional>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#define xx first
#define yy second
using namespace std;
using i64 = long long;
using ii = pair<int, int>;
using ii64 = pair<i64, i64>;
int main() {
int t;
scanf("%d", &t);
for (int i = 0; i < t; i++)
{
i64 n, x;
scanf("%lld %lld", &n, &x);
vector <ii64> v(n);
for (int j = 0; j < n; j++)
scanf("%lld %lld", &v[j].first, &v[j].second);
i64 max_val = v[0].first;
int max_idx = 0;
for (int j = 1; j < n; j++)
{
if((v[j].first - v[j].second) > (v[max_idx].first - v[max_idx].second))
max_idx = j;
if(v[j].first > max_val)
max_val = v[j].first;
}
x -= max_val;
if (x <= 0)
{
printf("1\n");
continue;
}
if (v[max_idx].first - v[max_idx].second <= 0)
printf("-1\n");
else
printf("%lld\n", (x+v[max_idx].first-v[max_idx].second-1)/(v[max_idx].first-v[max_idx].second)+1);
}
return 0;
}
이건 북님 코드
solve() 빼는 거 좋은듯
j, k를 안 써도 된다는 게 특히.. 계속 j를 i로 쓰고있음
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <functional>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#define xx first
#define yy second
using namespace std;
using i64 = long long;
using ii = pair<int, int>;
using ii64 = pair<i64, i64>;
void solve()
{
int n, x;
scanf("%d %d", &n, &x);
vector<ii> v(n);
int maxD = 0;
int maxG = 0;
for (int i = 0; i < n; i++)
{
scanf("%d %d", &v[i].xx, &v[i].yy);
maxD = max(v[i].xx, maxD);
maxG = max(v[i].xx-v[i].yy, maxG);
}
if (maxD >= x)
{
printf("1\n");
return ;
}
if (maxG == 0)
{
printf("-1\n");
return ;
}
printf("%d\n", (x - maxD + maxG -1)/maxG + 1);
}
int main() {
int t;
scanf("%d", &t);
for (int i = 0; i < t; i++)
{
solve();
}
return 0;
}
'코드포스' 카테고리의 다른 글
[코드포스 Practice22] 후기 (0) | 2020.07.04 |
---|---|
[코드포스 Practice21] D. Anu Has a Function (0) | 2020.06.26 |
[코드포스 Practice21] C. Little Artem and Matrix (0) | 2020.06.06 |
[코드포스 Practice21] B. Alice and Hairdresser (0) | 2020.06.06 |
[코드포스 Practice21] A. K-th Not Divisible by n (0) | 2020.06.06 |