[2018-4-27]BNUZ套题比赛div2

本文通过两道具体题目解析ACM竞赛中的“水题”,探讨如何快速准确地理解题意并给出解答。文章重点介绍了一种不使用除法而通过乘法判断特定条件是否满足的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

还是不明白问题在哪里,然后又是卡水题,郁闷,已经三次了吧,回回卡水题,越是简单越做不出来???真的难受,就是感觉水题自己思路就定死了,然后就不改了,结果当本质上的想法出错时,基本就一直卡着了,是不是我也有点头铁。。。心累。。

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 l, r, x, y, k (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
这个题,题意是要求药水效率,就是效力/成本,看能否找到对应效率。首先想到暴力,但是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

time limit per test:1 second
memory limit per test:256 megabytes
input:standard input
output:standard output

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)

Input
5 1 4
12 6 11 9 1
Output
0 2 3 1 1 
Input
3 1 2
1 2 3
Output
1 0 1 
Input
1 1 1
1
Output
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;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值