正文
增加 7 行删除 7 行
1234567891011121314156 行未改动2223242526272829303 行未改动343536373839404142163 行未改动全部展开2062072082092102112122132149 行未改动22422522622722822923023123223323423523623723823943 行未改动# A公式:$$\text{ans} =\begin{cases}n/3 & \text{if } n \% 3 == 0 \\n/3 + 1 & \text{otherwise}\end{cases}$$对 $n≥2$ 都成立。# B因为时间无限,因此只需要找到小明可以做的练习册然后把价值相加即可。6 行未改动int n,m,v[505],d[505],ans=0;cin >>n>>m;for(int i=1;i<=n;i++) cin >>v[i]>>d[i];for(int i=1;i<=n;i++){if(d[i]<=m) ans+=v[i];}cout <<ans;return 0;}3 行未改动观察函数的形式,发现是递推,容易得到:$$\text{g(x)} =\begin{cases}y & \text{if } x=1 \\y^2(1+2+3+...+x-1) & \text{otherwise}\end{cases}163 行未改动全部展开pos = std::upper_bound(a.begin() + 1, a.end(), pos + x) - a.begin();if (pos == a.end() - a.begin()) break;pos = a[pos];}return ans;}void solve() {9 行未改动for (int i = 0; i <= 553; i++) {ans = std::min(ans, check(i));}std::cout << ans << '\n';}signed main() {std::ios::sync_with_stdio(0);std::cout.tie(0);std::cin.tie(0);i64 t = 1;// std::cin >> t;while (t--) {solve();}43 行未改动1234567891011121314156 行未改动2223242526272829303 行未改动343536373839404142163 行未改动全部展开2062072082092102112122132149 行未改动22422522622722822923023123223323423523623723823943 行未改动# A公式:$$\text{ans} =\begin{cases}n/3 & \text{if } n \% 3 == 0 \\n/3 + 1 & \text{otherwise}\end{cases}$$对 $n≥2$ 都成立。# B因为时间无限,因此只需要找到小明可以做的练习册然后把价值相加即可。6 行未改动int n,m,v[505],d[505],ans=0;cin >>n>>m;for(int i=1;i<=n;i++) cin >>v[i]>>d[i];for(int i=1;i<=n;i++){if(d[i]<=m) ans+=v[i];}cout <<ans;return 0;}3 行未改动观察函数的形式,发现是递推,容易得到:$$\text{g(x)} =\begin{cases}y & \text{if } x=1 \\y^2(1+2+3+...+x-1) & \text{otherwise}\end{cases}163 行未改动全部展开pos = std::upper_bound(a.begin() + 1, a.end(), pos + x) - a.begin();if (pos == a.end() - a.begin()) break;pos = a[pos];}return ans;}void solve() {9 行未改动for (int i = 0; i <= 553; i++) {ans = std::min(ans, check(i));}std::cout << ans << '\n';}signed main() {std::ios::sync_with_stdio(0);std::cout.tie(0);std::cin.tie(0);i64 t = 1;// std::cin >> t;while (t--) {solve();}43 行未改动