AtCoder Beginner Contest 251

比赛链接

AtCoder Beginner Contest 251

D - At Most 3 (Contestant ver.)

Problem Statement

You are given an integer W.
You are going to prepare some weights so that all of the conditions below are satisfied.

  • The number of weights is between 1 and 300 , inclusive.
  • Each weight has a mass of positive integer not exceeding 106.
  • Every integer between 1 and W, inclusive, is a good integer. Here, a positive integer n is said to be a good integer if the following condition is satisfied:
    • We can choose at most 3 different weights from the prepared weights with a total mass of n.

Print a combination of weights that satisfies the conditions.

Constraints

  • 1W106
  • W is an integer.

解题思路

思维,构造

构造这样一些数:
99 个:1,2,3,,99  (1)
99 个:100,200,300,,9900  (2)
99 个:10000,20000,30000,,990000  (2)
297 个数
显然,一和二位的数已经存在,对于三位的数,可用 (1)(2) 组合,故可用 2 个数得到三位数,此时存在的四位数为 1000,1100,1200,,9900,可以 (1) 与这些数组合得到任意四位数,即可用 2 个数得到四位数,此时存在的五位数为 10000,20000,30000,,\90000,可用四位数与其组合成任意五位数,即可用 3 个数得到五位数,另外,1000000 可用 99000010000 得到

  • 时间复杂度:O(1)

代码

// Problem: D - At Most 3 (Contestant ver.) // Contest: AtCoder - Panasonic Programming Contest 2022(AtCoder Beginner Contest 251) // URL: https://atcoder.jp/contests/abc251/tasks/abc251_d // Memory Limit: 1024 MB // Time Limit: 2000 ms // // Powered by CP Editor (https://cpeditor.org) // %%%Skyqwq #include <bits/stdc++.h> //#define int long long #define help {cin.tie(NULL); cout.tie(NULL);} #define pb push_back #define fi first #define se second #define mkp make_pair using namespace std; typedef long long LL; typedef pair<int, int> PII; typedef pair<LL, LL> PLL; template <typename T> bool chkMax(T &x, T y) { return (y > x) ? x = y, 1 : 0; } template <typename T> bool chkMin(T &x, T y) { return (y < x) ? x = y, 1 : 0; } template <typename T> void inline read(T &x) { int f = 1; x = 0; char s = getchar(); while (s < '0' || s > '9') { if (s == '-') f = -1; s = getchar(); } while (s <= '9' && s >= '0') x = x * 10 + (s ^ 48), s = getchar(); x *= f; } int main() { int w; cin>>w; cout<<297<<'\n'; for(int i=1;i<=99;i++)cout<<i<<' '<<i*100<<' '<<i*10000<<' '; return 0; }

__EOF__

本文作者acwing_zyy
本文链接https://www.cnblogs.com/zyyun/p/16271725.html
关于博主:评论和私信会在第一时间回复。或者直接私信我。
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
声援博主:如果您觉得文章对您有帮助,可以点击文章右下角推荐一下。您的鼓励是博主的最大动力!
posted @   zyy2001  阅读(144)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!
点击右上角即可分享
微信分享提示