ural 1437. Gasoline Station
1437. Gasoline Station
Memory limit: 64 MB
Input
Output
Sample
input | output |
---|---|
0 |
6 |
Notes
Problem Source: The 7th USU Open Personal Contest - February 25, 2006
/**
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的更多相关文章
- 九度OJ 1437 To Fill or Not to Fill -- 贪心算法
题目地址:http://ac.jobdu.com/problem.php?pid=1437 题目描述: With highways available, driving a car from Hang ...
- 九度oj 1437 To Fill or Not to Fill 2012年浙江大学计算机及软件工程研究生机试真题
题目1437:To Fill or Not to Fill 时间限制:1 秒 内存限制:128 兆 特殊判题:否 提交:1488 解决:345 题目描述: With highways availabl ...
- 九度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 ...
- URAL 1277 Cops and Thieves
Cops and Thieves Time Limit: 1000ms Memory Limit: 16384KB This problem will be judged on Ural. Origi ...
- [LeetCode] Gas Station 加油站问题
There are N gas stations along a circular route, where the amount of gas at station i is gas[i]. You ...
- 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 ...
- 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 ...
- POJ 2031 Building a Space Station
3维空间中的最小生成树....好久没碰关于图的东西了..... Building a Space Station Time Limit: 1000MS Memory Li ...
- 【leetcode】Gas Station
Gas Station There are N gas stations along a circular route, where the amount of gas at station i is ...
随机推荐
- HDU 2577 How to Type(dp题)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2577 解题报告:有一个长度在100以内的字符串,并且这个字符串只有大写和小写字母组成,现在要把这些字符 ...
- Unity3D Optimizing Graphics Performance for iOS
原地址:http://blog.sina.com.cn/s/blog_72b936d801013ptr.html icense Comparisons http://unity3d.com/unity ...
- 搭建自己的ngrok服务
转载:http://tonybai.com/2015/03/14/selfhost-ngrok-service/ 在国内开发微信公众号.企业号以及做前端开发的朋友想必对ngrok都不陌生吧,就目前来看 ...
- [原创]DELPHI木马DIY之生成服务端
文章作者:上帝的禁区信息来源:邪恶八进制信息安全团队(www.eviloctal.com)DELPHI木马DIY之生成服务端 我在这里就生成简单的服务端,为什么不先讲服务端的隐藏?因为我觉得生成服 ...
- mysql 启动错误
错误提示如下: 150815 20:24:40 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended150815 20:2 ...
- Linux 查看网络连接状态
CLOSED:无连接是活动的或正在进行ESTABLISED:已建立连线的状态:SYN_SENT:发出主动连线 (SYN 标志) 的连线封包:SYN_RECV:接收到一个要求连线的主动连线封包:FIN_ ...
- Mysql增删改
改 UPDATE tbl_name SET 字段名=值,...[WHERE 条件][ORDER BY 字段名称][LIMIT限制条数] --更新用户名为4位的用户,让其以有年龄-3 UPDATA SE ...
- SpringMVC请求处理流程
从web.xml中 servlet的配置开始, 根据servlet拦截的url-parttern,来进行请求转发 Spring MVC工作流程图 图一 图二 Spring工作流程描述 ...
- 【leetcode】Longest Consecutive Sequence
Longest Consecutive Sequence Given an unsorted array of integers, find the length of the longest con ...
- WPF 将PPT,Word转成图片
在Office下,PowerPoint可以直接把每张幻灯片转成图片,而Word不能直接保存图片.所以只能通过先转换成xps文件,然后再转成图片. 一.PPT 保存为图片 /// <summary ...