[Programming problem-mushroom Street] Chat

Source: Internet
Author: User

[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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.