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.util.properties的随笔
public class Propertiesextends Hashtable<Object,Object> Properties 类表示了一个持久的属性集.Properties 可保存 ...
- hibernate映射数据库时@ManyToOne和@OneToMany
第一次用hibernate自动生成表,涉及到多个表的外键,用到了@OneToMany和@ManyToOne注解碰到了几个错误. 首先声明一个基础,@OneToMany和@ManyToOne两个注解没有 ...
- jQuery导航插件One-Page-Nav演示-显示命名锚记
jQuery导航插件One-Page-Nav演示-显示命名锚记 简介 使用 选项 示例 推荐 简介 电商网站的分类比较明确,比如1楼是手机通讯产品,2楼是家用电器,3楼是服装鞋包等等,旁边还会有一个固 ...
- python mongodb压力测试脚本
$ pip install pymongo #!/usr/bin/env python #coding=utf-8 #Author: Ca0Gu0 from pymongo import MongoC ...
- struts2_validate表单验证
使用代码实现 验证功能 (也就是重写ActionSupport中的validate()方法) 在validate方法中进行编写我们需要的验证功能 这里需要提几点的就是: 1.当我们需要对action中 ...
- Apache、Nginx与Tomcat的区别
一. 定义: 1. Apache Apache HTTP服务器是一个模块化的服务器,可以运行在几乎所有广泛使用的计算机平台上.其属于应用服务器.Apache支持支持模块多,性能稳定,A ...
- C# 获得Properties下的定义的资源
var str1 = Properties.Resources.ResourceManager.GetObject("String1", null); string url = S ...
- ESX/ESXi 主机的某些存储阵列可能存在读取或写入性能问题 (1002598)
Last Updated: 12/14/2018Categories: Troubleshooting Details 免责声明:本文为 ESX/ESXi hosts might experienc ...
- Python学习【第7篇】:Python之常用模块2
hashlib,configparser,logging模块 一.常用模块二 hashlib模块 hashlib提供了常见的摘要算法,如md5和sha1等等. 那么什么是摘要算法呢?摘要算法又称为哈希 ...
- Codeforces 918C/917A - The Monster
传送门:http://codeforces.com/contest/918/problem/C 一个括弧串由字符‘(’和‘)’组成.一个正确的串可被递归地定义,定义如下: ①空串e是一个正确的串: ② ...