题目链接:

  http://codeforces.com/gym/100526

  http://acm.hunnu.edu.cn/online/?action=problem&type=show&id=11665&courseid=0

题目大意:

  一个微波炉,有N个按钮,每个按钮可以让时间加或减一个数,问达到M至少需要按几次按钮。(N<=16,0<=M<=3600)

  如果无法达到M输出比M大的最小的值需要按的次数和这个值与M的差值。注意微波炉的时间满足0<=当前时间<=3600。如果超过则取边界。

题目思路:

  【最短路】

  初始状态d[0]=0之后按N个按钮所加的值往下扩展。每次扩展d+1.最后找d[M]和M之后第一个出现的可行解。

  SPFA或BFS即可。

 //
//by coolxxx
//#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<iomanip>
#include<map>
#include<memory.h>
#include<time.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
//#include<stdbool.h>
#include<math.h>
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define abs(a) ((a)>0?(a):(-(a)))
#define lowbit(a) (a&(-a))
#define sqr(a) ((a)*(a))
#define swap(a,b) ((a)^=(b),(b)^=(a),(a)^=(b))
#define mem(a,b) memset(a,b,sizeof(a))
#define eps (1e-8)
#define J 10
#define mod 1000000007
#define MAX 0x7f7f7f7f
#define PI 3.14159265358979323
#define N 24
#define M 3604
using namespace std;
typedef long long LL;
int cas,cass;
int n,m,lll,ans;
int t;
int b[N];
int q[M],d[M];
bool u[M];
void spfa()
{
int i,now,to,l=,r=;
mem(d,0x7f);
q[]=;d[]=;
while(l!=r)
{
now=q[l=(l+)%M];
u[now]=;
for(i=;i<=n;i++)
{
to=now+b[i];
to=max(to,);
to=min(to,);
if(d[to]>d[now])
{
d[to]=d[now]+;
if(!u[to])
{
u[to]=;
q[r=(r+)%M]=to;
}
}
}
}
for(i=t;i<=;i++)
if(d[i]!=MAX)break;
printf("%d %d\n",d[i],i-t);
}
int main()
{
#ifndef ONLINE_JUDGE
// freopen("1.txt","r",stdin);
// freopen("2.txt","w",stdout);
#endif
int i,j,k;
int x,y,way;
for(scanf("%d",&cas);cas;cas--)
// for(scanf("%d",&cas),cass=1;cass<=cas;cass++)
// while(~scanf("%s",s+1))
// while(~scanf("%d",&n))
{
scanf("%d%d",&n,&t);
for(i=;i<=n;i++)
{
scanf("%d",&b[i]);
}
spfa();
}
return ;
}
/*
// //
*/

【最短路】BAPC2014 B Button Bashing (Codeforces GYM 100526)的更多相关文章

  1. 【线段树】BAPC2014 E Excellent Engineers (Codeforces GYM 100526)

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

  2. 【扩展欧几里得】BAPC2014 I Interesting Integers (Codeforces GYM 100526)

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

  3. 【宽搜】BAPC2014 J Jury Jeopardy (Codeforces GYM 100526)

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

  4. 【模拟】BAPC2014 G Growling Gears (Codeforces GYM 100526)

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

  5. 【中途相遇法】【STL】BAPC2014 K Key to Knowledge (Codeforces GYM 100526)

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

  6. 【最大流】BAPC2014 A Avoiding the Apocalypse (Codeforces GYM 100526)

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

  7. Codeforces Gym 101252D&&floyd判圈算法学习笔记

    一句话题意:x0=1,xi+1=(Axi+xi%B)%C,如果x序列中存在最早的两个相同的元素,输出第二次出现的位置,若在2e7内无解则输出-1. 题解:都不到100天就AFO了才来学这floyd判圈 ...

  8. Codeforces Gym 101190M Mole Tunnels - 费用流

    题目传送门 传送门 题目大意 $m$只鼹鼠有$n$个巢穴,$n - 1$条长度为$1$的通道将它们连通且第$i(i > 1)$个巢穴与第$\left\lfloor \frac{i}{2}\rig ...

  9. Codeforces Gym 101623A - 动态规划

    题目传送门 传送门 题目大意 给定一个长度为$n$的序列,要求划分成最少的段数,然后将这些段排序使得新序列单调不减. 考虑将相邻的相等的数缩成一个数. 假设没有分成了$n$段,考虑最少能够减少多少划分 ...

随机推荐

  1. Web的鼠标拖动效果

    以前写过一个拖动效果的Demo,拖拽元素新位置的计算是放在拖拽元素的mousemove事件中进行的.计算效率差,而且效果不好.所以一直有想怎样才能做出jquery-ui那种顺滑的拖拽效果. 其实顺滑的 ...

  2. MVC4将Controller与views分开

    最近自己在要着手从头做一个项目,自己想把mvc里的view和controller文件分别写在不同的项目里,刚开始在网上找了下,可是不尽理想,最后翻了一下自己以前参加的项目找到了这个做法. 这个需要在G ...

  3. 我的网站终于连续一星期,ip数1000以上了

    相信每个程序员都有一个站长梦,我也是如此.说来惭愧,从2015年4月份开始,我投入了50块的域名费用,50块的空间费用,现在才回本. 由于终于从百度联盟的手里赚了一百块,按耐不住的菜鸟之冲动,于是决定 ...

  4. HTML5 TypeArray和Unicode 字符之间转换

    1.Uint32Array测试成功 // Uint32Array 测试成功 //字符串转为ArrayBuffer对象 function strToab() { var str = '张三丰'; var ...

  5. 浅谈Android系统的图标设计规范

    http://homepage.yesky.com/89/11620089.shtml 目前移动平台的竞争日益激烈,友好的用户界面可以帮助提高用户体验满意度,图标Icon是用户界面中一个重要的组成部分 ...

  6. [o] duplicate column name: _id 问题解决

    Android下使用SQLite数据库,报错:duplicate column name: _id 数据库文件下有两列数据的名称一样,原因是定义数据类型时有重复,如,我的定义: //复制上一行增加TY ...

  7. 抓取锁的sql语句-第七次修改

    最近闲来没事,把之前写的那个抓取锁的存储过程重新修改.优化了一下,呵呵 create or replace procedure solve_lock_061203_wanjie(v_msg out v ...

  8. spring jdbctemplate调用procedure(返回游标)

    package cn.com.git.htsc.uac.core.repository.report; import cn.com.git.htsc.uac.core.api.dto.report.R ...

  9. FlightGear 视角控制

    Flightgear提供了非常灵活的模块化功能 这里就简要记录一下视角切换功能 首先,需要了解一下Flightgear中的property tree的主要内容,这里暂略. http://wiki.fl ...

  10. SGU 224.Little Queens

    时间限制:0.75s 空间限制:6M 题意 n*n(n<=10)的棋盘,求出放置m(m<=n*n)个皇后的方案数. Solution: 状态压缩+位运算  搜索. 首先我们从上往下逐行放置 ...