BAPC2014 B&&HUNNU11582:Button Bashing(BFS)
题意:
给出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&&HUNNU11582:Button Bashing(BFS)的更多相关文章
- 【最短路】BAPC2014 B Button Bashing (Codeforces GYM 100526)
题目链接: http://codeforces.com/gym/100526 http://acm.hunnu.edu.cn/online/?action=problem&type=show& ...
- BAPC 2014:Button Bashing(暴力+bfs)
题意: 给出n,m,代表微波炉有n个按钮,要求达到总时间为m 然后给出n个数,代表n个按钮能增加的时间,问最少几步,能够使得按出的总时间大于等于要求的时间,并且相差最小 输出最小的步数与相差的最小值 ...
- Button Bashing(搜索)
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAx8AAAI2CAIAAAC+EqK4AAAgAElEQVR4nOydf0BT9f7/37fS423mWn
- ACM 第十七天
暑期热身赛 BAPC 2014 The 2014 Benelux Algorithm Programming Contest 题目网址:https://odzkskevi.qnssl.com/3655 ...
- Benelux Algorithm Programming Contest 2014 Final
// Button Bashing (bfs) 1 #include <iostream> #include <cstdio> #include <cstring> ...
- Benelux Algorithm Programming Contest 2014 Final(第二场)
B:Button Bashing You recently acquired a new microwave, and noticed that it provides a large number ...
- Left Mouse Button (bfs)
Mine sweeper is a very popular small game in Windows operating system. The object of the game is to ...
- CodeForces 520B Two Buttons(用BFS)
Two Buttons time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...
- 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 ...
随机推荐
- Unity学习-预制(四)
预制即克隆 比如要模拟一个下雨的场景,天下掉下来一颗一颗的雨滴.如果此时,我们给每一个雨滴创建一个对象的话,那会很浪费资源,而且也没必要,因为所有的雨滴是相同的.这个时候就使用到了预制,一种可以被重复 ...
- Intent的调用
//Intent intent=new Intent();//intent.setClass(MainActivity.this, GPSService.class);//以上二条可以合并成如下一条 ...
- 前端开发之旅-zopim在线即时聊天客服
一.与潜在客户实时聊天的神奇-zopim Zopim是一款高效的可嵌入网页中去的即使通讯与网站访客信息追踪的的Web软件.知道谁在访问您的网站吗?想和他们实时交流吗?想更有效的把握商机吗?使用Zopi ...
- c++ 以二进制和以文本方式读写文件的区别
在c++项目开发中,时常涉及到文件读写操作.因此在这里先简单梳理和回顾一下文本模式和二进制模式在进行文件读写上的区别. 1.linux平台下文本文件和二进制文件的读写 在linux平台下进行文件读写时 ...
- nc的简单使用
1.传输文件: 目的主机监听 nc -l 监听端口<未使用端口> > 要接收的文件名 nc -l 6666 > filename.tar 源主机发起请求 nc 目的主机ip ...
- mysql_基础1
初学mysql,感觉挺有意思的. mysql指令的一些参数: promrt修改提示符: PROMPT \D mysql的语法规范: 一些函数: 创建数据库: SHOW CREATE DATABAS ...
- django 加日志
LOGGING = { 'version': 1, 'disable_existing_loggers': False, # 指定输出的格式,被handler使用. 'formatters': { ' ...
- CSS 之自定义滚动条样式
::-webkit-scrollbar {/*滚动条整体样式*/ width: 5px; /*高宽分别对应横竖滚动条的尺寸*/ height: 1px; } ::-webkit-scrollbar-t ...
- Js—innerHTML和innerText的区别
1.innerHTML属性和innerText属性 都是对元素的一个操作,简单讲,innerHTML可以在某种特定环境下重构某个元素节点的DOM结构,innerText只能修改文本值 在JavaScr ...
- SolidWorks学习笔记(一)
一.草图绘制 1.简单命令 先直线后圆弧,几何约束.尺寸标定 2.圆周阵列 3.几何关系——对称 添加几何约束:圆弧相等.关于竖直中心线的对称 4.捕捉圆心 5.尺寸锁定,有圆弧的,先直后圆 6. 7 ...