http://www.codeforces.com/contest/79/problem/B
#include<iostream><br />using namespace std;<br />__int64 pos[1010];<br />#include<algorithm><br />int main()<br />{<br />//freopen("a.txt","r",stdin);<br />int n,m,k,t;<br />while(scanf("%d%d%d%d",&n,&m,&k,&t)!=EOF)<br />{<br />int i,j;<br />int a,b;<br />for(i=0;i<k;i++)<br />{<br />scanf("%d%d",&a,&b);<br />pos[i]=(a-1)*m+b;<br />}<br />sort(pos,pos+k);<br />while(t--)<br />{<br />scanf("%d%d",&a,&b);<br />int ans=lower_bound(pos,pos+k,(a-1)*m+b)-pos;//返回地址!<br />if(pos[ans]==(a-1)*m+b)<br />{<br />printf("Waste/n");<br />continue;<br />}<br />ans=(a-1)*m+b-ans;<br />ans=ans%3;<br />if(ans==0)<br />{<br />printf("Grapes/n");<br />continue;<br />}<br />if(ans==1)<br />{<br />printf("Carrots/n");<br />continue;<br />}<br />if(ans==2)<br />{<br />printf("Kiwis/n");<br />continue;<br />}<br />}<br />}<br />return 0;<br />}<br />