HDU 4803 Poor Warehouse Keeper(打表找规律)

思路:这个题一眼看上去没什么思路...先把小数据的用BFS打出来了然后直接看出规律来了....


#include<bits/stdc++.h>
using namespace std;

int main()
{
    int x,y;
	while(scanf("%d%d",&x,&y)!=EOF)
	{
		if(x>y)
		{
			printf("-1\n");
			continue;
		}
		if(x==1)
			printf("%d\n",y-1);
		if(x==2)
			printf("%d\n",(y+1)/2);
        if(x==3)
		{
			int a[3]={2,3,4};
			printf("%d\n",(y-3)/3+a[(y-3)%3]);
		}
		if(x==4)
		{
			int a[4]={3,4,4,5};
			printf("%d\n",(y-4)/4+a[(y-4)%4]);
		}
		if(x==5)
		{
            int a[5]={4,5,5,6,6};
			printf("%d\n",(y-5)/5+a[(y-5)%5]);
		}
		if(x==6)
		{
            int a[6]={5,6,6,6,7,7};
			printf("%d\n",(y-6)/6+a[(y-6)%6]);
		}
		if(x==7)
		{
			int a[7]={6,7,7,7,8,8,9};
            printf("%d\n",(y-7)/7+a[(y-7)%7]);

		}
		if(x==8)
		{
			int a[8]={7,8,8,9,8,9,9,10};
			printf("%d\n",(y-8)/8+a[(y-8)%8]);
		}
		if(x==9)
		{
            int a[9]={8,9,9,9,9,10,10,10,11};
			printf("%d\n",(y-9)/9+a[(y-9)%9]);
		}
		if(x==10)
		{
            int a[10]={9,10,10,10,11,10,11,11,11,12};
			printf("%d\n",(y-10)/10+a[(y-10)%10]);
		}
	}
}


Description

Jenny is a warehouse keeper. He writes down the entry records everyday. The record is shown on a screen, as follow: 

There are only two buttons on the screen. Pressing the button in the first line once increases the number on the first line by 1. The cost per unit remains untouched. For the screen above, after the button in the first line is pressed, the screen will be: 

The exact total price is 7.5, but on the screen, only the integral part 7 is shown. 
Pressing the button in the second line once increases the number on the second line by 1. The number in the first line remains untouched. For the screen above, after the button in the second line is pressed, the screen will be: 

Remember the exact total price is 8.5, but on the screen, only the integral part 8 is shown. 
A new record will be like the following: 

At that moment, the total price is exact 1.0. 
Jenny expects a final screen in form of: 

Where x and y are previously given. 
What’s the minimal number of pressing of buttons Jenny needs to achieve his goal?

Input

There are several (about 50, 000) test cases, please process till EOF. 
Each test case contains one line with two integers x(1 <= x <= 10) and y(1 <= y <= 10  9) separated by a single space - the expected number shown on the screen in the end.

Output

For each test case, print the minimal number of pressing of the buttons, or “-1”(without quotes) if there’s no way to achieve his goal.

Sample Input

1 1
3 8
9 31

Sample Output

0
5
11


        
  


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值