题意:

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

然后给出n个数,代表n个按钮能增加的时间,问最少几步,能够使得按出的总时间大于等于要求的时间,并且相差最小

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

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

题意:

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

然后给出n个数,代表n个按钮能增加的时间,问最少几步,能够使得按出的总时间大于等于要求的时间,并且相差最小

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

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

Sample Input

2
3 50
-10 10 60
1 50
20

Sample Output

2 0
3 10

AC代码:

#include<stdio.h>
#include<queue>
#include<string.h>
#define INF 0x3f3f3f3f
using namespace std;
int step[];
int a[];
int main()
{
int t,n,m,v,nt,i;
scanf("%d",&t);
while(t--)
{
memset(step,INF,sizeof(step));
queue<int>q;
scanf("%d%d",&n,&m);
for( i= ; i<n ;i++)
scanf("%d",&a[i]);
q.push();
step[]=;///记录步数
while(!q.empty())
{
v=q.front();
q.pop();
for( i= ; i<n ;i++)
{
nt=v+a[i];///时间点
if(nt<)
nt=;
if(nt>)
nt=;
if(step[nt]<=step[v]+)
continue;
step[nt]=step[v]+;
q.push(nt);
}
}
for( i=m; i<=;i++)
if(step[i]!=INF)
break;
printf("%d %d\n",step[i],i-m);
}
}

做题报告:

题意要理解清楚,要明白小于0为0,大于3600为3600,大胆暴力

BAPC 2014:Button Bashing(暴力+bfs)的更多相关文章

  1. hdu 1195:Open the Lock(暴力BFS广搜)

    Open the Lock Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

  2. BAPC2014 B&amp;&amp;HUNNU11582:Button Bashing(BFS)

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

  3. bzoj 1295: [SCOI2009]最长距离 暴力+bfs最短路

    题目链接: http://www.lydsy.com/JudgeOnline/problem.php?id=1295 题解: 对每个点暴力跑一遍bfs,看能够到达的最远位置,这里如果有障碍物则距离为1 ...

  4. 青岛网络赛J-Press the button【暴力】

    Press the Button Time Limit: 1 Second      Memory Limit: 131072 KB BaoBao and DreamGrid are playing ...

  5. UVa 10603 Fill (暴力BFS+优先队列)

    题意:给定4个数,a,b,c,d,分别代表空杯子容积为a,b,一个盛满水的杯子容积为c,让你不断倒水,找一个dd,是不是存在某个时刻, 某个杯子里的水dd,和d相同,或者无限接近.让求最少的倒水量和d ...

  6. hdu 4771 13 杭州 现场 B - Stealing Harry Potter's Precious 暴力bfs 难度:0

    Description Harry Potter has some precious. For example, his invisible robe, his wand and his owl. W ...

  7. 八数码问题(一) 暴力BFS + STL

    八数码问题是一个经典的人工智能问题.具体问题不累述了. 思路:由于存在多组测试数据,可以考虑“打表法“.所谓打表法,即枚举所有的初始情况,记录其到达终点的路径.而在这个题目中,顺序打表会调用很多次BF ...

  8. Nearest number - 2_暴力&&bfs

    Description Input is the matrix A of N by N non-negative integers. A distance between two elements A ...

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

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

随机推荐

  1. checked多选,取消,反选

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  2. 初步认识ASP.NET WebForm

    C#可已进行以下两大类的开发 一.客户端应用程序C/S 主要有两种开发技术: 1.winForm windows窗体应用程序 2.WPF微软新一代图形框架 MFC(比较老的开发技术) MVVM(客户端 ...

  3. .NET回归 HTML----表单元素(1)和一些常用的标记

    表单就是-----用于搜集不同类型的用户输入. 表单元素指的是不同类型的 input 元素.复选框.单选按钮.提交按钮等等. 首先将表单元素分为三个类型.文本类,按钮类,选择类. 表单可以嵌套在表中, ...

  4. iOS  地图(自定义地位图标)

    #import <UIKit/UIKit.h> @interface AppDelegate : UIResponder <UIApplicationDelegate> @pr ...

  5. [转]CSS块级元素和行内元素

    原地址:http://www.studyofnet.com/news/398.html 本文导读:HTML中的元素可分为两种类型:块级元素和行级元素.这些元素的类型是通过文档类型定义(DTD)来指明. ...

  6. PCL—关键点检测(rangeImage)低层次点云处理

    博客转载自:http://www.cnblogs.com/ironstark/p/5046479.html 关键点又称为感兴趣的点,是低层次视觉通往高层次视觉的捷径,抑或是高层次感知对低层次处理手段的 ...

  7. 算法Sedgewick第四版-第1章基础-1.4 Analysis of Algorithms-005计测试算法

    1. package algorithms.analysis14; import algorithms.util.StdOut; import algorithms.util.StdRandom; / ...

  8. 树莓派研究笔记(10)-- Retropie 模拟器

    前面介绍过lakka模拟器,小巧,轻便,支持中文.其实最著名的游戏系统还是要属于Retropie啊.虽然笨重了一点,但是很多树莓派系统的原汁原味还是保留的很好.这样就不需要我们自己还要对lakka的源 ...

  9. WordCount小程序及测试

    Github项目地址:https://github.com/792450735/wc PSP表格: PSP2.1表格[1] PSP2.1 PSP阶段 预估耗时 (分钟) 实际耗时 (分钟) Plann ...

  10. Boot Option Menu

    SATA HDD:TOSHIBA MQ02ABF100    1000G SATA HDD:SAMSUNG MZVLW512HMJP-000L2   => Invalid Partition T ...