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 ...
随机推荐
- ajax异步验证用户名密码,提示路径错误
使用thinkphp框架异步验证用户名和密码的时候,ajax路径错误可能有多重情况.我遇到的是,我自感路径没问题,且先前使用无错.由于多人合作使用svn,所以在更新代码后,使用firebug显示一直是 ...
- linux-统计一个文件中出现的单词数
#!/bin/bash ] then echo "Usage: $0 filename"; exit - fi filename=$ egrep -o "\b[[:alp ...
- iOS开发之 Xcode6 添加xib文件,去掉storyboard的hello world应用
iOS开发之 Xcode6.1创建仅xib文件,无storyboard的hello world应用 由于Xcode6之后,默认创建storyboard而非xib文件,而作为初学,了解xib的加载原理 ...
- html表单-双向绑定
潜水多年.一直是只看不评不写多年,每每看到各位大牛分享的经典文章都是默默的收藏,对大牛技术分享技术表示感谢,这么多年从博客园学到了很多. 这段时间项目告一段落. 正好这段时间相对清闲,我也整理一些常用 ...
- hdu 1874 畅通工程续(最短路)
最短路问题! 最简单的最短路问题! 恩! #include<stdio.h> #define MAX 1000000 int map[500][500]; int n,m,start,en ...
- CodeForces 294B Shaass and Bookshelf 【规律 &; 模拟】或【Dp】
这道题目的意思就是排两排书,下面这排只能竖着放,上面这排可以平着放,使得宽度最小 根据题意可以得出一个结论,放上这排书的Width 肯定会遵照从小到大的顺序放上去的 Because the total ...
- [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 ...
- C# ftp 上传、下载、删除
public class FtpHelper { public static readonly FtpHelper Instance = new FtpHelper(); /// <summar ...
- 对象序列化:pickle和shelve
import pickle class DVD: def __init__(self,tilte,year=None,duration=None,director_id=None): self.tit ...
- Eclipse.修改项目的JDK版本
1.我实际使用过程中,只是修改了 项目右键-->Properties-->左侧选择"Java Compiler" -->右侧的"JDK Complian ...