A:看样例过题;
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <vector>
using namespace std;
typedef long long LL;
typedef pair<LL, LL> pii;
const int MAXN = 1e5 + 10;
vector<pii> G[MAXN];
int a[10];
int main() {
for(int i = 1; i <= 6; ++i) {
scanf("%d", &a[i]);
}
int ans = -1e9;
printf("%d\n", min(a[1], a[5]) + min(a[2], a[6]) + min(a[3], a[4]));
return 0;
}
C:把原式化成只含有x或y的一元函数,然后求取对称轴,暴力在此点附近的x或y且满足ax+by=c;
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <queue>
#include <cstring>
#include <vector>
#define double long double
using namespace std;
typedef long long LL;
typedef pair<int, double> pii;
const int MAXN = 1e3 + 10;
const LL INF = (1ll << 60);
LL a, b, c, p1, p2, q1, q2;
int main() {
scanf("%lld %lld %lld", &a, &b, &c);
scanf("%lld %lld %lld %lld", &p1, &p2, &q1, &q2);
LL ans = INF, res, len = 2e5;
double aa = (double)(p2 * b * b) / (double)(a * a) + (double)q2;
double bb = (double)q1 - (double)(p2 * b * c * 2 - b * p1 * a)/ (double)(a * a);
LL mid = (long long)(0 - bb / (aa * 2.0));
for(LL i = mid - len; i <= mid + len; ++i) {
if((c - b * i) % a) continue;
LL x = (c - b * i) / a, y = i;
res = p2 * x * x + p1 * x + q2 * y * y + q1 * y;
ans = min(res, ans);
}
if(ans != INF) printf("%lld\n", ans);
else puts("Kuon");
return 0;
}
E:sort排序;
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <vector>
using namespace std;
typedef long long LL;
typedef pair<LL, LL> pii;
const int MAXN = 1e6 + 10;
int a[MAXN];
int main() {
int n, m;
scanf("%d %d", &n, &m);
for(int i = 1; i <= n; ++i) {
scanf("%d", &a[i]);
}
sort(a + 1, a + n + 1);
int ans = a[1], cnt = 1;
for(int i = 2; i <= n; ++i) {
if(ans + m >= a[i]) {
ans = a[i];
} else {
cnt++;
ans = a[i];
}
}
printf("%d\n", cnt);
return 0;
}
J:正常的括号匹配去写(有种类限制),记录匹配的位置,用并查集维护区间。
由于会有()()这种区间,并查集维护时让左端点全部减一,就实现区间和并了。
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ull;
typedef pair<LL, LL>pii;
const int MAXN = 2e6 + 10;
const LL MOD = 1e9 +7;
stack<pii> s;
LL pre[MAXN];
LL find(LL x) {
if(pre[x] == -1) return x;
return pre[x] = find(pre[x]);
}
int main() {
memset(pre, -1, sizeof(pre));
LL n, m, q, L, R, k;
scanf("%lld %lld %lld", &n, &m, &q);
for(LL i = 1; i <= n; ++i) {
scanf("%lld", &k);
if(k % 2 == 0) s.push(pii(k, i));
else {
if(s.empty()) s.push(pii(k, i));
else if(k == s.top().first + 1) {
pii u = s.top();
s.pop();
pre[i] = u.second - 1;
// printf("$$ %lld %lld\n", i, pre[i]);
} else s.push(pii(k, i));
}
}
while(q--) {
scanf("%lld %lld", &L, &R);
LL x = find(L - 1), y = find(R);
// printf("## %lld %lld\n", x, y);
if(x == y) puts("Yes");
else puts("No");
}
return 0;
}
L:建图跑最短路;
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <queue>
#include <cstring>
#include <vector>
#define double long double
using namespace std;
typedef long long LL;
typedef pair<int, double> pii;
const int MAXN = 1e3 + 10;
vector<pii> G[MAXN];
double x[MAXN], y[MAXN], r[MAXN];
double dis[MAXN][MAXN];
int n;
inline double spfa(int x) {
double dis[MAXN];
for(int i = 0; i < MAXN; ++i) dis[i] = 99999999.0;
queue<int> q;dis[x] = 0.0;
q.push(x);
while(!q.empty()) {
int ant = q.front();
q.pop();
for(int i = 0; i < G[ant].size(); ++i) {
pii ans = G[ant][i];
double res = dis[ant] + ans.second;
if(res < dis[ans.first]) {
dis[ans.first] = res;
q.push(ans.first);
}
}
}
return dis[n + 2];
}
double so(double x) {
double L = 0.0, R = 99999.999;
while(R - L >= 0.000000000001) {
double mid = (L + R) / 2.0;
if(mid * mid >= x) R = mid;
else L = mid;
}
return L;
}
int main() {
double A, B, c1, c2;
scanf("%d %Lf %Lf %Lf %Lf", &n, &A, &B, &c1, &c2);
double ans = fabs(c1 - c2) / so(A * A + B * B);
// printf("%.8Lf\n", ans);
G[1].push_back(pii(n + 1, ans)); G[n + 2].push_back(pii(1, ans));
for(int i = 2; i <= n + 1; ++i) {
scanf("%Lf %Lf %Lf", &x[i], &y[i], &r[i]);
double res1 = fabs((A * x[i] + B * y[i] + c1) / so(A * A + B * B)) - r[i];
double res2 = fabs((A * x[i] + B * y[i] + c2) / so(A * A + B * B)) - r[i];
res1 = max((double)0.0, res1);
res2 = max((double)0.0, res2);
G[1].push_back(pii(i, res1));G[i].push_back(pii(n + 2, res2));
}
for(int i = 2; i <= n + 1; ++i) {
for(int j = 2; j <= n + 1; ++j) {
if(i == j) continue;
double res = so((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]));
res = res - r[i] - r[j];
res = max((double)0.00, res);
G[i].push_back(pii(j, res));
}
}
// for(int i = 1; i <= 4; ++i) {
// for(int j = i + 1; j <= 4; ++j) {
// printf("%.6lf\n", dis[i][j]);
// }
// }
printf("%.8Lf\n", spfa(1));
return 0;
}