• CSP认证201812


    201812-1

    #include<bits/stdc++.h>
    using namespace std;
    #define inf 0x3f3f3f3f
    #define ll long long
    const int N=200005;
    const int mod=1e9+7;
    const double eps=1e-8;
    const double PI = acos(-1.0);
    #define lowbit(x) (x&(-x))
    ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
    ll qpow(ll a,ll b){ll res=1;while(b){if(b&1) res=res*a%mod;a=a*a%mod;b>>=1;}return res;}
    ll inv(ll a,ll p){return qpow(a,p-2);}
    int main()
    {
        std::ios::sync_with_stdio(false);
       // freopen("in.txt","r",stdin);
        ll r,y,g;
        cin>>r>>y>>g;
        int n;
        cin>>n;
        ll ans=0;
        for(int i=1;i<=n;i++)
        {
            ll o,x;
            cin>>o>>x;
            if(o==1)
            {
                ans+=x;
            }
            else if(o==2)
            {
                ans+=x+r;
            }
            else if(o==0)
            {
                ans+=x;
            }
        }
        cout<<ans<<endl;
        return 0;
    }
    

    201812-2

    #include<bits/stdc++.h>
    using namespace std;
    #define inf 0x3f3f3f3f
    #define ll long long
    const int N=200005;
    const int mod=1e9+7;
    const double eps=1e-8;
    const double PI = acos(-1.0);
    #define lowbit(x) (x&(-x))
    int main()
    {
        std::ios::sync_with_stdio(false);
    //    freopen("in.txt","r",stdin);
        ll r,y,g,tot;
        cin>>r>>y>>g;
        tot=r+y+g;
        int n;
        cin>>n;
        ll ans=0;
        for(int i=1; i<=n; i++)
        {
            ll o,x;//红绿黄
            cin>>o>>x;
            if(o==0)
            {
                ans+=x;
            }
            else if(o==1)//红
            {
                if(ans>=x)//换灯
                {
                    ll t=ans-x;
                    t%=tot;
                    if(t<g)
                    {
                        continue;
                    }
                    else if(t<g+y)
                    {
                        ans+=(r+(g+y-t));
                    }
                    else if(t<g+y+r)
                    {
                        ans+=((g+y+r)-t);
                    }
                }
                else
                {
                    ans+=(x-ans);
                }
            }
            else if(o==2)//黄
            {
                if(ans>=x)//换灯
                {
                    ll t=ans-x;
                    t%=tot;
                    if(t<r)//红
                    {
                        ans+=(r-t);
                    }
                    else if(t<r+g)//绿
                    {
                        continue;
                    }
                    else if(t<g+y+r)//黄
                    {
                        ans+=((g+y+r)-t+r);
                    }
                }
                else
                {
                    ans+=x-ans+r;
                }
            }
            else if(o==3)
            {
                if(ans>=x)//换灯
                {
                    ll t=ans-x;
                    t%=tot;
                    if(t<y)//黄
                    {
                        ans+=(y-t+r);
                    }
                    else if(t<y+r)//红
                    {
                        ans+=(y+r-t);
                    }
                    else if(t<g+y+r)//绿
                    {
                        continue;
                    }
                }
                else
                {
                    continue;
                }
            }
        }
        cout<<ans<<endl;
        return 0;
    }
    

      

    201812-4

    #include<bits/stdc++.h>
    using namespace std;
    #define inf 0x3f3f3f3f
    #define ll long long
    const int maxn=5e5+5;
    const int maxm=5e5+5;
    const int mod=1e9+7;
    const double eps=1e-8;
    const double PI = acos(-1.0);
    #define lowbit(x) (x&(-x))
    struct edge
    {
        ll u,v,w;
    } eg[maxm];
    ll tot=0,pre[maxn],n,m,r;
    void addedge(ll u,ll v,ll w)
    {
        eg[tot].u=u;
        eg[tot].v=v;
        eg[tot++].w=w;
    }
    bool cmp(edge a,edge b)
    {
        return a.w<b.w;
    }
    ll find(ll x)
    {
        if(pre[x]==x)  return x;
        else return pre[x]=find(pre[x]);
    }
    ll kruskal(ll n)
    {
        sort(eg,eg+tot,cmp);
        ll cnt=0,ans=0,mx=0;
        for(ll i=0; i<tot; i++)
        {
            ll u=eg[i].u,v=eg[i].v,w=eg[i].w;
            ll fu=find(u),fv=find(v);
            if(fu!=fv)
            {
                ans+=w;
                pre[fu]=fv;
                mx=max(mx,w);
                cnt++;
            }
            if(cnt==n-1)    break;
        }
        if(cnt<n-1) return -1;
        else return mx;
    }
    void init()
    {
        tot=0;
        for(ll i=1; i<=n; i++)
            pre[i]=i;
    }
    int main()
    {
        std::ios::sync_with_stdio(false);
        while(cin>>n>>m>>r)
        {
            init();
            for(int i=0; i<m; i++)
            {
                ll a,b,c;
                cin>>a>>b>>c;
                addedge(a,b,c);
                addedge(b,a,c);
            }
            cout<<kruskal(n)<<endl;
        }
        return 0;
    }
    

      

  • 相关阅读:
    Educational Codeforces Round 10 C. Foe Pairs 水题
    Educational Codeforces Round 10 B. z-sort 构造
    CDOJ 1048 Bob's vector 三分
    Educational Codeforces Round 10 A. Gabriel and Caterpillar 模拟
    第14届电子科大初赛民间盗版部分题目题解
    HDU 5654 xiaoxin and his watermelon candy 离线树状数组 区间不同数的个数
    HDU 5653 Bomber Man wants to bomb an Array. dp
    HDU 5652 India and China Origins 二分+并查集
    HDU 5651 xiaoxin juju needs help 数学
    HDU 5650 so easy 数学
  • 原文地址:https://www.cnblogs.com/mcq1999/p/11923453.html
Copyright © 2020-2023  润新知