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 ...
随机推荐
- Java系列学习(二)-配置开发环境
1.设置系统环境变量 1.1.设置JDK的Path路径 作用:通过path环境变量,将JDK安装目录下的bin目录配置到path变量下,可使javac指令和java指令在任意目录下运行 方法一:直 ...
- sql server 无法创建数据库,错误代码:1807
SQL Server 不能创建数据库,发生错误:1807 :未能获得数据库 'model' 上的排它锁.请稍后重试操作. declare @sql varchar(100) while ...
- FFmpeg编译Android版本
FFmpeg是很好用的一个音视频库,功能强大,但是用起来并不是很方便.之前一直不想用FFmpeg,因为感觉编译太麻烦,但是到了不得不用的时候了,没办法,参考了网上大神的方法,在这里自己也记录一下方便以 ...
- 一篇文章告诉你如何使用EF CodeFirst做增删改查
一.修改数据 其实修改涉及的内容挺多的,是相对于其他操作来说比较繁琐.也是本文的重头戏. 虽然都是基础内容,但是也是值得细细品味的. 1.最简单直接的修改数据就是从数据库里检索出数据修改相应的字段即可 ...
- CSS——属性选择器
属性选择器:通过对标签中属性的选择,控制标签. <!DOCTYPE html> <html> <head> <style> div[class*=&qu ...
- 【centOS7】Jenkins安装--漫漫踩坑路
安装步骤: https://www.cnblogs.com/h--d/p/5673085.html 安装后遇到的问题及解决办法: jenkins的admin用户的初始密码路径 https://blog ...
- acedinitget
// 提示用户选择选择方式 acedInitGet(0, _T("W CP")); int nRs = acedGetKword(_T("\n请输入关键字确定选择方式[窗 ...
- accmcolor
accmcolor c; c.setcolorindex(1); playertablerecord.setcolor(c);
- iptables详解(2):iptables实际操作之规则查询
所属分类:IPtables Linux基础 在阅读这篇文章之前,请确保你已经阅读了如下文章,如下文章总结了iptables的相关概念,是阅读这篇文章的基础. 图文并茂理解iptables 如果你是一 ...
- 利用shell脚本去备份幸运28源码搭建下载所指定的数据库
#! /bin/bash幸运28源码搭建下载Q[115288oo99]logintool=/home/yx/server/mysql/mysql/bin/mysqldumptool=/home/yx/ ...