BAPC 2014:Button Bashing(暴力+bfs)
题意:
给出n,m,代表微波炉有n个按钮,要求达到总时间为m
然后给出n个数,代表n个按钮能增加的时间,问最少几步,能够使得按出的总时间大于等于要求的时间,并且相差最小
输出最小的步数与相差的最小值
要求,当总时间小于0时,时间为0,大于3600时,时间为3600
题意:
给出n,m,代表微波炉有n个按钮,要求达到总时间为m
然后给出n个数,代表n个按钮能增加的时间,问最少几步,能够使得按出的总时间大于等于要求的时间,并且相差最小
输出最小的步数与相差的最小值
要求,当总时间小于0时,时间为0,大于3600时,时间为3600
2
3 50
-10 10 60
1 50
20
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)的更多相关文章
- hdu 1195:Open the Lock(暴力BFS广搜)
Open the Lock Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- BAPC2014 B&&HUNNU11582:Button Bashing(BFS)
题意: 给出n,m,代表微波炉有n个button,要求达到总时间为m 然后给出n个数.代表n个button能添加的时间,问最少几步,可以使得按出的总时间大于等于要求的时间,而且相差最小 输出最小的步数 ...
- bzoj 1295: [SCOI2009]最长距离 暴力+bfs最短路
题目链接: http://www.lydsy.com/JudgeOnline/problem.php?id=1295 题解: 对每个点暴力跑一遍bfs,看能够到达的最远位置,这里如果有障碍物则距离为1 ...
- 青岛网络赛J-Press the button【暴力】
Press the Button Time Limit: 1 Second Memory Limit: 131072 KB BaoBao and DreamGrid are playing ...
- UVa 10603 Fill (暴力BFS+优先队列)
题意:给定4个数,a,b,c,d,分别代表空杯子容积为a,b,一个盛满水的杯子容积为c,让你不断倒水,找一个dd,是不是存在某个时刻, 某个杯子里的水dd,和d相同,或者无限接近.让求最少的倒水量和d ...
- 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 ...
- 八数码问题(一) 暴力BFS + STL
八数码问题是一个经典的人工智能问题.具体问题不累述了. 思路:由于存在多组测试数据,可以考虑“打表法“.所谓打表法,即枚举所有的初始情况,记录其到达终点的路径.而在这个题目中,顺序打表会调用很多次BF ...
- Nearest number - 2_暴力&&bfs
Description Input is the matrix A of N by N non-negative integers. A distance between two elements A ...
- 【最短路】BAPC2014 B Button Bashing (Codeforces GYM 100526)
题目链接: http://codeforces.com/gym/100526 http://acm.hunnu.edu.cn/online/?action=problem&type=show& ...
随机推荐
- 封装 Toast
一. ToastView.java 1 import android.content.Context; import android.view.LayoutInflater; import andro ...
- Python之路:面向对象及相关
其他相关 一.isinstance(obj, cls) 检查是否obj是否是类 cls 的对象 class Foo(object): pass obj = Foo() isinstan ...
- Struts2框架02 消息传递
1 消息传递 浏览器和服务器之间的数据传递 2 服务器项浏览器发送数据 2.1 在控制器类中增加一个属性,该属性的值就是服务器需要向浏览器发送的数据 2.2 为该属性增加 get 方法 2.3 在处理 ...
- Spring_01 spring容器、控制反转(IOC)、依赖注入(DI)
目录 1 什么是spring框架 2 spring框架的特点 3 spring容器 3.1 什么是spring容器 3.2 spring容器创建对象的编程步骤 3.4 spring容器创建对象的方式 ...
- IIC协议解释
IIC协议解释 (1)概述 I2C(Inter-Integrated Circuit BUS) 集成电路总线,该总线由NXP(原PHILIPS)公司设计,多用于主控制器和从器件间的主从通信,在小数据量 ...
- jqueue使用ajax方式
1.get: $.ajax({ type: "GET", url: baseUrl + "Showcontent/del_user?type=1&id=" ...
- Data Base oracle简单使用及管理工具使用
oracle简单使用及管理工具使用 一.常用工具: 1.sqldeveloper 2.navicat for oracle 3.PLSQL Developer 4.toad
- Puppeteer入门初探
本文来自网易云社区 作者:唐钊 最近在看 node 爬虫相关的一些东西,我记得还是很久以前常用的 node 爬虫工具还是 superagengt+cherrio,他们的思路是通过发起 http 请求然 ...
- 网易CentOS yum源
wget http://mirrors.163.com/.help/CentOS6-Base-163.repo
- eclipse - 链接hadoop
插件: 配置:Map/Reduce Location 问题:An internal error occurred during: "Map/Reduce location status up ...