#include <iostream> #include <map> #include <math.h> using namespace std; int main() { double a, b; cin >> a >> b; int n; cin >> n; double MIN = 1e10; while (n--) { double x, y, v; cin >> x >> y >> v; double tmp = sqrt((a - x) * (a - x) + (b - y) * (b - y)) / v; if (tmp < MIN) MIN = tmp; } printf("%.10lf\n",MIN); return 0; }
#include <iostream> #include <map> #include <math.h> #include <algorithm> #include <string> using namespace std; int x[100000]; int main() { int n, q; cin >> n; for (int i = 0; i < n; i++) cin >> x[i]; sort(x, x + n); cin >> q; while (q--) { int m; cin >> m; if (m < x[0]) { cout << 0 << endl; continue; } if (m >= x[n - 1]) { cout << n << endl; continue; } int l = 0, r = n - 1, mid; while (1) { mid = (l + r) >> 1; if (m < x[mid]) r = mid; else l = mid; if (l == r || l + 1 == r) break; } cout << l + 1 << endl; } //system("pause"); return 0; }
f[i][0]表示把前i个排好序且第i个不翻转的最小代价,f[i][1]表示把前i个排好序且第i个翻转的最小代价。
#include <iostream> #include <map> #include <math.h> #include <algorithm> #include <string> using namespace std; long long dp[110000][2]; bool cmp[110000][2][2]; long long c[110000]; string s[110000], r[110000]; int main() { int n; cin >> n; for (int i = 1; i <= n; i++) cin >> c[i]; for (int i = 1; i <= n; i++) { cin >> s[i]; r[i] = s[i]; reverse(r[i].begin(), r[i].end()); } for (int i = 2; i <= n; i++) { if (s[i - 1] <= s[i]) cmp[i][0][0] = true; else cmp[i][0][0] = false; if (r[i - 1] <= s[i]) cmp[i][0][1] = true; else cmp[i][0][1] = false; if (s[i - 1] <= r[i]) cmp[i][1][0] = true; else cmp[i][1][0] = false; if (r[i - 1] <= r[i]) cmp[i][1][1] = true; else cmp[i][1][1] = false; } dp[1][0] = 0; dp[1][1] = c[1]; for (int i = 2; i <= n; i++) { dp[i][0] = 1e15; if (cmp[i][0][0] && dp[i - 1][0] < dp[i][0]) dp[i][0] = dp[i - 1][0]; if (cmp[i][0][1] && dp[i - 1][1] < dp[i][0]) dp[i][0] = dp[i - 1][1]; dp[i][1] = 1e15; if (cmp[i][1][0] && dp[i - 1][0] + c[i] < dp[i][1]) dp[i][1] = dp[i - 1][0] + c[i]; if (cmp[i][1][1] && dp[i - 1][1] + c[i] < dp[i][1]) dp[i][1] = dp[i - 1][1] + c[i]; } long long ans; if (dp[n][0] < dp[n][1]) ans = dp[n][0]; else ans = dp[n][1]; if (ans == 1e15) cout << -1 << endl; else cout << ans << endl; //system("pause"); return 0; }
#include<bits/stdc++.h> #include<set> using namespace std; multiset<int> ms; int main() { int n; cin >> n; ms.clear(); ms.insert(0); while (n--) { char ch; int x; cin >> ch >> x; if (ch == ‘+‘) ms.insert(x); if (ch == ‘-‘) ms.erase(ms.find(x)); if (ch == ‘?‘) { int ans = 0; for (int i = 30; i >= 0; i--) { int tmp; if ((x & (1 << i)) == 0) { tmp = ans | (1 << i); auto it = ms.lower_bound(tmp); if (it == ms.end()) continue; if ((*it) - tmp >= (1 << i)) continue; if ((*it) & (1 << i)) ans |= (1 << i); } else { auto it = ms.lower_bound(ans); int debug = *it; if ((*it) & (1 << i)) ans |= (1 << i); } } cout << (ans ^ x) << endl; } } return 0; }
时间: 2024-10-12 14:32:25