Time Limit : 3000/1000ms (Java/Other)   Memory Limit : 65535/32768K (Java/Other)
Total Submission(s) : 65   Accepted Submission(s) : 29

Font: Times New Roman | Verdana | Georgia

Font Size: ← →

Problem Description

Input

第一行一个数T,表示测试数据组数(1 <= T <= 100)
接下来T行,每行四个整数x,y,length, hight(length表示桥的长度,hight表示桥初始的高度,x和y与题目中的含义相同), 0 < x, y, length, hight <= 1e9

Output

对于每组测试数据,输出一个整数,表示最少需要的步数。如果猪猪无法过河,则输出-1

Sample Input

3
1 1 1 1
1 1 2 1
1 1 3 1

Sample Output

1
2
-1

Author

Tong Wei
注意一下最后一步是走在哪里就好了
#include<stdio.h>
//#include<bits/stdc++.h>
#include<string.h>
#include<iostream>
#include<math.h>
#include<sstream>
#include<set>
#include<queue>
#include<map>
#include<vector>
#include<algorithm>
#include<limits.h>
#define inf 0x3fffffff
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
using namespace std;
int a;
int main()
{
    int t;
    int x,y,l,h;
    while(cin>>t)
    {
        while(t--)
        {
            cin>>x>>y>>l>>h;
            if(l%x==0)
            {
                h=h-(l/x-1)*y;
                if(h>=0)
                {
                    cout<<l/x<<endl;
                }
                else
                {
                    puts("-1");
                }
            }
            else
            {
                h=h-(l/x)*y;
                if(h>=0)
                {
                    cout<<l/x+1<<endl;
                }
                else
                {
                    puts("-1");
                }
            }
        }
    }
    return 0;
}

  

相关文章: