zoukankan      html  css  js  c++  java
  • 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思维难度

  • 相关阅读:
    shell脚本:Kill掉MySQL中所有sleep的client线程
    为什么事务要提交或者回滚?
    MySQL 性能优化
    解决:Reading table information for completion of table and column names
    mysql distinct 用法详解及优化
    MySQL Profiling 的使用
    手把手教你用Strace诊断问题[转]
    mysql,命令导入导出表结构或数据
    八种架构设计模式及其优缺点概述(下)
    mysql多实例配置下,用脚本启动mysql时,出现Please read "Security" section of the manual to find out how to run mysqld as root!
  • 原文地址:https://www.cnblogs.com/CLGYPYJ/p/7762629.html
Copyright © 2011-2022 走看看