Codeforces 1480B. The Great Hero(阅读模拟题,注意数据范围和攻击顺序)
生活随笔
收集整理的這篇文章主要介紹了
Codeforces 1480B. The Great Hero(阅读模拟题,注意数据范围和攻击顺序)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
題意
解題思路
注意
C++ Code (優化后)
#include <bits/stdc++.h> using namespace std; typedef long long ll;int t; ll A, B, n; ll a[100010]; ll b;int main() {ios::sync_with_stdio(false);cin >> t;while (t--) {cin >> A >> B >> n;ll mxA = 0; // 攻擊力最高的怪的攻擊力。 for (int i = 0; i < n; ++i) cin >> a[i], mxA = max(mxA, a[i]);for (int i = 0; i < n; ++i) {cin >> b;B -= (b+A-1)/A*a[i];}// 回退一刀,看最后一刀前英雄的血量是否大于0 B+mxA > 0?puts("YES"):puts("NO");}return 0; }C++ Code (優化前)
#include <bits/stdc++.h> using namespace std; typedef long long ll;int t; ll A, B, n;struct node {ll a;ll b; } arr[100010];bool cmp(node x, node y) {return x.a < y.a; }int main() {ios::sync_with_stdio(false);cin >> t;while (t--) {cin >> A >> B >> n;for (int i = 0; i < n; ++i) {cin >> arr[i].a;}for (int i = 0; i < n; ++i) {cin >> arr[i].b;}// 將怪按攻擊力排序 sort(arr, arr + n, cmp);// 不攻擊最后一只怪 int cost = 0;// 默認可以勝利,通過血量改變標志位 bool flag = true;for (int i = 0; i < n - 1; ++i) {ll num = arr[i].b / A;arr[i].b -= num * A;if (arr[i].b > 0) {num++;arr[i].b -= A;}B -= num * arr[i].a;// 如果血量歸零,則失敗 if (B <= 0){flag = false;break; }}// 特判最后一只怪 int i = n - 1;ll num = arr[i].b / A;arr[i].b -= num * A;if (arr[i].b > 0) {num++;arr[i].b -= A;}B -= num * arr[i].a;// 回退一刀,若最后一刀前血量歸零,則失敗 if (B <= -arr[i].a)flag = false;if (flag)puts("YES");elseputs("NO");}return 0; }總結
以上是生活随笔為你收集整理的Codeforces 1480B. The Great Hero(阅读模拟题,注意数据范围和攻击顺序)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Codeforces 1480A. Ye
- 下一篇: Codeforces 1479A. Se