Under my umbrella.

SKII

Less is more.

洛谷 P1003 铺地毯 (C/C++, JAVA)

洛谷 P1003 铺地毯

/*
  P1003 铺地毯
*/
#include <iostream>
#include <cstdio>
using namespace std;

int main() {
  int n; cin >> n;
  // map数组用来保存每张地毯的信息
  // 行:地毯编号; 列:a, b, g, k
  int** map = new int*[n];
  for(int i = 0; i < n; i++) map[i] = new int[4]();
  for(int i = 0; i < n; i++)
    for(int j = 0; j < 4; j++)
      scanf("%d", &map[i][j]);
  int x, y; cin >> x >> y;
  bool nothing = true;
  for(int i = n-1; i >= 0; i--) {
    if(x>=map[i][0] && y>=map[i][1] &&
      x<=map[i][0]+map[i][2] && y<=map[i][1]+map[i][3]) {
      cout << i+1 << endl; nothing = false;
      break;
    }
  }
  if(nothing) {
    cout << -1 << endl;
  }

  delete[] map;
  return 0;
}
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int[][] map = new int[n][4];
        for(int i = 0; i < n; i++)
            for(int j = 0; j < 4; j++)
                map[i][j] = scan.nextInt();
        int x = scan.nextInt(), y = scan.nextInt();
        boolean nothing = true;
        for(int i = n-1; i >= 0; i--) {
            if(x>=map[i][0] && y>=map[i][1] &&
               x<=map[i][0]+map[i][2] && y<=map[i][1]+map[i][3]) {
                System.out.println(i+1); nothing = false;
                break;
            }
        }
        if(nothing) System.out.println("-1");
    }
}
posted @ 2020-01-14 11:39  NLYang  阅读(642)  评论(0编辑  收藏  举报