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 ...
随机推荐
- Hibernate 延迟加载剖析与代理模式应用
本文来源于:http://www.ibm.com/developerworks/cn/java/j-lo-hibernatelazy/#icomments
- Microsoft SQL Server学习(二)--数据库的语法
关于数据库的语法 创建数据库 样例 名词概念 编写数据库代码的注意事项 关于文件语法 实例代码 关于数据库的语法: 1.创建数据库 create database 数据库名 on primary (主 ...
- Canvas——基本入门
基本概念 1.canvas 是 HTML5 提供的一个用于展示绘图效果的标签. canvas 原意画布, 帆布. 在 HTML 页面中用于展示绘图效果. 最早 canvas 是苹果提出的一个方案, 今 ...
- 六时出行 App iOS隐私政策
本应用尊重并保护所有使用服务用户的个人隐私权.为了给您提供更准确.更有个性化的服务,本应用会按照本隐私权政策的规定使用和披露您的个人信息.但本应用将以高度的勤勉.审慎义务对待这些信息.除本隐私权政策另 ...
- python 求一个文件中每个字符出现的次数
import pprint import collections filename = input('Input filename') with open(filename) as info: cou ...
- VM虚拟机NAT链接外网
1.vi /etc/sysconfig/networkNETWORKING=yesHOSTNAME=localhost.localdomainGATEWAY=192.168.110.2 2.vi /e ...
- Mybatis操作Mysql批量更新的一个坑-&allowMultiQueries=true允许批量更新
前言 利用Mybatis批量更新或者批量插入,实际上即使Mybatis完美支持你的sql,你也得看看你操作的数据库是否完全支持,而同事,最近就遇到这样的一个坑! 问题 先带大家来 ...
- raspberry 重新烧录后的设置
raspberry初学者在使用的时候经常遇到各种问题,常常重新烧录系统,现在把新系统的常用配置和安装内容整理一下,避免自己忘记 1.安装常用软件包: sudo apt-get gedit sudo a ...
- PHP websocket之聊天室实现
PHP部分 <?php error_reporting(E_ALL); set_time_limit(0);// 设置超时时间为无限,防止超时 date_default_timezone_set ...
- Python模块 os.walk
Os.walk os.walk(top,topdown=True,onerror=None,followlinks=False) os.walk()是python中内置(built-in)的目录树生成 ...