中国地质大学(武汉)第十九届程序设计大赛 - D - 弗林戒指

传送门


题意简述: 你可以佩戴 \(n\) 个武器 以及 最多 \(1\) 个饰品, 你拥有 \(m\) 个武器进行选择, 每个武器有三个属性,重量、伤害以及武器的蓄力时间。你只能进行一次攻击,求出你可以杀死 一个 \(100\) 血量 的 \(boss\) 的最小花费时间,如果无论如何也杀不死,输出 \(YOU DIED\)

求最小花费,我们可以利用二分答案来求,容易得出答案是具有单调性的,如果 \(x+1\) 时间可以杀死 \(boss\),那么 \(x\) 时间也一定是可以杀死 \(boss\) 的。

现在我们考虑饰品的问题,饰品的作用是固定的,而且他只会对重量小于等于28的方案造成影响,因此我么只需要对重量小于\(28\)的方案重新计算答案即可。

因此我们每次进行 \(check\) 的时候,就是一个 \(O(100 m)\)\(DP\)

// Problem: 弗林戒指
// Contest: NowCoder
// URL: https://ac.nowcoder.com/acm/contest/35753/D
// Memory Limit: 262144 MB
// Time Limit: 2000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include  <bits/stdc++.h>
using namespace std;
typedef long long ll;

#define rep(i, a, b) for(int i(a); i <= b; i ++)
#define dec(i, a, b) for(int i(a); i >= b; i --)

#ifdef LOCAL
#include <debugger>
#else
#define debug(...) 42
#endif


template <typename T> inline void chkmax(T &x, T y) { x = max(x, y); }
template <typename T> inline void chkmin(T &x, T y) { x = min(x, y); }

void solve() {
  int n, m, H; cin >> n >> m >> H;
  //最多装备n个武器,有m个武器选择
  //H为boss血量 
  //求最短的t杀死boss
  //无论如何杀不死就输出 YOU DIED
  vector<array<int, 3> > a(m);
  //重量之和不超过100
  //伤害为a[1]
  //t为a[2]
  int l = 1, r = 1;
  for(int i = 0; i < m; i ++ ) {
  	cin >> a[i][0] >> a[i][1] >> a[i][2];
  	chkmax(r, a[i][2]);
  }
  
  auto chk = [&] (int x) {
  	vector<int> f(101);
  	for(int i = 0; i < m; i ++ ) {
  		if(a[i][2] > x) continue;
  		for(int j = 100; j >= a[i][0]; j -- ) {
  			chkmax(f[j], f[j - a[i][0]] + a[i][1]);
  		}
  	}
  	//只需要对小于28的选择进行重新计算即可 女少口阿
  	for(int i = 1; i <= 28; i ++ ) {
  		f[i] = floor(1.15 * f[i]);z
  	}
  	int mx = *max_element(f.begin(), f.end());
  	return mx >= H;
  	
  };
  
  while(l < r) {
  	int mid = (l + r) / 2;
  	if(chk(mid)) r = mid;
  	else l = mid + 1;
  }
  
  if(chk(l)) cout << l << "\n";
  else cout << "YOU DIED\n";
  
  
  
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  solve();

  return 0;
}
/*
 *
 *  ┏┓   ┏┓+ +
 * ┏┛┻━━━┛┻┓ + +
 * ┃       ┃
 * ┃   ━   ┃ ++ + + +
 *  ████━████+
 *  ◥██◤ ◥██◤ +
 * ┃   ┻   ┃
 * ┃       ┃ + +
 * ┗━┓   ┏━┛
 *   ┃   ┃ + + + +Code is far away from  
 *   ┃   ┃ + bug with the animal protecting
 *   ┃    ┗━━━┓ 神兽保佑,代码无bug 
 *   ┃        ┣┓
 *    ┃        ┏┛
 *     ┗┓┓┏━┳┓┏┛ + + + +
 *    ┃┫┫ ┃┫┫
 *    ┗┻┛ ┗┻┛+ + + +
 */
posted @ 2022-06-09 23:12  ccz9729  阅读(65)  评论(0编辑  收藏  举报