#35447: C++


11131039@stu.tshs.tp.edu.tw (二孝25林孟希)

學校 : 不指定學校
編號 : 201083
來源 : [125.228.248.38]
最後登入時間 :
2024-04-17 14:50:03
b966. 3. 線段覆蓋長度 -- 2016年3月apcs | From: [36.225.136.122] | 發表日期 : 2023-06-03 19:18

一次一次覆蓋掉

#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long n;
    cin>>n;
    long long a[1000000]={0};
    for(int i=0;i<n;i++)
    {
        int l,r;
        cin>>l>>r;
        for(int j=l;j<=l+(r-l-1);j++)
        {
            a[j]=1;
        }
    }
    int cnt=0;
    for(int i=0;i<1000000;i++)
    {
        if(a[i]==1)
        {
            cnt++;
        }
    }
    cout<<cnt;
}

 
ZeroJudge Forum