#include<iostream> #include<cstdlib> #include<algorithm> #include<cmath> #include<string> #include<map> #include<stack> #include<cstdio> #include<cstring> #define ll long long #define ull unsigned long long usingnamespace std; constint N = 1e8 + 10; boolcmp(int a, int b) { return a > b; } int a[N]; string s; intmain() { int x; getline(cin, s); int n = 0; int num = 0; for (int i = 0; i < s.length(); i++) { if (s[i] == ' ') { a[n++] = num; num = 0; } else { num = num * 10 + s[i] - '0'; } } int o, r; cin >> o >> r; bool f = false; sort(a, a + n, cmp); for (int i = 0; i < n; i++) { if (abs(a[i] - o) <= r) { f = true; cout << a[i] << ' '; } } if (!f) cout << endl; return0; }
F题
1 2 3 4 5 6 7 8 9 10 11 12 13
In the sample input, we have Chasm at (3,5), Jueyun Karst at (6,0), and Keqing can finish the visiting within radius 1.
So Keqing could go directly topoint (3,4) first to visit Chasm, then reach (5.4,0.8) to visit Jueyun Chasm. The total length is5+4=9. We can prove that there isnopathwith a smaller distance.
Sample Input 1 351 结尾无空行 Sample Output Case #1: 9.00 结尾无空行 Acknowledgment ICT Products & Solutions of HUAWEI.
#include<iostream> #include<cstdlib> #include<algorithm> #include<cmath> #include<string> #include<map> #include<stack> #include<cstdio> #include<cstring> #define ll long long #define ull unsigned long long usingnamespace std; intmain() { int t; int flag = 1;
scanf("%d", &t);
while (t--) { ll a, b, r;
cin >> a >> b >> r;
if (r > b) { printf("Case #%d: %.2f", flag++, 2.0 * a - r); } else { printf("Case #%d: %.2f", flag++, 2.0 * sqrt(a * a + (b - r) * (b - r)) - r); } if (t) puts(""); }