ICPC World Finals 2018 (ABHIFK)

 这一年的题明显的特点是没有很难的算法,全部都是模拟题或者码量题(至少前6题是),很考察代码能力,有点像PTA的感觉,但有很多细节,一不小心就会wa或者t,和国内区域赛不太一样,这就非常考察团队对于机时的把握了。

A - Catch the Plane

题意:

你要从0号点坐公交到1号点,给你m个公交车的起始点、终点、出发时间、到达时间、发车概率,问你选择最优策略时,到达1号点的概率是多少。

分析:

首先在做策略的时候肯定要考虑坐完公交之后的概率,所以考虑从后往前进行dp。

在dp的时候每个点到达的时间不同,可以到达1号点的概率也不同,很明显有一个单调性,就是越早到达一个点,从这个点到达终点的概率越大,所以我们的dp的状态f_i,代表在某个时间点到达i之后可以到达1号点的最终概率。非常关键的一点就是每个f_i的概率都是关于时间递减的,这样就可以通过二分进行快速的查找dp状态。

代码:

#include<bits/stdc++.h>
using namespace std;
#define K(x...){cerr<<"BEGIN     "<<#x<<"->";Err(x);cerr<<"   END"<<endl;}
void Err(){}
template<class T, class... A>void Err(T a, A... x){cerr<<a<<','; Err(x...); }
template<class X,class Y,class...A>void Err(pair<X,Y> a,A... x){cerr<<'('<<a.first<<','<<a.second<<')';Err(x...);}
template<template<class...> class T, class t,class...A>void Err(T<t>a,A...x){cerr<<a.size()<<":{ ";for(auto v:a)Err(v),cerr<<",";cerr<<" }";Err(x...); }
typedef long long ll;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll rnd(ll l,ll r){return uniform_int_distribution<ll>(l,r)(rng);}
template<class T>void Min(T &a,const T b){if(a>b)a=b;}
template<class T>void Max(T &a,const T b){if(a<b)a=b;}
#define fi first
#define se second
#define lo (o<<1)
#define ro (o<<1|1)
#define mid ((l+r)/2)
#define endl '\n'
#ifdef ONLINE_JUDGE
#define freopen(a,b,c)
#define K(a...)
#endif
typedef pair<int,int>pii;
typedef vector<int>vi;
const int inf=0x3f3f3f3f;
const ll linf=0x3f3f3f3f3f3f3f3f;
const int N=3e5+10,M=500;
const ll mod=1e9+7;

struct A{
    int a,b;
    ll c,d;
    double e;
};
int main() {
    ios::sync_with_stdio(0),cin.tie(0);
    freopen("A.in","r",stdin);
    int n,m;ll k;cin>>m>>n>>k;
    vector<A>ar(m);
    for(auto &i:ar)cin>>i.a>>i.b>>i.c>>i.d>>i.e;
    sort(ar.begin(),ar.end(),[](A a,A b){return a.c>b.c;});
    vector<vector<pair<ll,double>>>f(n);
    f[1].push_back({k+1,1});
    for(int i=0;i<n;i++)if(i!=1)f[i].push_back({k+1,0});
    for(auto i:ar)if(!f[i.b].empty()){
        auto it=--lower_bound(f[i.b].begin(),f[i.b].end(),(pair<ll,double>){i.d,2},greater<pair<ll,double>>());
        double p=it->se*i.e;
        it=--lower_bound(f[i.a].begin(),f[i.a].end(),(pair<ll,double>){i.c,2},greater<pair<ll,double>>());
        p+=it->se*(1-i.e);
        if(p>f[i.a].back().se)f[i.a].push_back({i.c,p});
    }
    cout<<fixed<<setprecision(10)<<f[0].back().se;
}

B - Comma Sprinkler 

题意

给你若干句子,每个句子里有些单词间有逗号,让你做无限次这种操作,如果一个词前/后面有逗号,所有非开头/结尾的这个词前/后面都加上逗号,最后输出结果句子。

分析

签到题之一,把每个词拆成两个节点,代表这个词前面或后面有逗号,然后如果两个词直接没有句号,就互相连边,最后跑一个搜索就可以了,dfs或者bfs都可以。

代码

#include<bits/stdc++.h>
using namespace std;
#define K(x...){cerr<<"BEGIN     "<<#x<<"->";Err(x);cerr<<"   END"<<endl;}
void Err(){}
template<class T, class... A>void Err(T a, A..
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值