1437. Gasoline Station

Time limit: 1.0 second
Memory limit: 64 MB
Once a gasoline meter broke at a filling station. Fortunately, there was an overflow clipper (a device that makes it possible not to overfill a tank).
An ACM-programmer came to this station and saw an announcement saying that the station didn't work properly. As he was meditating on what to do next, he noticed three empty cans at the station's counter. He thought: "If I fill the first can and then empty it to the second one, and then take the third one… Maybe, I'll be able to measure out the needed amount of gasoline?"
As usual, he began to think about a general formulation of the problem, forgetting the partial case: "How many different capacities can I measure out using these cans?"
Of course, it is forbidden to spill gasoline because of ecology reasons. Also, the station's owner requires that gasoline only be transferred from the storage tank to a can or between cans. The car's tank may be filled from one or several of the cans only after all of the transfers.

Input

Each of the three input lines contains an integer from 0 to 255, which is the capacity of a gasoline can in liters.

Output

The result is an integer that is the number of different answers to the question how many liters the programmer can measure out using the gasoline cans with the specified capacities.

Sample

input output
0
3
4
6

Notes

There is no sense to measure out 0 liters, so this value must not be counted.
Problem Author: Alexey Lakhtin
Problem Source: The 7th USU Open Personal Contest - February 25, 2006
Difficulty: 570
 
题意:经典倒水问题,问三个不同容量、没有刻度的杯子,只能加水,且只能一次加满,可以在杯子间互相倒水,水不能倒掉,问能得到多少种不同体积的水?
分析:记忆化搜索。
真的一句话就够了。。。
 
 /**
Create By yzx - stupidboy
*/
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <ctime>
#include <iomanip>
using namespace std;
typedef long long LL;
typedef double DB;
#define For(i, s, t) for(int i = (s); i <= (t); i++)
#define Ford(i, s, t) for(int i = (s); i >= (t); i--)
#define Rep(i, t) for(int i = (0); i < (t); i++)
#define Repn(i, t) for(int i = ((t)-1); i >= (0); i--)
#define rep(i, x, t) for(int i = (x); i < (t); i++)
#define MIT (2147483647)
#define INF (1000000001)
#define MLL (1000000000000000001LL)
#define sz(x) ((int) (x).size())
#define clr(x, y) memset(x, y, sizeof(x))
#define puf push_front
#define pub push_back
#define pof pop_front
#define pob pop_back
#define ft first
#define sd second
#define mk make_pair inline int Getint()
{
int Ret = ;
char Ch = ' ';
bool Flag = ;
while (!(Ch >= '' && Ch <= ''))
{
if (Ch == '-') Flag ^= ;
Ch = getchar();
}
while (Ch >= '' && Ch <= '')
{
Ret = Ret * + Ch - '';
Ch = getchar();
}
return Flag ? -Ret : Ret;
} const int N = * + , M = ;
int Arr[], Now[];
bool Visit[M][M][M], Ans[N];
int Answer; inline void Input()
{
Rep(i, ) cin >> Arr[i];
Rep(i, ) swap(Arr[i], Arr[rand() % ]);
} inline void Full(int *Can, int x, int y)
{
int t = min(Can[x], Arr[y] - Can[y]);
Can[x] -= t;
Can[y] += t;
} inline void Search(int *Can)
{
int x = Can[], y = Can[], z = Can[];
if (Visit[x][y][z]) return;
Visit[x][y][z] = ;
//cout << x << ' ' << y << ' ' << z << endl;
Rep(i, )
if (!Ans[Can[i]]) Ans[Can[i]] = ;
Rep(i, )
Rep(j, )
if (i != j && !Ans[Can[i] + Can[j]])
Ans[Can[i] + Can[j]] = ;
if (!Ans[Can[] + Can[] + Can[]])
Ans[Can[] + Can[] + Can[]] = ; int tmp[];
Rep(i, ) tmp[i] = Can[i];
Rep(i, )
Rep(j, )
if (i != j)
{
Full(tmp, i, j);
Search(tmp);
tmp[i] = Can[i];
tmp[j] = Can[j];
}
Rep(i, )
{
tmp[i] = Arr[i];
Search(tmp);
tmp[i] = Can[i];
}
} inline void Solve()
{
Rep(i, )
if (Arr[i] == )
{
cout << Arr[] + Arr[] + Arr[] << endl;
return;
} Search(Now); Answer = ;
For(i, , N - )
{
Answer += Ans[i];
//if(Ans[i]) cout << i << endl;
} cout << Answer << endl;
} int main()
{
//SetIO("G");
Input();
Solve();
return ;
}

