Contest1803 - 2019年第二阶段我要变强个人训练赛第十八场(补题场)

 

 

#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
const ll maxm=55000;
const ll maxn=300;
const ll inf=0x3f3f3f3f;
ll n,m,d[maxn],u[maxm],d2[maxn],v[maxm],w[maxm],d1[maxn];
 
struct Dijkstra
{
    struct Edge
    {
        ll next,  to,w;
    } e[maxm];
    ll head[maxn],v[maxn],tol;
    void add(ll u, ll v, ll w)
    {
        tol++;
        e[tol].to = v;
        e[tol].next = head[u];
        e[tol].w = w;
        head[u] = tol;
    }
 
    priority_queue<pair<long long,ll>,vector<pair<long long,ll> >,greater<pair<long long,ll> > >q1;
    void dijkstra(ll s)
    {
        memset(d,inf,sizeof(d));
        memset(v,0,sizeof(v));
        d[s] = 0;
        q1.push(make_pair(0, s));
        while (!q1.empty())
        {
            ll x = q1.top().second;
            q1.pop();
            if (!v[x])
            {
                v[x] = 1;
                for (register ll i = head[x]; i; i = e[i].next)
                {
                    ll to=e[i].to;
                    if (d[to] > d[x] + e[i].w)
                    {
                        d[to] = d[x] + e[i].w;
                        q1.push(make_pair(d[to], to));
                    }
                }
            }
        }
    }
 
    void init()
    {
        memset(head, 0, sizeof(head));
        tol = 0;
    }
} D;
int main()
{
    scanf("%lld%lld",&n,&m);
    for (ll i=1; i<=m; i++)
    {
        scanf("%lld%lld%lld",&u[i],&v[i],&w[i]);
        D.add(u[i],v[i],w[i]);
        D.add(v[i],u[i],w[i]);
    }
    D.dijkstra(1);
    for (ll i=1; i<=n; i++)
    {
        d1[i]=d[i];
    }
    D.dijkstra(n);
    for (ll i=1; i<=n; i++)
    {
        d2[i]=d[i];
    }
    ll ans=0;
    for (ll i=1; i<=m; i++)
    {
        if (d1[u[i]]+w[i]+d2[v[i]]==d1[n]||d1[v[i]]+w[i]+d2[u[i]]==d1[n])
        {
            w[i]=w[i]*2;
            D.init();
            for (ll j=1; j<=m; j++)
            {
                D.add(u[j],v[j],w[j]);
                D.add(v[j],u[j],w[j]);
            }
            D.dijkstra(1);
            ans=max(ans,d[n]-d1[n]);
            w[i]=w[i]/2;
        }
    }
    printf("%lld\n",ans);
}

#include<bits/stdc++.h>
using namespace std;
vector<pair<int,int> >ans;
int n,a[101000],len[1000000];
int main()
{
    scanf("%d",&n);
    for (int i=1;i<=n;i++){
        scanf("%d",&a[i]);
    }
    for (int i=1;i<=n;i++){
        len[a[i]]++;
        if (a[i+1]<a[i]){
            for (int j=a[i];j>a[i+1];j--){
                ans.push_back(make_pair(i-len[j]+1,i));
                len[j-1]+=len[j];
                len[j]=0;
            }
        }
    }
 
    printf("%d\n",ans.size());
    for (int i=0;i<ans.size();i++){
        printf("%d %d\n",ans[i].first,ans[i].second);
    }
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,m,p;
 
struct node
{
    ll a[2][2];
    node operator*(const node &b) const
    {
        node res;
        for (int i = 0; i < 2; i++)
        {
            for (int j = 0; j < 2; j++)
            {
                res.a[i][j] = 0;
                for (int k = 0; k < 2; k++)
                {
                    res.a[i][j] = (res.a[i][j] + a[i][k] * b.a[k][j]%p) % p;
                }
            }
        }
        return res;
    }
};
 
node pow(node b,ll c)
{
    node res;
    res.a[0][0] = 1;
    res.a[1][0] = 0;
    res.a[0][1] = 0;
    res.a[1][1] = 1;
    while (c)
    {
        if (c & 1)
        {
            res = res * b;
        }
        c >>= 1;
        b = b * b;
    }
    return res;
}
 
int main()
{
    node f,f1;
    f.a[0][0] = 1;
    f.a[1][0] = 1;
    f.a[0][1] = 1;
    f.a[1][1] = 0;
    f1.a[0][0] = 3;
    f1.a[0][1] = 1;
    f1.a[1][0] = 0;
    f1.a[1][1] = 0;
    scanf("%lld%lld", &n,&p);
    if  (p==1)
    {
        printf("0\n");
        return 0;
    }
    if (n==0){
        printf("1\n");
        return 0;
    }
    ll ans = (f1*pow(f, n-2)).a[0][0];
    if (n%2==0){
        ans=(ans-1+p)%p;
    }
    printf("%lld\n",ans);
}

 

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1000010;
ll n,a,b,sum[N],c,l[N],r[N],ans=-99999999999999999;
int main(){
    scanf("%lld%lld%lld",&n,&a,&b);
    for (int i=1;i<=n;i++){
        scanf("%lld",&c);
        sum[i]=sum[i-1]+c;
        l[i]=max(l[i-1],sum[i]);
    }
    r[n]=sum[n];
    for (int i=n-1;i>=0;i--){
        r[i]=min(r[i+1],sum[i]);
    }
    for (int i=0;i<=n;i++){
        ans=max(ans,min((1+b)*r[i]-(a+1)*sum[i]-b*sum[n],b*(1+a)*sum[i]-a*(b+1)*l[i]-b*sum[n]));
    }
    cout<<ans<<endl;
}

 

posted @ 2019-07-30 17:20  Snow_in_winer  阅读(161)  评论(0编辑  收藏  举报