还是不明白问题在哪里,然后又是卡水题,郁闷,已经三次了吧,回回卡水题,越是简单越做不出来???真的难受,就是感觉水题自己思路就定死了,然后就不改了,结果当本质上的想法出错时,基本就一直卡着了,是不是我也有点头铁。。。心累。。
A. Kirill And The Game
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?
First string contains five integer numbers l, r, x, y, k (1 ≤ l ≤ r ≤ 107, 1 ≤ x ≤ y ≤ 107, 1 ≤ k ≤ 107).
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.
1 10 1 10 1
YES
1 5 6 10 1
NO
这个题,题意是要求药水效率,就是效力/成本,看能否找到对应效率。首先想到暴力,但是10e7,两个for直接TLE,然后还有问题是不可以做除法,不能求上下限来判断,因为答案只有整数,不可能有小数,比如一个样例是 l=4,r=4,x=1,y=2,这时k只能得1或2两个整数,求不出范围,如果k要求为3就wa了,所以不可以除,然后需要改成乘法,乘法需要注意用longlong,不然会爆。
#include<bits/stdc++.h>
using namespace std;
int main() {
long long int l,r,x,y,k,p;
double a,b,c,d;
while(~scanf("%lld %lld %lld %lld %lld",&l,&r,&x,&y,&k)) {
p = 0;
// printf("%lf %lf",a,b);
for(int i = x; i <= y; i ++) {
if(i * k >= l && i * k <= r) {
p = 1;
break;
}
}
if(!p) {
printf("NO\n");
} else {
printf("YES\n");
}
}
}
Mashmokh and Tokens
Bimokh is Mashmokh's boss. For the following n days he decided to pay to his workers in a new way. At the beginning of each day he will give each worker a certain amount of tokens. Then at the end of each day each worker can give some of his tokens back to get a certain amount of money. The worker can save the rest of tokens but he can't use it in any other day to get more money. If a worker gives back w tokens then he'll get dollars.
Mashmokh likes the tokens however he likes money more. That's why he wants to save as many tokens as possible so that the amount of money he gets is maximal possible each day. He has n numbers x1, x2, ..., xn. Numberxi is the number of tokens given to each worker on the i-th day. Help him calculate for each of n days the number of tokens he can save.
Input
The first line of input contains three space-separated integers n, a, b (1 ≤ n ≤ 105; 1 ≤ a, b ≤ 109). The second line of input contains n space-separated integers x1, x2, ..., xn (1 ≤ xi ≤ 109).
Output
Output n space-separated integers. The i-th of them is the number of tokens Mashmokh can save on the i-th day.
Sample test(s)
5 1 4 12 6 11 9 1
0 2 3 1 1
3 1 2 1 2 3
1 0 1
1 1 1 1
0
这个题真的巨坑,到后面题都没看懂,整个题找不到a,b代表什么意思,很难受。实际上是个数学题,题中说
y是向下取整,得到最少的金币数。在保证y不变的情况下,最小的w是多少呢?
===》》》
可以得到这个。 要先判断y*b%a?因为是向下取整,(x只能是整数,比如x=3.1,你总不能给员工3个令牌吧,工人不愿意啊。只能给4个)所以,%a!=0时要加1。
#include<stdio.h>
int x[100000];
int main()
{
long long n,a,b,w,z;
scanf("%lld%lld%lld",&n,&a,&b);
int i;
for(i=0; i<n; i++)
{
scanf("%lld",&x[i]);
w=x[i]*a/b;
if(w*b%a==0)
z=w*b/a;
else
z=w*b/a+1;
printf("%lld ",x[i]-z);
}
printf("\n");
return 0;