题目链接:

  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. int? 参数是这个的时候 是可以传入null的 而int的就不行

    such as     pager.CurrentPageIndex = (page != null ? (int)page : 1);

  2. android EventBus 的使用

    今天简单的介绍 一下啊 android  EventBus 的使用 EventBus 在官方介绍中是订阅......什么的 一大堆  ,  在我android 菜鸟眼里 就是用来代替android 广 ...

  3. ASP.NET mvc 遇见的问题

    1.数据库配置 The specified named connection is either not found in the configuration, not intended to be ...

  4. SQL Server中的死锁

    简介 死锁的本质是一种僵持状态,是多个主体对于资源的争用而导致的.理解死锁首先需要对死锁所涉及的相关观念有一个理解. 一些基础知识 要理解SQL Server中的死锁,更好的方式是通过类比从更大的面理 ...

  5. Objective-C的对象模型 http://foredoomed.org/blog/2014/02/24/object-modeling-of-objective-c/

    Objective-C是一门面向对象,并且在C的基础上加入了Smalltalk式的消息机制而形成的编程语言,它主要被苹果公司用于开发Mac OS X和iOS操作系统.既然Objective-C是面向对 ...

  6. hdoj 2041 超级阶梯

    代码: #include <stdio.h>int main(){int n;int i;int m;int count;int dp[50];while(scanf("%d&q ...

  7. 【POJ2887】【块状链表】Big String

    Description You are given a string and supposed to do some string manipulations. Input The first lin ...

  8. javascript——处理(获取)浏览器版本、操作系统

    javascript——处理(获取)浏览器版本.操作系统 /** * Created by Administrator on 15-1-12. */ function BroswerUtil() { ...

  9. Oracle数据库之动态SQL

    Oracle数据库之动态SQL 1. 静态SQLSQL与动态SQL Oracle编译PL/SQL程序块分为两个种:一种为前期联编(early binding),即SQL语句在程序编译期间就已经确定,大 ...

  10. js对象的复制,传递,新增,删除和比较

    当我们把一个某个对象拷贝或者传递给某个函数时,往往传递的是该对象的引用. 因此我们在引用上做的任何改动,都将会影响到它所引用的原对象.  复制,拷贝  var o = { add: 'Changdao ...