beebe_3 发表于 2015-11-26 07:33:31

Chef -- Divide the Tangerine

  给你k对数,让你判断后面的p对数是否全在前面k对数中。
  对于给的 l和r ,看成在 l 一刀 和 在r+1 一刀,先把k对间隔都存下来。再去二分查找即可。
  #include<stdio.h>
#include<algorithm>
using namespace std;
const int N=502;
int a;
int main(){
int tt,n,k,p,l,r;
scanf(&quot;%d&quot;,&tt);
while(tt--){
scanf(&quot;%d%d%d&quot;,&n,&k,&p);
int cnt=0;
for(int i=0;i<k;i++){
scanf(&quot;%d %d&quot;,&l,&r);
a=l;
a=(r+1)%n;
}
sort(a,a+cnt);
int nn=unique(a,a+cnt)-a;
int goal=1;
for(int i=0;i<p;i++){
scanf(&quot;%d %d&quot;,&l,&r);
if(goal){
int loc=lower_bound(a,a+nn,l)-a;
if(a!=l) goal=0;
loc=lower_bound(a,a+nn,(r+1)%n)-a;
if(a!=(r+1)%n) goal=0;
}
}
printf(&quot;%s\n&quot;,goal?&quot;Yes&quot;:&quot;No&quot;);
}
}
页: [1]
查看完整版本: Chef -- Divide the Tangerine