当前位置: 代码迷 >> 综合 >> ACdream 1073 - 雷霆战机
  详细解决方案

ACdream 1073 - 雷霆战机

热度:53   发布时间:2023-12-24 11:17:44.0

题目大意:中文题

解题思路:根据风风的习惯,就是如果有能够升一星的就选能升一星的最低经验球,否则就选经验最大的使用。看懂以后就明白了,先排序,然后用贪心模拟风风的做法。

ac代码:

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
int main()
{int n, level[4], ex[1005], vis[1005], cnt, pos;while (scanf("%d", &n)!=EOF){cnt = 0;for (int i=0; i<4; i++)scanf("%d", &level[i]);for (int i=0; i<n; i++){scanf("%d", &ex[i]);vis[i] = 1;			}sort(ex, ex+n);while (cnt < 4){while (1){pos = 0;for (int i=0; i<n; i++)pos += vis[i];for (int i=0; i<n; i++)if (vis[i]){if (ex[i] >= level[cnt]){pos = i + 1;break;}pos = i + 1;}if (pos){level[cnt] -= ex[pos - 1];vis[pos-1] = 0;					}if (level[cnt] <= 0 || !pos){cnt++;break;}}}for (int i=0; i<4; i++){if (level[i] > 0)cnt = 0;			}if (cnt){cnt = 0;for (int i=0; i<n; i++)if (vis[i])cnt += ex[i];printf("YES %d\n", cnt);		}elseprintf("NO\n");}
return 0;
}