思路讲解
我反正贪心过的,n比较小,所以全部是循环。
先尝试性价比比较高的,再尝试性价比比较低的
AC代码
https://codeforces.com/contest/2038/submission/293535960
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
| #include <iostream> #include <vector>
using namespace std; typedef long long ll;
void solve(ll n){ ll a=n,b=n,c=n; ll cnt=0; while (a>=1 && b>=2){ a-=1; b-=2; ++cnt; } while (a>=3) { a-=3; ++cnt; } while (a>=1 && c>=1){ a-=1,c-=1; ++cnt; } while (b>=1 && c>=1) { b-=1; c-=1; ++cnt; } while (c>=1) { c-=2; ++cnt; } while (b>=1) { b-=2; ++cnt; } while (a>=1) { a-=2; ++cnt; } cout<<cnt<<endl; }
int main() { ios::sync_with_stdio(false); cin.tie(0);cout.tie(0); ll n; cin>>n; solve(n); return 0; }
|
心路历程(WA,TLE,MLE……)