救救喵咪

链接:https://ac.nowcoder.com/acm/contest/372/A
来源:牛客网

时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 262144K,其他语言524288K
64bit IO Format: %lld
题目描述
某天,一只可爱的肥橘喵在路上走,突然遇到了一个怪人,那怪人自称PM6,“小肥喵,这里有一道水题,答对了我就请你吃狗肉,答错了你就请我吃猫肉!”

喵咪瑟瑟发抖:“QAQ什么题?”

PM6道:“给你坐标轴上的N个点,求出对于每个点,有多少个点的 X 坐标和 Y 坐标都大于它。”

毫不意外,蠢肥喵完全不会这道题并面临着被做成猫肉火锅的危险,求求你救救喵咪!

输入描述:
输入包括两行,第一行是正整数n,表示点数,接下来N行每行两个数表示第i个点的横坐标和纵坐标,坐标值都是整数,输入数据中存在坐标相同的点。
对于50%的数据:0<=点的坐标大小<=10000,0<=N<=100
对于100%的数据:0<=点的坐标大小<=10000,0<=N<=1000
输出描述:
输出包括N行,第i行表示有多少个点在点i的右上方。
示例1
输入
复制
3
1 2
2 3
4 4
输出
复制
2
1
0

思路:事实告诉我们,一定要看清楚题,肠子都悔青了。真的是,右上方,我怎么会理解成。。。。唉

错误代码:


    import java.util.Scanner;
	public class Main {
    public static int[] vals= new int[100005];
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] num = new int[n];
        for(int i = 0;i < n;i++) {
            int x = sc.nextInt();
            int y = sc.nextInt();
            num[i] = x*x + y*y;
        }
        for(int i = 0;i < n;i++) {
            int ans = 0;
            for(int j = i+1;j < n;j++)
                if(num[i] < num[j])
                    ans++;
            System.out.println(ans);
        }
        sc.close();
    }
}

import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[][] num = new int[n][2];
        for (int i = 0; i < n; i++) {
            num[i][0] = sc.nextInt();
            num[i][1] = sc.nextInt();
        }
        for (int i = 0; i < n; i++) {
            int ans = 0;
            for (int j = 0; j < n; j++) {
                if (num[j][0] > num[i][0] && num[j][1] > num[i][1]) {
                    ans++;
                }
            }
            System.out.println(ans);
        }
        sc.close();
    }
}

猜你喜欢

转载自blog.csdn.net/weixin_42105744/article/details/87897997
今日推荐