牛客多校第三场题解

D - Link with Game Glitch

题目大意

题目大意

思路

思路

代码

#include<bits/stdc++.h>

using namespace std;
const int N = 1e4+7;
int n,m;
int a[N],b[N],c[N],d[N];
int h[N],e[N],ne[N],idx,st[N],cnt[N];
long double w[N],dist[N];
const double eps = 1e-8;

void add(int a, int b,long double c){
    e[idx]=b,ne[idx]=h[a],w[idx]=c,h[a]=idx++;
}

bool check(long double k){
    idx = 0;
    for(int i= 1;i<=n;i++){
        h[i]=-1;
        cnt[i]=0;
        st[i]=0;
        dist[i]=0;
    }
    for(int i=1;i<=m;i++){
        add(b[i],d[i],log(a[i])-log(c[i]*k));
    }
    queue<int> q;
    for(int i=1;i<=n;i++){
        q.push(i);
        st[i]=1;
    }
    while(q.size()){
        int t=q.front();
        q.pop();
        st[t]=0;
        for(int i=h[t]; i!=-1; i=ne[i]){
            int j=e[i];
            if(dist[j]>dist[t]+w[i]+eps){
                cnt[j]=cnt[t]+1;
                dist[j]=dist[t]+w[i];
                if(!st[j]){
                    q.push(j);
                    st[j]=1;
                }
            }
            if(cnt[j]>=n) return true;
        }
    }
    return false;
}

signed main(){
    scanf("%d %d",&n,&m);
    for(int i=1;i<=m;i++){
        scanf("%d %d %d %d", &a[i],&b[i],&c[i],&d[i]);
    }
    long double l=0,r=2000;
    int time=100;
    while(time--){
        double mid=(l+r)/2;
        if(check(mid)) r=mid;
        else l=mid;
    }
    printf("%.10lf\n", (double)l);
}

H - Take the Elevator

题目大意

题目大意

思路

思路

代码

#include <bits/stdc++.h>
struct O { int O = 0; } O;
using namespace std;
using namespace rel_ops;
using ll = long long;
using ld = long double;
template<typename T>
using pr_q_rev = priority_queue<T, vector<T>, greater<T>>;
using Pair = pair<ll, ll>;

ll gettime(const ll& m, multiset<Pair, greater<Pair>>& people) {
  if (people.empty()) return 0;
  ll ret = people.begin()->first;
  if (people.size() <= m) {
    people.clear();
    return ret;
  }
  priority_queue<ll> q;
  while (q.size() < m) {
    q.push(people.begin()->second);
    people.erase(people.begin());
  }
  while (1) {
    ll qt = q.top();
    q.pop();
    auto it = people.lower_bound({qt, LLONG_MAX});
    if (it == people.end()) break;
    q.push(it->second);
    people.erase(it);
  }
  return ret;
}

void solve(const int& T) {
  ll n, m, k, ans = 0;
  cin >> n >> m >> k;
  multiset<Pair, greater<Pair>> up, down;
  for (ll i = n; i > 0; i--) {
    ll s, t;
    cin >> s >> t;
    if (s < t) up.insert({t, s});
    else down.insert({s, t});
  }
  while (!(up.empty() && down.empty())) ans += max(gettime(m, up), gettime(m, down)) - 1;
  cout << ans * 2 << '\n';
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
  int t = 1;
  // cin >> t;
  for (int i = 1; i <= t; i++) solve(i);
  return O.O;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值