救救喵咪

鏈接: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();
    }
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章