A monster is attacking the Cyberland!
Master Yang, a braver, is going to beat the monster. Yang and the monster each have 3 attributes: hitpoints (HP), offensive power (ATK) and defensive power (DEF).
During the battle, every second the monster's HP decrease by max(0, ATKY - DEFM), while Yang's HP decreases bymax(0, ATKM - DEFY), where index Y denotes Master Yang and index M denotes monster. Both decreases happen simultaneously Once monster's HP ≤ 0 and the same time Master Yang's HP > 0, Master Yang wins.
Master Yang can buy attributes from the magic shop of Cyberland: h bitcoins per HP, a bitcoins per ATK, and d bitcoins per DEF.
Now Master Yang wants to know the minimum number of bitcoins he can spend in order to win.
The first line contains three integers HPY, ATKY, DEFY, separated by a space, denoting the initial HP, ATK and DEF of Master Yang.
The second line contains three integers HPM, ATKM, DEFM, separated by a space, denoting the HP, ATK and DEF of the monster.
The third line contains three integers h, a, d, separated by a space, denoting the price of 1 HP, 1 ATK and 1 DEF.
All numbers in input are integer and lie between 1 and 100 inclusively.
The only output line should contain an integer, denoting the minimum bitcoins Master Yang should spend in order to win.
1 2 1 1 100 1 1 100 100
99
100 100 100 1 1 1 1 1 1
0
For the first sample, prices for ATK and DEF are extremely high. Master Yang can buy 99 HP, then he can beat the monster with 1 HP left.
For the second sample, Master Yang is strong enough to beat the monster, so he doesn't need to buy anything.
打DIV1真是从头卡落未,差点爆0 , 最后还是过了 。
题意很容易懂。
然后我暴力枚举 3 个变量 初始值 ~ 200 。 过了小数据, 然后被hack 了 。
其实不然 , 因为monster 各个属性最大都是100。
那么Yang的攻击力最多枚举到201就可以秒了monster 。
防御力最多枚举到101就可保证自己滴血不伤 。
然而血量是可以好大的 。
我直接从初始值暴力找上去第一个合法的血量 。
这样都能过,可能数据是弱了。后来想过弄一个10的几次方二分快点。
其实也不用 。 你已经确定了2个值 ,直接通过公式就可以得出血量的下界了。
O(1)时间解决。
3层暴力代码:
#includeusing namespace std;typedef long long LL;const int N = 222;const int inf = 1e9 + 7 ;int a ,b , c , hp1 , ac1 , of1, hp2 , ac2 , of2 ;bool check( int hp , int ac , int of ){ if( ac - of2 <= 0 ) return false ; if( ac2 - of <= 0 ) return true ; if( ceil( (double) hp / ( ac2 - of ) ) > ceil( (double) hp2 / ( ac - of2 ) ) ) return true ; return false ;}int main(){ #ifdef LOCAL freopen("in.txt","r",stdin); #endif // LOCAL ios::sync_with_stdio(false); while( cin >> hp1 >> ac1 >> of1 >> hp2 >> ac2 >> of2 >> a >> b >> c ){ int ans = inf ; if( of1 >= ac2 ) { if( ac1 > of2 ) cout << '0' << endl ; else cout << ( of2 + 1 - ac1 ) * b << endl; break ; } for( int i = max( ac1 , of2 + 1 ) ; i <= 201 ; ++i ) { for( int j = of1 ; j <= ac2 + 1 ; ++j ){ for( int k = hp1 ; ; ++k ){ if( check( k , i , j ) ) { ans = min( ans , ( k - hp1 ) * a + ( i - ac1 ) * b + ( j - of1 ) * c ) ; break ; } } } } cout << ans << endl ; } return 0;}