文章目录
icpc 2019 沈阳区域赛
A.Leftbest
题意: 签到水题
题解:
代码:
#include <set>
#include <iostream>
using namespace std;
int const N = 1e5 + 10;
typedef long long LL;
int a[N], n;
int main()
{
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
set<int> s;
cin >> n;
LL res = 0;
for (int i = 1; i <= n; ++i)
{
scanf("%d", &a[i]);
s.insert(a[i]);
if (i == 1) continue;
auto it = s.upper_bound(a[i]);
if (*it > a[i] && it != s.end()) res += *it;
}
cout << res << endl;
return 0;
}
B.First Date
题意: 给定m条边,每条边有个权值x+ay,x和y是给定的已知值,a是随机因子,每条边的随机因子相同。问从S点到T点的期望距离的最小值是多少?
题解: 之所以会有期望距离,就是因为a是随机的,因此才会有一个平均值–期望。要让期望值最小,那么就是要跑最短路。本题的数据较小,我们可以每次把a加上1e-4,然后把所有的dist[T]累加起来,最后除以10000即可。
代码:
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<double, int> PDI;
int const MAXN = 200, MAXM = 400 * 2;
int n, m, T, S, e[MAXM], ne[MAXM], idx, h[MAXN], st[MAXN];
double w[MAXM];
struct Edge {
int u, v, x, y;
}edge[MAXM];
double dis[MAXN];
void add(int a, int b, double c) {
e[idx] = b, w[idx] = c, ne[idx] = h[a], h[a] = idx++;
}
double dijkstra(double a) {
for (int i = 1; i <= n; ++i) dis[i] = 1e18 + 10, h[i] = -1, st[i] = 0;
idx = 0;
for (int i = 1; i <= m; ++i) {
int u = edge