Ural1876(貪心)

題目鏈接:點擊打開鏈接


解題思路:

按照兩個方面來貪:首先第一點,我們可以想到先將所有右腳的鞋子穿完,然後把所有剩餘的右腳鞋子丟掉,最後穿夠左腳即可。即b * 2 + 40;

第二點,我們先穿39個右腳的鞋子,然後穿40個左腳的鞋子,之後我們把所有剩下的左腳鞋子丟掉,最後再花1s時間穿1個右腳鞋子。即39 * 2 + 40  + 2 * (a - 40) + 1;

二者中取最大值即可。


完整代碼:

#include <algorithm>
#include <iostream>
#include <cstring>
#include <climits>
#include <cstdio>
#include <string>
#include <cmath>
#include <map>
#include <queue>
using namespace std;
typedef long long LL;
const int MOD = int(1e9)+7;
const int INF = 0x3f3f3f3f;
const double EPS = 1e-9;
const double PI = acos(-1.0); //M_PI;

int main()
{
    #ifdef DoubleQ
    freopen("in.txt","r",stdin);
    #endif
    int a , b;
    while(cin >> a >> b)
    {
        int res = max( b * 2 + 40 , 119 + 2 * (a - 40) );
        cout << res << endl;
    }
}

更多精彩請訪問:點擊打開鏈接
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章