题意:

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

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

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

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



思路:

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



#include <iostream>
#include <stdio.h>
#include <string.h>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <math.h>
#include <bitset>
#include <algorithm>
#include <climits>
using namespace std; #define ls 2*i
#define rs 2*i+1
#define UP(i,x,y) for(i=x;i<=y;i++)
#define DOWN(i,x,y) for(i=x;i>=y;i--)
#define MEM(a,x) memset(a,x,sizeof(a))
#define W(a) while(a)
#define gcd(a,b) __gcd(a,b)
#define LL long long
#define ULL unsigned long long
#define N 100005
#define INF 0x3f3f3f3f
#define EXP 1e-8
#define rank rank1
const int mod = 1000000007; int t,n,sum;
int a[20];
int vis[N]; int main()
{
int i,j,k;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&n,&sum);
for(i = 0; i<n; i++)
scanf("%d",&a[i]);
MEM(vis,INF);
queue<int> Q;
Q.push(0);
vis[0] = 0;
while(!Q.empty())
{
int x = Q.front();
Q.pop();
for(i = 0; i<n; i++)
{
int next = x+a[i];
if(next<0) next = 0;
if(next>3600) next = 3600;
if(vis[next]<=vis[x]+1) continue;
vis[next] = vis[x]+1;
Q.push(next);
}
}
for(i = sum; i<=3600; i++)
{
if(vis[i]!=INF)
{
break;
}
}
printf("%d %d\n",vis[i],i-sum);
} return 0;
}

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. [ HNOI 2006 ] 公路修建问题

    \(\\\) \(Description\) 一个\(N\)个点\(M\)条边的图,每条边可以选择\(w_i,p_i\)两个边权之一,现求一个生成树上的最大边权最小值,要求这棵生成树上至少有\(K\) ...

  2. 前端-Node.js思维导图笔记

    看不清的朋友右键保存或者新窗口打开哦!喜欢我可以关注我,还有更多前端思维导图笔记

  3. Paint、Canvas

    1.Canvas类 public class Canvas { public static final int ALL_SAVE_FLAG = 31; /** @deprecated */ @Depr ...

  4. 从CSDN转到cnblogs了

    之前一直用的CSDN的博客,网站卡慢经常出问题,发布文章要审核,连修改几个标点符号也要审核,这些我都忍了,毕竟之前发的文章舍不得弃掉. 现在竟然无故封禁我的博客?请问我写的都是技术文章,有哪点违反规定 ...

  5. HTTP常见状态码(404、400、500)等错误

    一些常见的状态码为: 200 - 服务器成功返回网页 404 - 请求的网页不存在 503 - 服务不可用 详细分解: 1xx(临时响应) 表示临时响应并需要请求者继续执行操作的状态代码. 代码 说明 ...

  6. CORNERSTONE在线敏捷开发工具这么强大,除了推荐,我别无选择

    刚接到一个新项目,完全找不到思路, 怎么办? 任务分工不明,成员相互推诿, 怎么办? 编制的工作计划,老挨产品经理批, 怎么办? 时间短,任务紧,进度与时间两难控制, 怎么办? ...... 别着急, ...

  7. spring IOC bean间关系

    1.0 继承关系 实体 package com.java.test5; import java.util.*; /** * @author nidegui * @create 2019-06-22 1 ...

  8. [nodejs]在mac环境下如何将node更新至最新?

    在mac下安装angular-cli时,报出较多错误.初步怀疑是因为node环境版本过低导致. 在mac下,需要执行如下几步将node更新至最新版本,也可以更新到指定版本 1. sudo npm ca ...

  9. Chromium CEF 2623 -- 支持 xp 的最后一个版本源码下载和编译步骤

    背景 因为项目需要在客户端中内嵌浏览器,需要支持 xp 操作系统和播放视频,但 CEF 2623 以后的版本已经不支持 xp 操作系统,也不再提供 2623 版本的二进制发布包下载,只好自己手动编译. ...

  10. Delphi / Pascal 语法知识干货

    ********************************************* Pascal.Delph干货 *************************************** ...