• Day4下午


    不会啊。

    T1

    找规律: 辗转相减,加速。

    #include<iostream>
    #include<cstring>
    #include<cstdio>
    #include<algorithm>
    #include<queue>
    #include<cmath>
    using namespace std;
    long long a,b,c,ans=2;
    int main()
    {
        freopen("seq.in","r",stdin);
        freopen("seq.out","w",stdout);
        scanf("%lld%lld",&a,&b);
        if(abs(a-b)==1)
        {
            cout<<(a+1);
            return 0;
        }
        if(a<b)
        {
            c=a;
            a=b;
            b=c;
        }
    
        while(a&&b)
        {
            if(b<a-b)
                b=a-b;
            c=a-b;
            if(c<b)
            {a=b;b=c;}
            else
            if(c>b)
            {a=c;}
            else
            if(b==c)
            {a=c;ans--;}
            ans++;    
            if(b==1)
            {
                cout<<ans+a-1<<endl;
                return 0;
            }
        }
        cout<<ans<<endl;
        return 0;
    }
    first
    #include<iostream>
    #include<cstring>
    #include<cstdio>
    #include<algorithm>
    #include<queue>
    #include<cmath>
    using namespace std;
    long long a,b,c,ans;
    int main()
    {
        freopen("seq.in","r",stdin);
        freopen("seq.out","w",stdout);
        scanf("%lld%lld",&a,&b);
        if(a<b)
        {
            c=a;
            a=b;
            b=c;
        }
        c=a%b;
        while(c)
        {
            ans+=a/b;        
            a=b;b=c;c=a%b;
        }
        ans+=a/b;
        ans++;
        cout<<ans<<endl;
        return 0;
    }
    除法加速

    T2

    好写的一种方法,直接建一棵最大生成树。

    #include<iostream>
    #include<cstring>
    #include<cstdio>
    #include<algorithm>
    #include<queue>
    #include<cmath>
    #include<ctime>
    using namespace std;
    const int N=100009;
    struct node{
        int x,y,z;
    }a[N*2];
    int f[N],size[N],last[N];
    int n,m;
    long long ans[N];
    bool cmp(node v,node u)
    {    return v.z>u.z;}
    int find(int x)
    {
        while(x!=f[x])
            x=f[x]=f[f[x]];
        return x;
    }
    int main()
    {
        freopen("car.in","r",stdin);
        freopen("car.out","w",stdout);
        scanf("%d%d",&n,&m);
        for(int i=1;i<=m;i++)    
        scanf("%d%d%d",&a[i].x,&a[i].y,&a[i].z);
        
        sort(a+1,a+1+m,cmp);
        for(int i=1;i<=n;i++)
            f[i]=i,size[i]=1,last[i]=1;
        int f1,f2,i=2;
        f1=find(a[1].x);f2=find(a[1].y);
        if(f1!=f2)
                    f[f1]=f2,size[f2]+=size[f1];
        while(i<=m+1)
        {
            while(a[i].z==a[i-1].z)
            {
                f1=find(a[i].x);
                f2=find(a[i].y);
                if(f1!=f2)
                    f[f1]=f2,size[f2]+=size[f1];
                i++;
            }
            for(int j=1;j<=n;j++)
            {
                ans[j]+=(1LL*size[find(j)]-1LL*last[j])*(1LL*size[find(j)]-1LL*last[j]);
                last[j]=size[f[j]];
            }
            f1=find(a[i].x);f2=find(a[i].y);
            if(f1!=f2)
                    f[f1]=f2,size[f2]+=size[f1];
            i++;                
        }
        for(int i=1;i<=n;i++)
        printf("%lld ",ans[i]);
        cout<<'
    '<<clock();
        return 0;
    }
    first 30

    我自己测得50%的数据试过的,跑的贼快。不知道哪错了。

    反正我的做法是O(nm)的不是正解。

    正解是见一棵最大生成树, 

    T3

    部分分dp

    很难noi思维难度

  • 相关阅读:
    mysql运行报The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one time zone的解决方法
    【SpringBoot】服务器端主动推送SSE技术讲解
    【SpringBoot】SpringBoot2.0响应式编程
    【SpringBoot】息队列介绍和SpringBoot2.x整合RockketMQ、ActiveMQ
    第二部分初始阶段 第四章 初始不是需求阶段
    第一部分绪论 第三章 案例研究
    第一部分绪论 第二章 迭代,进化和敏捷
    第一部分绪论 第一章
    java集合(4)-Set集合
    java集合(3)-Java8新增的Stream操作集合
  • 原文地址:https://www.cnblogs.com/CLGYPYJ/p/7762629.html
Copyright © 2020-2023  润新知