【洛谷】P1003 铺地毯

#include
int n;
int a[100005],b[100005],g[100005],k[100005];
int x,y;
int OK;
int bh;
void input(){
    int j;
    scanf("%d",&n);
    for(j=1;j<=n;j++)
        scanf("%d %d %d %d",&a[j],&b[j],&g[j],&k[j]);
    scanf("%d %d",&x,&y);
}
void solve(){
    int i;
    for(i=n;i>=1;i--){
        if(x>=a[i]&&x<=(a[i]+g[i])&&y>=b[i]&&y<=(b[i]+k[i])){
            bh=i;
            OK=1;
            break;
        }
        else
            OK=0;
    }
}
void output(){
    if(OK)
        printf("%d",bh);
    else
        printf("-1");
}
int main(){
    input();
    solve();
    output();
    return 0;
}

你可能感兴趣的:(洛谷)