Codeforces - 842A Kirill And The Game

xiaoxiao2021-02-28  107

A. Kirill And The Game time limit per test  2 seconds memory limit per test  256 megabytes input  standard input output  standard output

Kirill plays a new computer game. He came to the potion store where he can buy any potion. Each potion is characterized by two integers — amount of experience and cost. The efficiency of a potion is the ratio of the amount of experience to the cost. Efficiency may be a non-integer number.

For each two integer numbers a and b such that l ≤ a ≤ r and x ≤ b ≤ y there is a potion with experience a and cost b in the store (that is, there are (r - l + 1)·(y - x + 1) potions).

Kirill wants to buy a potion which has efficiency k. Will he be able to do this?

Input

First string contains five integer numbers lrxyk (1 ≤ l ≤ r ≤ 1071 ≤ x ≤ y ≤ 1071 ≤ k ≤ 107).

Output

Print "YES" without quotes if a potion with efficiency exactly k can be bought in the store and "NO" without quotes otherwise.

You can output each of the letters in any register.

Examples input 1 10 1 10 1 output YES input 1 5 6 10 1 output NO

题意:很复杂,但转换后其实就是求a/b能不能等于k,然后a,b有个取值范围

解题思路:一开始以为直接求最小值l/y,最大值r/x,然后看k在不在里面。其实这样是不可以的(所以被hack了),因为他说了,a,b是整数……只能老老实实枚举……枚举的时候枚举b就可以了,简单易懂……

#include<iostream> #include<deque> #include<memory.h> #include<stdio.h> #include<map> #include<string> #include<algorithm> #include<vector> #include<math.h> #include<stack> #include<queue> #include<set> #define INF 1<<29 using namespace std; typedef long long int ll; const int N = 2505; ll l,r,x,y,k; int main() { cin>>l>>r>>x>>y>>k; int flag=0; for(ll i=x;i<=y;i++) { ll temp=k*i; if(l<=temp&&temp<=r) { flag=1; break; } } if(flag) printf("YES\n"); else printf("NO\n"); return 0; }

转载请注明原文地址: https://www.6miu.com/read-96141.html

最新回复(0)