题意:

给出n,m,代表微波炉有n个button,要求达到总时间为m

然后给出n个数。代表n个button能添加的时间,问最少几步,可以使得按出的总时间大于等于要求的时间,而且相差最小

输出最小的步数与相差的最小值

要求,当总时间小于0时。时间为0,大于3600时,时间为3600



思路:

直接暴力BFS。用VIS记录步数



  1. #include <iostream>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <stack>
  5. #include <queue>
  6. #include <map>
  7. #include <set>
  8. #include <vector>
  9. #include <math.h>
  10. #include <bitset>
  11. #include <algorithm>
  12. #include <climits>
  13. using namespace std;
  14.  
  15. #define ls 2*i
  16. #define rs 2*i+1
  17. #define UP(i,x,y) for(i=x;i<=y;i++)
  18. #define DOWN(i,x,y) for(i=x;i>=y;i--)
  19. #define MEM(a,x) memset(a,x,sizeof(a))
  20. #define W(a) while(a)
  21. #define gcd(a,b) __gcd(a,b)
  22. #define LL long long
  23. #define ULL unsigned long long
  24. #define N 100005
  25. #define INF 0x3f3f3f3f
  26. #define EXP 1e-8
  27. #define rank rank1
  28. const int mod = 1000000007;
  29.  
  30. int t,n,sum;
  31. int a[20];
  32. int vis[N];
  33.  
  34. int main()
  35. {
  36. int i,j,k;
  37. scanf("%d",&t);
  38. while(t--)
  39. {
  40. scanf("%d%d",&n,&sum);
  41. for(i = 0; i<n; i++)
  42. scanf("%d",&a[i]);
  43. MEM(vis,INF);
  44. queue<int> Q;
  45. Q.push(0);
  46. vis[0] = 0;
  47. while(!Q.empty())
  48. {
  49. int x = Q.front();
  50. Q.pop();
  51. for(i = 0; i<n; i++)
  52. {
  53. int next = x+a[i];
  54. if(next<0) next = 0;
  55. if(next>3600) next = 3600;
  56. if(vis[next]<=vis[x]+1) continue;
  57. vis[next] = vis[x]+1;
  58. Q.push(next);
  59. }
  60. }
  61. for(i = sum; i<=3600; i++)
  62. {
  63. if(vis[i]!=INF)
  64. {
  65. break;
  66. }
  67. }
  68. printf("%d %d\n",vis[i],i-sum);
  69. }
  70.  
  71. return 0;
  72. }

BAPC2014 B&amp;&amp;HUNNU11582:Button Bashing(BFS)的更多相关文章

  1. 【最短路】BAPC2014 B Button Bashing (Codeforces GYM 100526)

    题目链接: http://codeforces.com/gym/100526 http://acm.hunnu.edu.cn/online/?action=problem&type=show& ...

  2. BAPC 2014:Button Bashing(暴力+bfs)

    题意: 给出n,m,代表微波炉有n个按钮,要求达到总时间为m 然后给出n个数,代表n个按钮能增加的时间,问最少几步,能够使得按出的总时间大于等于要求的时间,并且相差最小 输出最小的步数与相差的最小值 ...

  3. Button Bashing(搜索)

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAx8AAAI2CAIAAAC+EqK4AAAgAElEQVR4nOydf0BT9f7/37fS423mWn

  4. ACM 第十七天

    暑期热身赛 BAPC 2014 The 2014 Benelux Algorithm Programming Contest 题目网址:https://odzkskevi.qnssl.com/3655 ...

  5. Benelux Algorithm Programming Contest 2014 Final

    // Button Bashing (bfs) 1 #include <iostream> #include <cstdio> #include <cstring> ...

  6. Benelux Algorithm Programming Contest 2014 Final(第二场)

    B:Button Bashing You recently acquired a new microwave, and noticed that it provides a large number ...

  7. Left Mouse Button (bfs)

    Mine sweeper is a very popular small game in Windows operating system. The object of the game is to ...

  8. CodeForces 520B Two Buttons(用BFS)

     Two Buttons time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...

  9. HDU 1548 A strange lift (bfs / 最短路)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1548 A strange lift Time Limit: 2000/1000 MS (Java/Ot ...

随机推荐

  1. Java系列学习(二)-配置开发环境

    1.设置系统环境变量 1.1.设置JDK的Path路径 作用:通过path环境变量,将JDK安装目录下的bin目录配置到path变量下,可使javac指令和java指令在任意目录下运行   方法一:直 ...

  2. sql server 无法创建数据库,错误代码:1807

    SQL Server 不能创建数据库,发生错误:1807 :未能获得数据库 'model' 上的排它锁.请稍后重试操作. declare   @sql   varchar(100)     while ...

  3. FFmpeg编译Android版本

    FFmpeg是很好用的一个音视频库,功能强大,但是用起来并不是很方便.之前一直不想用FFmpeg,因为感觉编译太麻烦,但是到了不得不用的时候了,没办法,参考了网上大神的方法,在这里自己也记录一下方便以 ...

  4. 一篇文章告诉你如何使用EF CodeFirst做增删改查

    一.修改数据 其实修改涉及的内容挺多的,是相对于其他操作来说比较繁琐.也是本文的重头戏. 虽然都是基础内容,但是也是值得细细品味的. 1.最简单直接的修改数据就是从数据库里检索出数据修改相应的字段即可 ...

  5. CSS——属性选择器

    属性选择器:通过对标签中属性的选择,控制标签. <!DOCTYPE html> <html> <head> <style> div[class*=&qu ...

  6. 【centOS7】Jenkins安装--漫漫踩坑路

    安装步骤: https://www.cnblogs.com/h--d/p/5673085.html 安装后遇到的问题及解决办法: jenkins的admin用户的初始密码路径 https://blog ...

  7. acedinitget

    // 提示用户选择选择方式 acedInitGet(0, _T("W CP")); int nRs = acedGetKword(_T("\n请输入关键字确定选择方式[窗 ...

  8. accmcolor

    accmcolor c; c.setcolorindex(1); playertablerecord.setcolor(c);

  9. iptables详解(2):iptables实际操作之规则查询

    所属分类:IPtables  Linux基础 在阅读这篇文章之前,请确保你已经阅读了如下文章,如下文章总结了iptables的相关概念,是阅读这篇文章的基础. 图文并茂理解iptables 如果你是一 ...

  10. 利用shell脚本去备份幸运28源码搭建下载所指定的数据库

    #! /bin/bash幸运28源码搭建下载Q[115288oo99]logintool=/home/yx/server/mysql/mysql/bin/mysqldumptool=/home/yx/ ...