[Programming questions] Chat A and B are friends, they often chat in idle time, A's idle time for [A1, B1],[a2, B2]. [AP, BP]. The idle time for B is [C1 +t,d1 +t]. [CQ +T,DQ +t], here T is the waking time of B. These times include the boundary points. B's waking time is [l,r] a moment. If a wake up time can make two people at any time chat, then this time is appropriate, ask how many of the right time to get up?
Input Description:
The first row of data is four integers: p,q,l,r (1≤p,q≤50,0≤l≤r≤1000). Next p row data each row has a pair of integers ai,bi (0≤ai<bi≤1000) represents the schedule of a, and the next P line is a pair of integers per line Ci,di (0≤ci,di≤1000) represents the schedule of B. Guaranteed a
I+1>bi,ci+1>di
Output Description:
Output answer number
Input Example:
2 3 0 20
15 17
23 26
1 4
7 11
15 17
Output Example:
20
#include <iostream>#include<vector>#include<utility>using namespacestd;BOOLIsoverlap (vector<vector<int>>&a, vector<vector<int>>&b,intt) { for(intI=0; I<b.size (); i++) { for(intj=0; J<a.size (); j + +) { if((a[j][0]<=b[i][0]+t) && (b[i][0]+t<=a[j][1])) return true; if((b[i][0]+t<=a[j][0]) && (a[j][0]<=b[i][1]+t))return true; } } return false;}intMain () {intP,q,l,r; while(cin>>p>>q>>l>>r) {vector<vector<int>> A (p,vector<int> (2,0)); for(intI=0; i<p;i++) { intx, y; CIN>>x>>y; a[i][0]=x; a[i][1]=y; } Vector<vector<int>> B (q,vector<int> (2,0)); for(intI=0; i<q;i++) { intx, y; CIN>>x>>y; b[i][0]=x; b[i][1]=y; } intCnt=0; for(intt=l;t<=r;t++) { if(Isoverlap (a,b,t)) CNT++; } cout<<cnt<<Endl; }}
[Programming problem-mushroom Street] Chat