icpc 2019 沈阳区域赛

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
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值