Ural1876(贪心)

来源:互联网 发布:拓客宝软件怎么收费 编辑:程序博客网 时间:2024/05/18 00:25

题目链接:点击打开链接


解题思路:

按照两个方面来贪:首先第一点,我们可以想到先将所有右脚的鞋子穿完,然后把所有剩余的右脚鞋子丢掉,最后穿够左脚即可。即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;    }}

更多精彩请访问:点击打开链接

0 0
原创粉丝点击