PAT-乙-1082 1082 射擊比賽 (20 分)
程式碼
#include <stdio.h> #include <math.h> int main() { double min = 10000; double max = -1; int N; scanf("%d", &N); int minId; int maxId; for(int i=0; i<N; i++) { int id; double x, y; scanf("%d %lf %lf", &id, &x, &y); double dis = sqrt(x*x+y*y); if(dis>max){ maxId = id; max = dis; } if(dis<min){ minId = id; min = dis; } } printf("%04d %04d\n", minId, maxId); return 0; }
註解
這種不需儲存,就能找到最大最小值的方法,是很常用的。
結果
相關推薦
PAT-乙-1082 1082 射擊比賽 (20 分)
程式碼 #include <stdio.h> #include <math.h> int main() { double min = 10000; double max = -1; int N; scanf("%d",
PAT乙級 1082 射擊比賽 (20 分)
本題目給出的射擊比賽的規則非常簡單,誰打的彈洞距離靶心最近,誰就是冠軍;誰差得最遠,誰就是菜鳥。本題給出一系列彈洞的平面座標(x,y),請你編寫程式找出冠軍和菜鳥。我們假設靶心在原點(0,0)。 輸入格式: 輸入在第一行中給出一個正整數 N(≤ 10 000)。隨後 N 行,每行按下
PAT乙級:1082 射擊比賽(20 分)
本題目給出的射擊比賽的規則非常簡單,誰打的彈洞距離靶心最近,誰就是冠軍;誰差得最遠,誰就是菜鳥。本題給出一系列彈洞的平面座標(x,y),請你編寫程式找出冠軍和菜鳥。我們假設靶心在原點(0,0)。 輸入格式: 輸入在第一行中給出一個正整數 N(≤ 10 000)。隨後 N
1082 射擊比賽 (20 分)
1082 射擊比賽 (20 分) 本題目給出的射擊比賽的規則非常簡單,誰打的彈洞距離靶心最近,誰就是冠軍;誰差得最遠,誰就是菜鳥。本題給出一系列彈洞的平面座標(x,y),請你編寫程式找出冠軍和菜鳥。我們假設靶心在原點(0,0)。 輸入格式: 輸入在第一行中給出一個正整數
【PAT】B1082 射擊比賽(20 分)
r+ 射擊 spa sca code ace algorithm ret pat 水提水題,直接貼代碼啦 #include<cstdio> #include<algorithm> using namespace std; struct ppp{
PAT-B1082 射擊比賽(20 分)
1082 射擊比賽(20 分) 本題目給出的射擊比賽的規則非常簡單,誰打的彈洞距離靶心最近,誰就是冠軍;誰差得最遠,誰就是菜鳥。本題給出一系列彈洞的平面座標(x,y),請你編寫程式找出冠軍和菜鳥。我們假設靶心在原點(0,0)。 輸入格式: 輸入在第一行中給出一個正整數
PAT-乙-1072 1072 開學寄語 (20 分)
程式碼 #include <iostream> using namespace std; int main() { int N, M; scanf("%d %d", &N, &M); int a[10000] = {0}; for(i
PAT-乙-1067 1067 試密碼 (20 分)
程式碼 #include <iostream> using namespace std; int main() { string s; int n; cin>>s>>n; string t; getline(cin, t);
PAT-乙-1064 1064 朋友數 (20 分)
程式碼 #include <iostream> #include <vector> #include <set> #include <algorithm> using namespace std; int main() { i
PAT-乙-1062 1062 最簡分數 (20 分)
程式碼 #include <iostream> #include <algorithm> using namespace std; int maxCommon(int a, int b) { if(a>b) { swap(a, b); }
PAT-乙-1034 1034 有理數四則運算 (20 分)
程式碼 #include <iostream> #include <math.h> #include <stdio.h> using namespace std; struct fenshu { long long int fenzi; l
PAT-乙-1047 1047 程式設計團體賽 (20 分)
程式碼 #include <iostream> #include <map> using namespace std; int main() { int n; scanf("%d", &n); map<in
PAT-乙-1088 1088 三人行 (20 分)
程式碼 #include <stdio.h> #include <math.h> int me, x, y; int print(double t){ if(me==t){ printf(" Ping"); } else
PAT-乙-1084 1084 外觀數列 (20 分)
程式碼 #include <iostream> using namespace std; int main() { string d; int N; cin>>d>>N; while(--N){ st
PAT-乙-1009 1009 說反話 (20 分)
程式碼(c++版本) #include <iostream> #include <string.h> #include <vector> using namespace std; int main(){ vector&
【PAT】B1042 字符統計(20 分)
lower int har string.h flag char s algorithm printf for /* 15分的題很簡單,但是自己寫的時候在輸入數據時沒有考慮好下標 另外有忘記了輸入字符時考慮是否有\n */ #include<stdio
PAT-乙-1070 1070 結繩 (25 分)
程式碼 #include <iostream> #include <algorithm> using namespace std; int main() { int n; cin>>n; double a[n]; for(in
PAT-乙-1066 1066 影象過濾 (15 分)
程式碼 #include <stdio.h> int main() { int n, m; int a, b, c; scanf("%d %d %d %d %d", &n, &m, &a, &b, &c); int
PAT-乙-1065 1065 單身狗 (25 分)
程式碼 #include <iostream> #include <vector> #include <algorithm> using namespace std; const int MAX = 100000; int main() {
PAT-乙-1061 1061 判斷題 (15 分)
程式碼 #include <stdio.h> int main() { int n, m; scanf("%d %d", &n, &m); int score[m] = {0}; int ans[m] = {0}; for(int