zoukankan      html  css  js  c++  java
  • 贪吃的小J

    https://www.luogu.com.cn/problem/P4817 

    # Description

    现在小J的胃的容量为0,她每吃一个orange,容量就会增加A;每吃一个lemon,饱食度就会增加B。小J还有一次喝水的机会,如果小J喝水前饱食度为x,喝水后饱食度会变为trunc(x/2)

    小J的胃的容量不能超过T,否则肚子会爆炸。
    试求小J的胃的容量最大能达到多少。

    # Format

    ## Input
    一行给出三个数字T,A,B
    1<=T<=5,000,000
    1<=A,B<=T

    ## Output
    如题
    # Samples

    ```input1
    8 5 6
    ```

    ```output1

    ```

    //76分 
    #include <iostream>
    using namespace std;
    
    int t, a, b;
    int ans;
    
    inline int maxa(int a, int b) {
    	if (a > b)
    		return a;
    	return b;
    }
    
    void dfs(int food, bool flag) {
    	ans = maxa(ans, food);
    	if (t >= food + a)
    		dfs(food + a, flag);
    	if (t >= food + b)
    		dfs(food + b, flag);
    	if (! flag)
    		dfs(food >> 1, flag ^ 1);
    	return ;
    }
    
    int main() {
    	cin >> t >> a >> b;
    	dfs(0, 0);
    	cout << ans << endl;
    	return 0;
    } 
    
    
    
    //ac
    #include <iostream>
    
    using namespace std;
    
    const int T = 5e6 + 7;
    
    int t, a, b;
    int ans;
    int mem[T];
    
    inline int maxa(int a, int b) {
    	if (a > b)
    		return a;
    	return b;
    }
    
    void dfs(int food, bool flag) {
    	if (mem[food])
    		return ;
    	mem[food] = 1;//就是这步!!
    	if (food > t)
    		return ;
    	ans = maxa(ans, food);
    	dfs(food + a, flag);
    	dfs(food + b, flag);
    	if (! flag)
    		dfs(food >> 1, flag ^ 1);
    	return ;
    }
    
    int main() {
    	cin >> t >> a >> b;
    	dfs(0, 0);
    	cout << ans << endl;
    	return 0;
    } 
    

      

  • 相关阅读:
    ios开发-2015-07-19
    ios开发-2015-07-18
    ios开发-2015-07-17
    ios开发-2015-07-16
    ios开发-2015-07-15
    ios开发-2015-07-14
    ios开发-2015-07-13
    Selenium源码分析之WebDriver
    webdriver实现原理 分类: Selenium 2015-07-16 00:16 11人阅读 评论(0) 收藏
    webdriver实现原理
  • 原文地址:https://www.cnblogs.com/cutemush/p/15317681.html
Copyright © 2011-2022 走看看