NC216123. 小C的飞机跑道
描述
输入描述
共N+1行输入
第一行为两个整数
1<=L<=10000
1<=N<=100
以下n行为Q与P
Q<=P<=L
输出描述
输出一个整数 代表没有被清理的长度
示例1
输入:
1000 2 1 3 3 100
输出:
900
示例2
输入:
1000 5 1 9 10 12 16 18 100 333 369 500
输出:
619
说明:
1 9 10 12C++(g++ 7.5.0) 解法, 执行用时: 3ms, 内存消耗: 488K, 提交时间: 2023-01-08 13:35:21
#include <iostream> using namespace std; int main(){ int a,b,x[10001]={0},m,n,c=0; cin>>a>>b; for(int i=0;i<b;i++){ cin>>m>>n; for(int o=m;o<=n;o++){ if(x[o]==0){x[o]++;c++;} } } cout<<a-c; return 0; }
C++ 解法, 执行用时: 3ms, 内存消耗: 400K, 提交时间: 2021-05-18 20:33:06
#include<iostream> using namespace std; bool st[1000010]; int main() { int n,m,res=0; cin>>n>>m; while(m--) { int a,b; cin>>a>>b; for(int i=a;i<=b;i++) st[i]=true; } while(n--) if(!st[n+1])res++; cout<<res; return 0; }
C(clang11) 解法, 执行用时: 2ms, 内存消耗: 352K, 提交时间: 2020-12-27 14:22:25
#include<stdio.h> main() { int l,i,k,j,m=0; int a[10001]={0}; scanf("%d %d",&l,&k); while(k--) { scanf("%d %d",&i,&j); for(i;i<=j;i++) { a[i]=1; } } for(i=0;i<l;i++) if(a[i]==0)m++; printf("%d",m); }
Python3(3.9) 解法, 执行用时: 130ms, 内存消耗: 18480K, 提交时间: 2020-12-27 14:10:08
l,n=map(int,input().split()) s=[] ll=[] for i in range(n): s.append(list(map(int,input().split()))) for i in s: ll=ll+list(range(i[0],i[1]+1)) sss=list(set(ll)) print(l-len(sss))