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 思路: 小于等于 ...
随机推荐
- JVM——自定义类加载器
)以上两种情况在实际中的综合运用:比如你的应用需要通过网络来传输 Java 类的字节码,为了安全性,这些字节码经过了加密处理.这个时候你就需要自定义类加载器来从某个网络地址上读取加密后的字节代码,接着 ...
- easyui的tree基本属性
1.cascadeCheck,级联 默认情况下,是true,级联的,就是选中一个子节点,父节点是半选中状态,子节点全选中之后,父节点就是选中状态.
- cacheData
<%@ page language="java" import="java.util.*,com.fiberhome.bcs.appprocess.common.u ...
- mysql 外连接的时候,条件在on后面和条件在where后面的区别
最近使用mysql的时候碰到一个问题:当一个表外联另一个表的时候,将一些查询条件放在on后面和放在where后面不太一样: 学生分数表stuscore: 当查询语句如下(查询语句1): SELECT ...
- virsh命令管理虚拟机
virsh命令管理虚拟机 libvirt有两种控制方式,命令行和图形界面. 1.图形界面:通过执行名virt-manager,启动libvirt的图形界面,在图形界面下可以一步一步的创建虚拟机,管理虚 ...
- java读取文件(更新jdk7及jdk8)
以字节的方式读取: InputStream inputStream = new FileInputStream(file); int temp = -1; StringBuilder sb = new ...
- Zookeeper 增删改查
初始化对象连接到zookeeper服务: public ZooKeeper initZk(){ final CountDownLatch countDownLatch = new CountDownL ...
- nyoj 题目17 单调递增最长子序列
单调递增最长子序列 时间限制:3000 ms | 内存限制:65535 KB 难度:4 描述 求一个字符串的最长递增子序列的长度如:dabdbf最长递增子序列就是abdf,长度为4 输入 ...
- 优化脚本性能 Optimizing Script Performance
This page gives some general hints for improving script performance on iOS. 此页面提供了一些一般的技巧,提高了在iOS上的脚 ...
- Pointcut is not well-formed: expecting 'name pattern' at character position 53
报错内容: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataso ...