Codeforces 898 B.Proper Nutrition
1 second
256 megabytes
standard input
standard output
Vasya has n burles. One bottle of Ber-Cola costs a burles and one Bars bar costs b burles. He can buy any non-negative integer number of bottles of Ber-Cola and any non-negative integer number of Bars bars.
Find out if it's possible to buy some amount of bottles of Ber-Cola and Bars bars and spend exactly n burles.
In other words, you should find two non-negative integers x and y such that Vasya can buy x bottles of Ber-Cola and y Bars bars and x·a + y·b = n or tell that it's impossible.
First line contains single integer n (1 ≤ n ≤ 10 000 000) — amount of money, that Vasya has.
Second line contains single integer a (1 ≤ a ≤ 10 000 000) — cost of one bottle of Ber-Cola.
Third line contains single integer b (1 ≤ b ≤ 10 000 000) — cost of one Bars bar.
If Vasya can't buy Bars and Ber-Cola in such a way to spend exactly n burles print «NO» (without quotes).
Otherwise in first line print «YES» (without quotes). In second line print two non-negative integers x and y — number of bottles of Ber-Cola and number of Bars bars Vasya should buy in order to spend exactly n burles, i.e. x·a + y·b = n. If there are multiple answers print any of them.
Any of numbers x and y can be equal 0.
7
2
3
YES
2 1
100
25
10
YES
0 10
15
4
8
NO
9960594
2551
2557
YES
1951 1949
In first example Vasya can buy two bottles of Ber-Cola and one Bars bar. He will spend exactly 2·2 + 1·3 = 7 burles.
In second example Vasya can spend exactly n burles multiple ways:
- buy two bottles of Ber-Cola and five Bars bars;
- buy four bottles of Ber-Cola and don't buy Bars bars;
- don't buy Ber-Cola and buy 10 Bars bars.
In third example it's impossible to but Ber-Cola and Bars bars in order to spend exactly n burles.
代码:
1 #include<iostream>
2 #include<cstring>
3 #include<cstdio>
4 #include<cmath>
5 #include<algorithm>
6 using namespace std;
7 typedef long long ll;
8 int main(){
9 ll n,a,b;
10 while(~scanf("%lld",&n)){
11 scanf("%lld%lld",&a,&b);
12 int flag=0;ll cnt,num;
13 for(int i=0;;i++){
14 num=n-i*a;
15 if(num<0)break;
16 if(num%b==0){flag=1;cnt=i;break;}
17 }
18 if(flag==1){
19 printf("YES\n");
20 cout<<cnt<<" "<<num/b<<endl;
21 }
22 else cout<<"NO"<<endl;
23 }
24 return 0;
25 }
Codeforces 898 B.Proper Nutrition的更多相关文章
- Codeforces Round #451 (Div. 2) B. Proper Nutrition【枚举/扩展欧几里得/给你n问有没有两个非负整数x,y满足x·a + y·b = n】
B. Proper Nutrition time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Codeforces 898 B(拓展欧几里得)
Proper Nutrition 题意:有n元钱,有2种单价不同的商品,是否存在一种购买方式使得钱恰好花光,如果有输入任意一种方式,如果没有输出“NO” 题解:可以使用拓展欧几里得快速求解. #inc ...
- Codeforces Round #451 (Div. 2)-898A. Rounding 898B.Proper Nutrition 898C.Phone Numbers(大佬容器套容器) 898D.Alarm Clock(超时了,待补坑)(贪心的思想)
A. Rounding time limit per test 1 second memory limit per test 256 megabytes input standard input ou ...
- 【Codeforces Round #451 (Div. 2) B】Proper Nutrition
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 可以直接一层循环枚举. 也可以像我这样用一个数组来存y*b有哪些. 当然.感觉这样做写麻烦了.. [代码] /* 1.Shoud i ...
- 898B. Proper Nutrition#买啤酒问题(枚举&取余)
题目出处:http://codeforces.com/problemset/problem/898/B 题目大意:为一个整数能否由另外两个整数个整数合成 #include<iostream> ...
- Codeforces 898 C.Phone Numbers-STL(map+set+vector)
C. Phone Numbers time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- Codeforces 898 A. Rounding
A. Rounding time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...
- Codeforces 898 贪心关闭最少闹钟 优先队列最少操作构造N/2squares 讨论情况哈希数字串分割a+b=c
A /* Huyyt */ #include <bits/stdc++.h> #define mem(a,b) memset(a,b,sizeof(a)) #define mkp(a,b) ...
- Codeforces Round #451 (Div. 2) A B C D E
Codeforces Round #451 (Div. 2) A Rounding 题目链接: http://codeforces.com/contest/898/problem/A 思路: 小于等于 ...
随机推荐
- RNN教程之-2 LSTM实战
前言 说出来你们不敢相信,刚才码了半天的字,一个侧滑妈的全没了,都怪这Mac的触摸板太敏感沃日.好吧,不浪费时间了,前言一般都是废话,这个教程要解决的是一个LSTM的实战问题,很多人问我RNN是啥,有 ...
- OpenCV学习笔记(一) 环境配置
Visual Studio 2010 VS2010对应的OpenCV的lib文件(build\x86\vc10\lib)分为debug模式和release模式两种:debug模式牺牲速度,但能提供更多 ...
- [项目1] bloger - day1
项目代码:https://github.com/venicid/Project1--Bloger 1.准备工作 1.创建project PS C:\Users\Administrator\Deskto ...
- Python中bisect的使用方法
Python中列表(list)的实现其实是一个数组,当要查找某一个元素的时候时间复杂度是O(n),使用list.index()方法,但是随着数据量的上升,list.index()的性能也逐步下降,所以 ...
- “帮你APP”团队冲刺8
1.整个项目预期的任务量 (任务量 = 所有工作的预期时间)和 目前已经花的时间 (所有记录的 ‘已经花费的时间’),还剩余的时间(所有工作的 ‘剩余时间’) : 所有工作的预期时间:88h 目前已经 ...
- Flask 中蓝图的两种表现形式
最近在学Flask,特有的@X.route 很适合RESTfuld API, 一般小型应用,在一个py文件中就可以完成,但是维护起来比较麻烦. 想体验Django那样的MVT模式, 看到 Flask提 ...
- Python 包导入
首先我们先了解下python中寻找模块的顺序 是否是内建模块 ->主目录 ->PYTHONPATH环境变量 ->标准库 -> 首先判断这个model是否是built-in,即内 ...
- loj2090 「ZJOI2016」旅行者
分治+最短路,很套路的 #include <algorithm> #include <iostream> #include <cstring> #include & ...
- Careercup - Microsoft面试题 - 4639756264669184
2014-05-12 06:42 题目链接 原题: Write your own regular expression parser for following condition: az*b can ...
- MFC定时关机程序的实现2-添加启动项到注册表
虽然上一篇实现了的定时关机,但是还不够完善,比如开机自动启动,然后按照配置的时间定时关机,并最小化到任务栏. 先来说开机启动怎么实现,开机启动实现的方法有好几种,比如直接在开始菜单启动项里添加一个程序 ...