CodeForces1214A
说起来你们可能不信,这题硬生生卡了我\(1h\),我想了背包,扩欧,二分....等等一坨办法.结果最后还是用了\(bfs\)过的.
呃,代码一目了然,不用说吧...
\(Code:\)

#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <ctime>
#include <map>
#include <set>
#define MEM(x,y) memset ( x , y , sizeof ( x ) )
#define rep(i,a,b) for (int i = a ; i <= b ; ++ i)
#define per(i,a,b) for (int i = a ; i >= b ; -- i)
#define pii pair < int , int >
#define X first
#define Y second
#define rint read<int>
#define pb push_backusing std::set ;
using std::pair ;
using std::max ;
using std::min ;
using std::priority_queue ;
using std::vector ;
using std::swap ;
using std::sort ;
using std::unique ;
using std::greater ;
using std::queue ;template < class T >inline T read () {T x = 0 , f = 1 ; char ch = getchar () ;while ( ch < '0' || ch > '9' ) {if ( ch == '-' ) f = - 1 ;ch = getchar () ;}while ( ch >= '0' && ch <= '9' ) {x = ( x << 3 ) + ( x << 1 ) + ( ch - 48 ) ;ch = getchar () ;}return f * x ;
}template < class T >inline void write(T x) {static T stk[100], top = 0;if (x == 0) { putchar('0'); return; }if (x < 0) { x = -x; putchar('-'); }while (x) { stk[++top] = x % 10; x /= 10; }while (top) { putchar(stk[top--] + '0'); }putchar ( 10 ) ;}const int N = 1e8 + 100 ;int dollar , euro , tot ;
int d[] = { 1 , 2 , 5 , 10 , 20 , 50 , 100 } ;
int e[] = { 5 , 10 , 20 , 50 , 100 , 200 } ;
bool mk[N] ; queue < int > q ; inline void bfs (int x) {q.push ( x ) ; mk[x] = true ;while ( ! q.empty () ) {int j = q.front () ; q.pop () ;rep ( i , 0 , 6 ) {int tmp = j - d[i] ;if ( tmp >= 0 && ! mk[tmp] ) {mk[tmp] = true ;q.push ( tmp ) ;}}rep ( i , 0 , 5 ) {int tmp = j - e[i] ;if ( tmp >= 0 && ! mk[tmp] ) {mk[tmp] = true ;q.push ( tmp ) ;}}}return ;
}signed main (int argc , char * argv[] ) {tot = rint () ; dollar = rint () ; euro = rint () ; MEM ( mk , 0 ) ;rep ( i , 0 , 6 ) d[i] *= dollar ; rep ( i , 0 , 5 ) e[i] *= euro ;bfs ( tot ) ; rep ( i , 0 , tot ) if ( mk[i] ) { write ( i ) ; break ; }return 0 ;
}

转载于:https://www.cnblogs.com/Equinox-Flower/p/11469081.html

CodeForces1214A相关推荐

最新文章

  1. 火星无人机「机智号」代码开源,1.2w人参与贡献
  2. 常用 CSS 选择器
  3. 人工智能的发展,需要遵守的四个AI伦理原则
  4. 在linux中教你通过NFS实现文件共享
  5. 使用JDOM解析XML
  6. 微服务集成——《微服务设计》读书笔记
  7. java登录界面命令_Java命令行界面(第29部分):自己动手
  8. 基于 KIF 的 iOS UI 自动化测试和持续集成
  9. 好的飞鸽传书2007对于对外的API
  10. 【python】-- Socket接收大数据
  11. 技术和商业的碰撞,谈阿里云与天猫双11这十年
  12. 黑桃怎么用html代码,index.html
  13. 多人网络(Valve开发文档翻译[起源引擎])(一)
  14. CSS制作的32种图形效果 梯形 | 三角 | 椭圆 | 平行四边形 | 菱形 | 四分之一圆 | 旗帜
  15. 语音转换工具推荐tts-vue
  16. python namedtuple
  17. vue-js实现日期加减,年月日,及单位换算。
  18. Java给定字符串形式的非负数,返回两个非负数的乘积
  19. 数据分享|R语言逻辑回归、线性判别分析LDA、GAM、MARS、KNN、QDA、决策树、随机森林、SVM分类葡萄酒交叉验证ROC...
  20. regsvr32提示模块加载失败 请确保二进制

热门文章

  1. TeamCity 的安装和使用
  2. 资源站点收集中......
  3. 360手机卫士经典案例分析
  4. Python编程 递归函数
  5. 数据中心SDN网络、VXLAN、虚拟化之间的关系和概念
  6. c#调用matlab生成的dll
  7. pycharm运行os.system出现�����ڲ����ⲿ���Ҳ���ǿ����еij��� ���������ļ���
  8. 三相同步电动机的平衡方程式
  9. html会员中心源码,响应式自适应手机端会员中心(两种编码)
  10. 企业开发App的优势有哪些