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. ajax异步验证用户名密码,提示路径错误

    使用thinkphp框架异步验证用户名和密码的时候,ajax路径错误可能有多重情况.我遇到的是,我自感路径没问题,且先前使用无错.由于多人合作使用svn,所以在更新代码后,使用firebug显示一直是 ...

  2. linux-统计一个文件中出现的单词数

    #!/bin/bash ] then echo "Usage: $0 filename"; exit - fi filename=$ egrep -o "\b[[:alp ...

  3. iOS开发之 Xcode6 添加xib文件,去掉storyboard的hello world应用

    iOS开发之  Xcode6.1创建仅xib文件,无storyboard的hello world应用 由于Xcode6之后,默认创建storyboard而非xib文件,而作为初学,了解xib的加载原理 ...

  4. html表单-双向绑定

    潜水多年.一直是只看不评不写多年,每每看到各位大牛分享的经典文章都是默默的收藏,对大牛技术分享技术表示感谢,这么多年从博客园学到了很多. 这段时间项目告一段落. 正好这段时间相对清闲,我也整理一些常用 ...

  5. hdu 1874 畅通工程续(最短路)

    最短路问题! 最简单的最短路问题! 恩! #include<stdio.h> #define MAX 1000000 int map[500][500]; int n,m,start,en ...

  6. CodeForces 294B Shaass and Bookshelf 【规律 &amp; 模拟】或【Dp】

    这道题目的意思就是排两排书,下面这排只能竖着放,上面这排可以平着放,使得宽度最小 根据题意可以得出一个结论,放上这排书的Width 肯定会遵照从小到大的顺序放上去的 Because the total ...

  7. [Swift]LeetCode563. 二叉树的坡度 | Binary Tree Tilt

    Given a binary tree, return the tilt of the whole tree. The tilt of a tree node is defined as the ab ...

  8. C# ftp 上传、下载、删除

    public class FtpHelper { public static readonly FtpHelper Instance = new FtpHelper(); /// <summar ...

  9. 对象序列化:pickle和shelve

    import pickle class DVD: def __init__(self,tilte,year=None,duration=None,director_id=None): self.tit ...

  10. Eclipse.修改项目的JDK版本

    1.我实际使用过程中,只是修改了 项目右键-->Properties-->左侧选择"Java Compiler" -->右侧的"JDK Complian ...