CF - 44C - Holidays

本文介绍了一个CodeForces上的经典问题:如何安排人员浇花以确保每朵花每天都能被浇一次且不重复。通过使用C++实现算法,详细记录了每朵花被浇水的次数,并给出了解决方案。

题意:n天假,安排m个人来浇花,第i个人负责[ai, bi]天,问花是否可以每天都被浇水且不重复,可以的话输出“OK”,不可以的话输出最早出问题的那天的天号以及那天花被浇了多少次水(1 ≤ n, m ≤ 100, 1 ≤ ai ≤ bi ≤ n,bi ≤ ai + 1)。

题目链接:http://codeforces.com/problemset/problem/44/C

——>>记录花各天被浇了多少次。

#include <cstdio>
#include <cstring>

using namespace std;

const int maxn = 100 + 10;
int a[maxn], n, m;

void solve(){
    int l, r;
    memset(a, 0, sizeof(a));
    for(int i = 0; i < m; i++){
        scanf("%d%d", &l, &r);
        for(int j = l; j <= r; j++) a[j]++;
    }
    bool ok = 1;
    for(int i = 1; i <= n; i++) if(a[i] != 1){
        printf("%d %d\n", i, a[i]);
        return;
    }
    if(ok) puts("OK");
}

int main()
{
    while(scanf("%d%d", &n, &m) == 2) solve();
    return 0;
}


(venv) gapinyc@DESKTOP-9QS7RL5:~/superset$ cat requirements.txt aiohappyeyeballs==2.6.1 aiohttp==3.13.1 aiosignal==1.4.0 alembic==1.17.0 amqp==5.3.1 -e git+ssh://git@github.com/apache/superset.git@465e2a9631994892cf399d13dd926c56cecd58ca#egg=apache_superset apispec==6.8.4 apsw==3.50.4.0 async-timeout==5.0.1 attrs==25.4.0 babel==2.17.0 backoff==2.2.1 backports-datetime-fromisoformat==2.0.3 backports.zstd==1.0.0 bcrypt==5.0.0 billiard==4.2.2 blinker==1.9.0 Bottleneck==1.6.0 Brotli==1.1.0 cachelib==0.13.0 cachetools==6.2.1 cattrs==25.3.0 celery==5.5.3 certifi==2025.10.5 cffi==2.0.0 charset-normalizer==3.4.4 click==8.3.0 click-didyoumean==0.3.1 click-option-group==0.5.9 click-plugins==1.1.1.2 click-repl==0.3.0 colorama==0.4.6 cron_descriptor==2.0.6 croniter==6.0.0 cryptography==43.0.3 defusedxml==0.7.1 Deprecated==1.2.18 deprecation==2.1.0 dnspython==2.8.0 email-validator==2.3.0 et_xmlfile==2.0.0 exceptiongroup==1.3.0 Flask==2.3.3 Flask-AppBuilder==4.8.1 Flask-Babel==2.0.0 Flask-Caching==2.3.1 Flask-Compress==1.20 Flask-JWT-Extended==4.7.1 Flask-Limiter==3.12 Flask-Login==0.6.3 Flask-Migrate==3.1.0 Flask-Session==0.8.0 Flask-SQLAlchemy==2.5.1 flask-talisman==1.1.0 Flask-WTF==1.2.2 frozenlist==1.8.0 geographiclib==2.1 geopy==2.4.1 google-auth==2.41.1 greenlet==3.1.1 gunicorn==23.0.0 h11==0.16.0 hashids==1.3.1 holidays==0.25 humanize==4.14.0 idna==3.11 importlib_metadata==8.7.0 invoke==2.2.1 isodate==0.7.2 itsdangerous==2.2.0 Jinja2==3.1.6 jsonpath-ng==1.7.0 jsonschema==4.25.1 jsonschema-specifications==2025.9.1 kombu==5.5.4 korean-lunar-calendar==0.3.1 limits==5.6.0 Mako==1.3.10 Markdown==3.9 markdown-it-py==4.0.0 MarkupSafe==3.0.3 marshmallow==3.26.1 marshmallow-sqlalchemy==1.4.2 mdurl==0.1.2 msgpack==1.0.8 msgspec==0.19.0 multidict==6.7.0 nh3==0.2.22 numpy==1.26.4 odfpy==1.4.1 openpyxl==3.1.5 ordered-set==4.1.0 outcome==1.3.0.post0 packaging==25.0 pandas==2.0.3 paramiko==4.0.0 parsedatetime==2.6 pgsanity==0.3.0 pillow==12.0.0 platformdirs==4.5.0 ply==3.11 polyline==2.0.3 prison==0.2.1 prompt_toolkit==3.0.52 propcache==0.4.1 psycopg2-binary==2.9.11 pyarrow==14.0.2 pyasn1==0.6.1 pyasn1_modules==0.4.2 pycparser==2.23 Pygments==2.19.2 PyJWT==2.10.1 PyMySQL==1.1.2 PyNaCl==1.6.0 pyOpenSSL==25.1.0 pyparsing==3.2.5 PySocks==1.7.1 python-dateutil==2.9.0.post0 python-dotenv==1.1.1 python-geohash==0.8.5 python-graphql-client==0.4.3 pytz==2025.2 pyxlsb==1.0.10 PyYAML==6.0.3 redis==4.6.0 referencing==0.37.0 requests==2.32.5 requests-cache==1.2.1 rich==13.9.4 rpds-py==0.28.0 rsa==4.9.1 selenium==4.37.0 shillelagh==1.4.2 shortid==0.1.2 simplejson==3.20.2 six==1.17.0 slack_sdk==3.37.0 sniffio==1.3.1 sortedcontainers==2.4.0 SQLAlchemy==1.4.54 SQLAlchemy-Utils==0.38.3 sqlglot==26.33.0 sqlparse==0.5.3 sshtunnel==0.4.0 tabulate==0.8.10 tomli==2.3.0 trio==0.31.0 trio-websocket==0.12.2 typing_extensions==4.15.0 tzdata==2025.2 url-normalize==2.2.1 urllib3==2.5.0 vine==5.1.0 wcwidth==0.2.14 websocket-client==1.9.0 websockets==15.0.1 Werkzeug==3.1.3 wrapt==1.17.3 wsproto==1.2.0 WTForms==3.2.1 WTForms-JSON==0.3.5 xlrd==2.0.2 XlsxWriter==3.0.9 yarl==1.22.0 zipp==3.23.0 (venv) gapinyc@DESKTOP-9QS7RL5:~/superset$
最新发布
10-26
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值