1 条题解

  • 0
    @ 2021-6-15 1:40:14

    C :

    #include<stdio.h>
    #include<string.h>
    #define N 10000
    int main()
    {
        int i,n,a[N][4],j,aa,bb,k,m,pos=0;
        scanf("%d",&n);
        for(i=0;i<n;i++){
            for(j=0;j<4;j++){
                scanf("%d",&a[i][j]);
            }
        }
        scanf("%d %d",&aa,&bb);
        for(k=0;k<n;k++){
            if(a[k][0]<=aa && a[k][1]<=bb && (a[k][2]+a[k][0])>=aa && (a[k][1]+a[k][3])>=bb)
                pos=k+1;
                //flag++;
        }
     //   printf("%d\n",flag);
        if(pos!=0) printf("%d\n",pos);
        else printf("-1\n");
        return 0;
    }
    
    

    C++ :

    #include <iostream>
    using namespace std;
    struct Carpet
    {
    	int a;
    	int b;
    	int g;
    	int k;
    };
    Carpet S[10000];
    int C=0;
    int Find(int n)
    {
    	for(int a,b,g,k;C<n;C++)
    	{
    		cin>>a>>b>>g>>k;
    		S[C].a=a;
    		S[C].b=b;
    		S[C].g=g;
    		S[C].k=k;
    	}
    	int x,y;
    	cin>>x>>y;
    	for(int i=C-1;i>=0;i--)
    	{
    		if(x>=S[i].a&&x<=(S[i].a+S[i].g)&&y>=S[i].b&&y<=(S[i].b+S[i].k))
    		{
    			cout<<i+1<<endl;
    			return 0;
    		}
    	}
    	cout<<"-1"<<endl;
    	return 0;
    }
    int main()
    {
    	int n;
    	while(cin>>n)
    	Find(n);
    	return 0;
    }
    

    Pascal :

    var n,m,i,x,y:longint;
    
        a,b,c,d:array[1..10000]of longint;
    
    begin
    
     readln(n);
    
     m:=-1;
    
     for i:=1 to n do 
    
      readln(a[i],b[i],c[i],d[i]);
    
     readln(x,y);
    
     for i:=1 to n do 
    
      if(x>=a[i])and(x<=a[i]+c[i]-1)and(y>=b[i])and(y<=b[i]+d[i]-1)then
    
       m:=i;
    
     writeln(m);
    
    end.
    
    
    • 1

    信息

    ID
    288
    时间
    1000ms
    内存
    128MiB
    难度
    (无)
    标签
    递交数
    0
    已通过
    0
    上传者