ural 1437. Gasoline Station的更多相关文章

  1. 九度OJ 1437 To Fill or Not to Fill -- 贪心算法

    题目地址:http://ac.jobdu.com/problem.php?pid=1437 题目描述: With highways available, driving a car from Hang ...

  2. 九度oj 1437 To Fill or Not to Fill 2012年浙江大学计算机及软件工程研究生机试真题

    题目1437:To Fill or Not to Fill 时间限制:1 秒 内存限制:128 兆 特殊判题:否 提交:1488 解决:345 题目描述: With highways availabl ...

  3. 九度OJ #1437 To Fill or Not to Fil

    题目描写叙述: With highways available, driving a car from Hangzhou to any other city is easy. But since th ...

  4. URAL 1277 Cops and Thieves

    Cops and Thieves Time Limit: 1000ms Memory Limit: 16384KB This problem will be judged on Ural. Origi ...

  5. [LeetCode] Gas Station 加油站问题

    There are N gas stations along a circular route, where the amount of gas at station i is gas[i]. You ...

  6. PAT 1072. Gas Station (30)

    A gas station has to be built at such a location that the minimum distance between the station and a ...

  7. Leetcode 134 Gas Station

    There are N gas stations along a circular route, where the amount of gas at station i is gas[i]. You ...

  8. POJ 2031 Building a Space Station

    3维空间中的最小生成树....好久没碰关于图的东西了.....              Building a Space Station Time Limit: 1000MS   Memory Li ...

  9. 【leetcode】Gas Station

    Gas Station There are N gas stations along a circular route, where the amount of gas at station i is ...

随机推荐

  1. HDU 2577 How to Type(dp题)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2577 解题报告:有一个长度在100以内的字符串,并且这个字符串只有大写和小写字母组成,现在要把这些字符 ...

  2. Unity3D Optimizing Graphics Performance for iOS

    原地址:http://blog.sina.com.cn/s/blog_72b936d801013ptr.html icense Comparisons http://unity3d.com/unity ...

  3. 搭建自己的ngrok服务

    转载:http://tonybai.com/2015/03/14/selfhost-ngrok-service/ 在国内开发微信公众号.企业号以及做前端开发的朋友想必对ngrok都不陌生吧,就目前来看 ...

  4. [原创]DELPHI木马DIY之生成服务端

    文章作者:上帝的禁区信息来源:邪恶八进制信息安全团队(www.eviloctal.com)DELPHI木马DIY之生成服务端   我在这里就生成简单的服务端,为什么不先讲服务端的隐藏?因为我觉得生成服 ...

  5. mysql 启动错误

    错误提示如下: 150815 20:24:40 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended150815 20:2 ...

  6. Linux 查看网络连接状态

    CLOSED:无连接是活动的或正在进行ESTABLISED:已建立连线的状态:SYN_SENT:发出主动连线 (SYN 标志) 的连线封包:SYN_RECV:接收到一个要求连线的主动连线封包:FIN_ ...

  7. Mysql增删改

    改 UPDATE tbl_name SET 字段名=值,...[WHERE 条件][ORDER BY 字段名称][LIMIT限制条数] --更新用户名为4位的用户,让其以有年龄-3 UPDATA SE ...

  8. SpringMVC请求处理流程

    从web.xml中 servlet的配置开始, 根据servlet拦截的url-parttern,来进行请求转发   Spring MVC工作流程图   图一   图二    Spring工作流程描述 ...

  9. 【leetcode】Longest Consecutive Sequence

    Longest Consecutive Sequence Given an unsorted array of integers, find the length of the longest con ...

  10. WPF 将PPT,Word转成图片

    在Office下,PowerPoint可以直接把每张幻灯片转成图片,而Word不能直接保存图片.所以只能通过先转换成xps文件,然后再转成图片. 一.PPT 保存为图片 /// <summary ...