2017年12月4日 星期一

ITSA 58 - [Problem 2] 道路修補 - 參考答案

Difficulty: Easy
Ref: ITSA 58 - [Problem 2] 道路修補
/*******************************************************/
/* [Problem 2] 道路修補                                 */
/* Author: awei0905  [at]  awei0905.blogspot.tw        */
/* Version: 2017/12/04                                 */
/*******************************************************/
#include <iostream> 

using namespace std;

int main() {
    int m;
    cin >> m;
    
    while(m--) {
        int n, s, e, length = 0, road[10001] = { 0 };
        
        cin >> n;
        
        while(n--) {
            cin >> s >> e;
            for(int i = s; i < e; i++)
                road[i] = 1;
        }
        
        for(int i = 0; i < 10001; i++)
            if(road[i])
                length++;
        
        cout << length << endl;
    }
    return 0;
}
Debug: I/O
需修補的路段進行標示,然後統計出答案。
2
3
6 13
3 5
10 14
7
2 4
0 2
7 9
5 6
1 3
8 10
7 10
10
8

沒有留言:

張貼留言