30求调

P1047 [NOIP2005 普及组] 校门外的树

bithldwdh @ 2024-08-01 07:46:49

代码:

#define _CRT_SECURE_NO_WARNINGS 1

#include <stdio.h>

int main()
{
    int l, m;
    int a[100][2] = { 0 };
    int i, j;
    int count = 0;
    int cnt[10000] = { 0 };
    scanf("%d %d", &l, &m);
    //遍历,赋值
    for (i = 0; i < m; i++) {
        scanf("%d %d", &a[i][0], &a[i][1]);
    }
    //改值,把挪走的树都变成1
    for (i = 0; i < m; i++) {
        for (j = a[i][0]; j <= a[i][1]; j++) {
            cnt[j] = 1;
        }
    }
    for (i = 0; i <= l; i++) {
        if (cnt[i] == 0) {
            count++;
        }
    }
    printf("%d", count);
    return 0;
}

by HFZ20111110 @ 2024-08-01 08:03:05

@bithldwdh 我还能说什么呢?无语了数组开小了。AC记录

#define _CRT_SECURE_NO_WARNINGS 1

#include <stdio.h>

int main()
{
    int l, m;
    int a[100][5] = { 0 };
    int i, j;
    int count = 0;
    int cnt[10005] = { 0 };
    scanf("%d %d", &l, &m);
    //遍历,赋值
    for (i = 0; i < m; i++) {
        scanf("%d %d", &a[i][0], &a[i][1]);
    }
    //改值,把挪走的树都变成1
    for (i = 0; i < m; i++) {
        for (j = a[i][0]; j <= a[i][1]; j++) {
            cnt[j] = 1;
        }
    }
    for (i = 0; i <= l; i++) {
        if (cnt[i] == 0) {
            count++;
        }
    }
    printf("%d", count);
    return 0;
}

可以给个关注吗?


by bithldwdh @ 2024-08-01 08:17:00

@HFZ20111110

okok万分感谢


by zhuowei @ 2024-08-01 09:02:25

改个万能头就过了(我也不知道为什么

#include<bits/stdc++.h>
int main()
{
    int l, m;
    int a[100][2] = { 0 };
    int i, j;
    int count = 0;
    int cnt[10000] = { 0 };
    scanf("%d %d", &l, &m);
    //遍历,赋值
    for (i = 0; i < m; i++) {
        scanf("%d %d", &a[i][0], &a[i][1]);
    }
    //改值,把挪走的树都变成1
    for (i = 0; i < m; i++) {
        for (j = a[i][0]; j <= a[i][1]; j++) {
            cnt[j] = 1;
        }
    }
    for (i = 0; i <= l; i++) {
        if (cnt[i] == 0) {
            count++;
        }
    }
    printf("%d", count);
    return 0;
}

by zhuowei @ 2024-08-01 09:02:37

@bithldwdh


|