CF - 44C - Holidays

来源:互联网 发布:淘宝网店铺搜索 编辑:程序博客网 时间:2024/05/14 19:57

题意: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;}


原创粉丝点击