最後更新於 2021 年 8 月 24 日
題目原文:https://onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=2493
題目概要:輸出從當前位置到指定位置的方向。
這題看範例輸入輸出大概就能解題,並不一定要看懂題目。
像我個人理解為題目要求的是輸出當前位置到指定位置的方向(象限)。
假設今天有3筆位置資料(K),當前位置在[2,1] (N,M),這三筆位置資料分別為[10,10][-10,1][0,33] (X,Y):那麼
[2,1] 到 [10,10] 很明顯X與Y都是增加的,因此往東北方向移動,因此輸出”NE“
[2,1] 到 [-10,1] X減少但Y不動,可得知只是在X軸上移動(East-West) ,因此輸出”divisa“
[2,1] 到 [0,33] X減少但Y增加,代表往西北方向移動,因此輸出“NO”
輸入
第一行,變數K 代表要查詢的數量
第二行,N 與 M 兩個整數代表當前的座標
接下來每 K 行代表住所座標的 X與Y
當 K 輸入為0時程式結束
輸出
• 如果居住地位於邊界線之一,則為”divisa“一詞(在葡萄牙語中為邊界)(North-South 或 East-West)
• “NO”代表西北(Northwestern Nlogonia)
• “NE”代表東北(Northeastern Nlogonia)
• “SE”代表東南(Southeastern Nlogonia)
• “SO”代表西南(Southwestern Nlogonia)
Sample Input
3
2 1
10 10
-10 1
0 33
4
-1000 -1000
-1000 -1000
0 0
-2000 -10000
-999 -1001
0
Sample Output
NE
divisa
NO
divisa
NE
SO
SE
程式碼
import java.util.*; public class main{ public static void main(String[] args) { try{ Scanner sc=new Scanner(System.in); int K; while((K = sc.nextInt())!=0){ int N = sc.nextInt(); int M = sc.nextInt(); for(int i=0;i<K;i++){ int X = sc.nextInt(); int Y = sc.nextInt(); if(X>N && Y>M){ System.out.println("NE"); }else if(X==N || Y==M){ System.out.println("divisa"); }else if(X<N && Y>M){ System.out.println("NO"); }else if(X>N && Y<M){ System.out.println("SE"); }else if(X<N && Y<M){ System.out.println("SO"); } } } }catch(Exception e){ System.out.println("Input error!"); } } };
- 解決 preact-router 資源請求路徑錯誤的問題 - 2022 年 6 月 24 日
- [楓之谷私服] 潮流轉蛋機 NPC 腳本優化 - 2022 年 6 月 19 日
- [楓之谷私服] 簡單的飛天椅子(坐騎)改法 v120 - 2022 年 6 月 19 日