日常训练2025-1-5
L. Bridge Renovation
rating:1400
https://codeforces.com/problemset/problem/2038/L
思路(贪心)
需要思考每种板子的组合方式,最好的组合方式是两个2号板子和1个1号板子,加起来只消耗一块板子。
其次是三块1号板子加起来只消耗一块板子。
然后就是两块任意板子需要消耗一块板子。
代码
#include <bits/stdc++.h>typedef std::pair<int, int> pii;
#define INF 0x3f3f3f3f
#define MOD 998244353
using i64 = long long;
const int N = 1e5+5;void solve(){int n;std::cin >> n;if (n == 1){std::cout << 2 << '\n';return;}int ans = 0;int a = n, b = n, c = n;if (b % 2 == 0){ans += b / 2;a -= b / 2;b = 0;}else{ans += b / 2;a -= b / 2;b = 1;if (a >= 2){ans += 1;a -= 2;b = 0;}}if (a != 0){if (a % 3 == 1){ans += a / 3;ans += 1;c -= 1;a = 0;}else if (a % 3 == 2){ans += a / 3;ans += 1;a = 0;}else if (a % 3 == 0){ans += a / 3;a = 0;}}ans += c / 2;ans += c % 2 == 0 ? 0 : 1;std::cout << ans << '\n';
}signed main()
{std::ios::sync_with_stdio(false);std::cin.tie(nullptr);std::cout<<std::setiosflags(std::ios::fixed)<<std::setprecision(2);int t = 1, i;for (i = 0; i < t; i++){solve();}return 0;
}