A
贪心,由于基地可以重复销毁,所以找出找出每架战机可轰炸基地的最大价值,排序之后贪心找一下即可
#include<iostream> #include<algorithm> using namespace std; const int N = 1e6 + 15; struct node{ int d, v; }no[N]; bool cmp(node a, node b){ if(a.d == b.d) return a.v < b.v; else return a.d < b.d; } int a[N]; int main() { int n, m; cin >> n >> m; for(int i = 0; i < n; i++) cin >> a[i]; for(int i = 0; i < m; i++) cin >> no[i].d; for(int i = 0; i < m; i++) cin >> no[i].v; sort(a, a + n); sort(no, no + m, cmp); int ans = 0, p = 0; int maxd = 0; for(int i = 0; i < n; i++){ while(p < m && a[i] > no[p].d){ maxd = max(maxd, no[p].v); p++; } ans += maxd; } cout << ans << endl; return 0; }
E
对比两个人答案的不同,如果不同答案大于k,则判定不同的k道题都是对的,num - k道是错的;如果不同答案小于k,则判定不同的都是对的,k - num道是错的
#include <iostream> using namespace std; const int N = 1005 + 15; int a[N], b[N]; int main() { int n, k; cin >> n >> k; for(int i = 0; i < n; i++) cin >> a[i]; int num = 0; for(int i = 0; i < n; i++){ int x; cin >> x; if(x != a[i]) num++; } cout << n - (max(num, k) - min(num, k)) << endl; return 0; }
G
只能出现前导0,所以有 n + 1种方案
举个例子即可n = 5
1 1 1 1 1
0 1 1 1 1
0 0 1 1 1
0 0 0 1 1
0 0 0 0 1
0 0 0 0 0
#include <iostream> using namespace std; int main() { int n; cin >> n; cout << n + 1<< endl; return 0; }
H
两圆相交,注意:相切也算相交,同时注意double的精度问题
#include<iostream> using namespace std; #define ll long long int main() { int t; cin >> t; while(t--) { ll x, y, r; ll x1, y1, r1; cin >> x >> y >> r >> x1 >> y1 >> r1; ll dis = (y1 - y) * (y1 - y) + (x1 - x) * (x1 - x); ll rr = (r + r1) * (r + r1); ll rrr = ((max(r, r1) - min(r, r1))) * ((max(r, r1) - min(r, r1))); if (rrr <= dis && dis <= rr) cout << "YES" << endl; else cout << "NO"<< endl; } return 0; }