Educational Codeforces Round 125 (Rated for Div. 2)

比赛链接

Educational Codeforces Round 125 (Rated for Div. 2)

D. For Gamers. By Gamers.

Monocarp is playing a strategy game. In the game, he recruits a squad to fight monsters. Before each battle, Monocarp has C coins to spend on his squad.

Before each battle starts, his squad is empty. Monocarp chooses one type of units and recruits no more units of that type than he can recruit with C coins.
There are n types of units. Every unit type has three parameters:

  • ci - the cost of recruiting one unit of the i-th type;
  • di - the damage that one unit of the i-th type deals in a second;
  • hi - the amount of health of one unit of the i-th type.
    Monocarp has to face m monsters. Every monster has two parameters:
  • Dj - the damage that the j-th monster deals in a second;
  • Hj - the amount of health the j-th monster has.

Monocarp has to fight only the j-th monster during the j-th battle. He wants all his recruited units to stay alive. Both Monocarp's squad and the monster attack continuously (not once per second) and at the same time. Thus, Monocarp wins the battle if and only if his squad kills the monster strictly faster than the monster kills one of his units. The time is compared with no rounding.
For each monster, Monocarp wants to know the minimum amount of coins he has to spend to kill that monster. If this amount is greater than C, then report that it's impossible to kill that monster.

Input

The first line contains two integers n and C(1n3105;1C106) - the number of types of units and the amount of coins Monocarp has before each battle.
The i-th of the next n lines contains three integers ci,di and hi(1ciC;1di,hi106).
The next line contains a single integer m(1m3105) - the number of monsters that Monocarp has to face.
The j-th of the next m lines contains two integers Dj and Hj(1Dj106;1Hj1012).

Output

Print m integers. For each monster, print the minimum amount of coins Monocarp has to spend to kill that monster. If this amount is greater than C, then print 1.

解题思路

二分,思维

设一个单元的血量为 h,攻击为 d,用了 x 个单位,一个怪兽的血量为 H,攻击为 D,则 Hxd<hD,即 x>HDhd,由于总花费 C 较小,可以预处理对于每个花费 i 可以造成的最大的 hd,然后再二分答案即可

  • 时间复杂度:O(nlogn)

代码

// Problem: D. For Gamers. By Gamers. // Contest: Codeforces - Educational Codeforces Round 125 (Rated for Div. 2) // URL: https://codeforces.com/contest/1657/problem/D // Memory Limit: 256 MB // Time Limit: 4000 ms // // Powered by CP Editor (https://cpeditor.org) // %%%Skyqwq #include <bits/stdc++.h> //#define int long long #define help {cin.tie(NULL); cout.tie(NULL);} #define pb push_back #define fi first #define se second #define mkp make_pair using namespace std; typedef long long LL; typedef pair<int, int> PII; typedef pair<LL, LL> PLL; template <typename T> bool chkMax(T &x, T y) { return (y > x) ? x = y, 1 : 0; } template <typename T> bool chkMin(T &x, T y) { return (y < x) ? x = y, 1 : 0; } template <typename T> void inline read(T &x) { int f = 1; x = 0; char s = getchar(); while (s < '0' || s > '9') { if (s == '-') f = -1; s = getchar(); } while (s <= '9' && s >= '0') x = x * 10 + (s ^ 48), s = getchar(); x *= f; } int main() { int n,C; cin>>n>>C; vector<LL> a(C+1,0); for(int i=1;i<=n;i++) { LL c,d,h; cin>>c>>d>>h; a[c]=max(a[c],d*h); } for(int i=1;i<=C;i++) { if(a[i]==0)continue; for(int j=i;j<=C;j+=i)a[j]=max(a[j],j/i*a[i]); } for(int i=1;i<=C;i++)a[i]=max(a[i],a[i-1]); LL m,D,H; cin>>m; while(m--) { cin>>D>>H; D*=H; int p=upper_bound(a.begin(),a.end(),D)-a.begin(); if(p==C+1)cout<<"-1 "; else cout<<p<<' '; } return 0; }

__EOF__

本文作者acwing_zyy
本文链接https://www.cnblogs.com/zyyun/p/16044056.html
关于博主:评论和私信会在第一时间回复。或者直接私信我。
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
声援博主:如果您觉得文章对您有帮助,可以点击文章右下角推荐一下。您的鼓励是博主的最大动力!
posted @   zyy2001  阅读(49)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!
点击右上角即可分享
微信分享提示