标签:col == lin case name nbsp init lse efi
题意:有头龙有m个头,有n种砍法。第i种,砍去ai个,再长bi个。某一时刻头为0胜利。要砍几刀。
先找伤害最大(记为d)的刀和效率(maxv=max(ai-bi))最高的刀。如果d<m且maxv<=0则输出-1.否则最后一刀用伤害最大的一定更优。这样m-d的数值都用效率最高的。
//#pragma comment(linker, "/STACK:1024000000,1024000000") #include <iostream> #include <cstdio> #include <cmath> #include <algorithm> #include <vector> #include <iomanip> #include <cstring> #include <map> #include <queue> #include <set> #include <cassert> #include <stack> #include <bitset> #include <unordered_set> #define mkp make_pair using namespace std; const double EPS=1e-8; typedef long long lon; typedef pair<lon,lon> pii ; const lon SZ=100010,SSZ=0,APB=26,INF=0x7FFFFFF,mod=1000000007; lon n; lon m; void init() { cin>>n>>m; lon eff=0,str=0,ok=0; for(lon i=1;i<=n;++i) { lon dec,inc; cin>>dec>>inc; if(dec>=m) { ok=1; } if(dec>inc)ok=1; eff=max(eff,dec-inc); str=max(str,dec); } if(ok==0)cout<<-1<<endl; else { if(str>=m)cout<<1<<endl; else { lon rem=m-str; lon res=rem/eff+(rem%eff!=0)+1; cout<<res<<endl; } } } void work() { } int main() { std::ios::sync_with_stdio(0); //freopen("d:\\1.txt","r",stdin); lon casenum; cin>>casenum; for(lon tim=1;tim<=casenum;++tim) { init(); work(); } return 0; }
codeforces 1217b B - Zmei Gorynich
标签:col == lin case name nbsp init lse efi
原文地址:https://www.cnblogs.com/gaudar/p/11521289.html