Training round (1---5) d

Source: Internet
Author: User

I. Question

Description

Sometimes you have to try fighting even though you know that your enemy is very powerful than you. your hero with initial health H is about to fight against a venomous enemy who has a previous onous value of P. the enemy's poison deals I * P damage at it's ith attacking chance (I> = 1 ). the hero dies when his health becomes <= 0. after enemy's attack, if the hero ves, he heals himself with a health of a by using his skills. then the enemy gets the chance again and the cycle continues till the hero dies. find the interval Val time of the hero. you can safely assume that the hero is mortal.

Example scenario:

Initial health (H) = 10, poison (p) = 2, heal value (A) = 1

At time 1, enemy does 1*2 damage costs the hero's health to 8

At time 2, hero heals himself by 1 increasing his health to 9

At time 3, enemy does 2*2 damage costs the hero's health to 5

At time 4, hero heals himself by 1 increasing his health to 6

At time 5, enemy does 3*2 damage and kill the hero.

The hero specified ved 5 units of time.

Input:

The first line consists of an integer t, the number of test cases. For each test case there is a line with 3 integers H, P and.

Output:

For each test case, find the interval Val time of the hero.

Input constraints:

1 <= T <= 10 ^ 6

1 <= H <= 10 ^ 6

1 <= P <= 10 ^ 6

0 <= A <p

Sample input:

3

3 7 2

81 4 1

87 8 4

Sample output:

1

13

9

 

Ii. program code

#include <cstdio>typedef long long LL;int H,P,A;bool judge(int n){    LL ans = (LL)(n+1)*n/2*P-(LL)(n-1)*A-H;    if(ans >= 0) return 1;    return 0;}int main(){    int kase;    scanf("%d",&kase);    while(kase--)    {        scanf("%d%d%d",&H,&P,&A);        int l = 1,r = 1000000,ans = l;        while(l <= r)        {            int mid = (l+r)>>1;            if(judge(mid))  r = mid-1,ans = mid;            else    l = mid+1;        }        printf("%d\n",ans*2-1);    }    return 0;}

 

Iii. Experiences

This question has always been regarded as a violent question and has timed out.

Just use a second ~~

The time when the second hero died is directly calculated and determined ~~~

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.