1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
| #include<iostream> #include<algorithm> #include<iomanip> #include<cmath> #include<cstring> using namespace std; int main(){ int l,subnum,subhead,subtail,treelocate,treeflag[10001],treenonflag=0;
cin>>l>>subnum; for(treelocate=0;treelocate<=l;treelocate++){ treeflag[treelocate]=0; } for(int i=1;i<=subnum;i++){ cin>>subhead>>subtail; for(treelocate=subhead;treelocate<=subtail;treelocate++){ if(treeflag[treelocate]==0){ treeflag[treelocate]=1; } } } for(treelocate=0;treelocate<=l;treelocate++){ if(treeflag[treelocate]==0){ treenonflag+=1; } } cout<<treenonflag<<endl; return 0; }
|