Problem Description
Have you ever played the Warcraft?It doesn't matter whether you have played it !We will give you such an experience.There are so many Heroes in it,but you could only choose one of them.Each Hero has his own skills.When such a Skill is used ,it costs some MagicValue,but hurts the Boss at the same time.Using the skills needs intellegence,one should hurt the enemy to the most when using certain MagicValue.
Now we send you to complete such a duty to kill the Boss(So cool~~).To simplify the problem:you can assume the LifeValue of the monster is 100, your LifeValue is 100,but you have also a 100 MagicValue!You can choose to use the ordinary Attack(which doesn't cost MagicValue),or a certain skill(in condition that you own this skill and the MagicValue you have at that time is no less than the skill costs),there is no free lunch so that you should pay certain MagicValue after you use one skill!But we are good enough to offer you a "ResumingCirclet"(with which you can resume the MagicValue each seconds),But you can't own more than 100 MagicValue and resuming MagicValue is always after you attack.The Boss is cruel , be careful!
Input
There are several test cases,intergers n ,t and q (0<n<=100,1<=t<=5,q>0) in the first line which mean you own n kinds of skills ,and the "ResumingCirclet" helps you resume t points of MagicValue per second and q is of course the hurt points of LifeValue the Boss attack you each time(we assume when fighting in a second the attack you show is before the Boss).Then n lines follow,each has 2 intergers ai and bi(0<ai,bi<=100).which means using i skill costs you ai MagicValue and costs the Boss bi LifeValue.The last case is n=t=q=0.
Output
Output an interger min (the minimun time you need to kill the Boss)in one line .But if you die(the LifeValue is no more than 0) ,output "My god"!
Sample Input
4 2 25
10 5
20 10
30 28
76 70
4 2 25
10 5
20 10
30 28
77 70
0 0 0
Sample Output
4
My god
Hint
Hint: When fighting,you can only choose one kind of skill or just to use the ordinary attack in the whole second,the ordinary attack costs the Boss 1 points of LifeValue,the Boss can only use ordinary attack which costs a whole second at a time.Good Luck To You!
#include<stdio.h>
#include<string.h>
int n,t,q;
int skillCost[110];
int skillhurt[110];
int dp[110];//dp[i][j]表示第i轮攻击,boss还剩下j滴hp时候剩下的最大mp
int max(int a,int b)
{
return a>b?a:b;
}
int main()
{
while(scanf("%d%d%d",&n,&t,&q))
{
if(n==0&&t==0&&q==0){break;}
int T;
if(100%q!=0)
{
T=100/q+1;
}else
{
T=100/q;
}
memset(dp,-1,sizeof(dp));
dp[100]=100;
int i,j,k;
for(i=1;i<=n;i++)
{
scanf("%d%d",&skillCost[i],&skillhurt[i]);
}
skillCost[0]=0;
skillhurt[0]=1;
bool flag=false;
for(i=1;i<=T;i++)
{
for(j=1;j<=100;j++)
{
if(dp[j]!=-1)
{
for(k=0;k<=n;k++)
{
if(j<=skillhurt[k]&&dp[j]>=skillCost[k])
{
printf("%d\n",i);
flag=true;
break;
}
else if(j>skillhurt[k]&&dp[j]>=skillCost[k])
{
dp[j-skillhurt[k]]=max(dp[j-skillhurt[k]],dp[j]-skillCost[k]+t);
}
}
}
if(flag==true){break;}
}
if(flag==true){break;}
}
if(flag==false)printf("My god\n");
}
}
#include<stdio.h>
#include<string.h>
int n,t,q;
int skillCost[110];
int skillhurt[110];
int dp[110];//dp[i][j]表示第i轮攻击,boss还剩下j滴hp时候剩下的最大mp
int max(int a,int b)
{
return a>b?a:b;
}
int main()
{
while(scanf("%d%d%d",&n,&t,&q))
{
if(n==0&&t==0&&q==0){break;}
int T;
if(100%q!=0)
{
T=100/q+1;
}else
{
T=100/q;
}
memset(dp,-1,sizeof(dp));
dp[100]=100;
int i,j,k;
for(i=1;i<=n;i++)
{
scanf("%d%d",&skillCost[i],&skillhurt[i]);
}
skillCost[0]=0;
skillhurt[0]=1;
bool flag=false;
for(i=1;i<=T;i++)
{
for(j=1;j<=100;j++)
{
if(dp[j]!=-1)
{
for(k=0;k<=n;k++)
{
if(j<=skillhurt[k]&&dp[j]>=skillCost[k])
{
printf("%d\n",i);
flag=true;
break;
}
else if(j>skillhurt[k]&&dp[j]>=skillCost[k])
{
dp[j-skillhurt[k]]=max(dp[j-skillhurt[k]],dp[j]-skillCost[k]+t);
}
}
}
if(flag==true){break;}
}
if(flag==true){break;}
}
if(flag==false)printf("My god\n");
}
}