Ural1437 Gasoline Station DFS

三个杯子倒来倒去。。。。能倒出多少容量。

超级暴力的一题。。。。。



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

#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>

using namespace std;

bool s[260][260][260];
bool vis[800];
int a,b,c;
int cnt;

void dfs(int l1,int l2,int l3){
    if(l1>a || l2>b || l3>c) return;
    if(l1<0 || l2<0 || l3<0) return;
    s[l1][l2][l3]=1;
    if(!vis[l1]){
        cnt++;
        vis[l1]=1;
    }
    if(!vis[l2]){
        cnt++;
        vis[l2]=1;
    }
    if(!vis[l3]){
        cnt++;
        vis[l3]=1;
    }
    if(!vis[l1+l2]){
        cnt++;
        vis[l1+l2]=1;
    }
    if(!vis[l1+l3]){
        cnt++;
        vis[l1+l3]=1;
    }
    if(!vis[l3+l2]){
        cnt++;
        vis[l3+l2]=1;
    }
    if(!vis[l1+l2+l3]){
        cnt++;
        vis[l1+l2+l3]=1;
        //cout<<l1+l2+l3<<endl;
    }
    int res1=a-l1,res2=b-l2,res3=c-l3;
    if(res1 && !s[a][l2][l3]) dfs(a,l2,l3);
    if(res2 && !s[l1][b][l3]) dfs(l1,b,l3);
    if(res3 && !s[l1][l2][c]) dfs(l1,l2,c);
    if(res1 && !s[l1+min(res1,l2)][max(l2-res1,0)][l3]) dfs(l1+min(res1,l2),max(l2-res1,0),l3);
    if(res1 && !s[l1+min(res1,l3)][l2][max(l3-res1,0)]) dfs(l1+min(res1,l3),l2,max(l3-res1,0));
    if(res2 && !s[max(0,l1-res2)][l2+min(res2,l1)][l3]) dfs(max(0,l1-res2),l2+min(res2,l1),l3);
    if(res2 && !s[l1][l2+min(res2,l3)][max(0,l3-res2)]) dfs(l1,l2+min(res2,l3),max(0,l3-res2));
    if(res3 && !s[max(0,l1-res3)][l2][l3+min(l1,res3)]) dfs(max(0,l1-res3),l2,l3+min(l1,res3));
    if(res3 && !s[l1][max(0,l2-res3)][l3+min(l2,res3)]) dfs(l1,max(0,l2-res3),l3+min(l2,res3));
}

int main(){
    while(~scanf("%d%d%d",&a,&b,&c)){
        memset(vis,0,sizeof(vis));
        memset(s,0,sizeof(s));
        vis[0]=1;cnt=0;
        dfs(0,0,0);
        printf("%d\n",cnt);
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值