• P1338 末日的传说,P1372 P1414 又是毕业季——贪心


    一个1到n序列,合理排序逆序对数要求是m,而且字典序要求最小;

    这个题,因为数字只能用一次,所以我们可以知道什么位置放什么数逆序对的个数会增加或减少多少;

    先求出最多能产生的数量,每次先输出最小的数,用总数减去减少的逆序对数;

    如果不够的时候就要用大数排在前面;

    vector,记得输出一个删一个;

    #include<cstdio>
    #include<vector>
    #include<cstring>
    #include<algorithm>
    using namespace std;
    typedef long long ll;
    ll n,m;
    ll now;
    vector<ll> v;
    int main()
    {
        scanf("%lld%lld",&n,&m);
        for(ll i=1;i<=n;i++) v.push_back(i);
        ll s=n*(n-1)/2;
        for(int i=n-1;i>=0;i--)
        {
            s-=i;
            if(m>s)
            {
                now=m-s;
                m=s;
            }
            else now=0;
            printf("%lld ",v[now]);
            v.erase(v.begin()+now);
        } 
        return 0;
    }

    又是毕业季我什么也不想说

    1到n这些数中,找到k个,使他们的GCD最大,输出GCD;

    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    using namespace std;
    int n,k;
    int main()
    {
        scanf("%d%d",&n,&k);
        printf("%d",n/k);
        return 0;
    }

    又是毕业季II

    这回数字不连续而且k的值是变的;

    把所有的数的公约数的数量记一下就好了

    #include<cstdio>
    #include<cstring>
    #include<cmath>
    #include<algorithm>
    using namespace std;
    const int maxn=1e6+10;
    int n,x;
    int c[maxn];
    int maxx;
    int main()
    {
        scanf("%d",&n);
        for(int i=1;i<=n;i++)
        {
            scanf("%d",&x);
            maxx=max(maxx,x);
            int m=sqrt(x);
            for(int j=1;j<=m;j++)
            {
                if(x%j==0)
                {
                    c[j]++;
                    if(x/j!=j) c[x/j]++;
                }
            }
        }
        x=maxx;
        for(int i=1;i<=n;i++)
        {
            while(c[x]<i) x--;
            printf("%d
    ",x);
        }
        return 0;
    }
  • 相关阅读:
    sqlmap的学习以及使用
    SQL查询关于相对路径、矢代、绝对路径、递归、计算列的速度对比跟优化-SOD群记录
    新版本打印控件插件
    vs2013 遇到的web性能记录器无法使用问题
    sql数据库 管理处理问题--维护计划
    nopcommerce 初学2
    控制饭庄
    递归问题==优化 还有数据库sqlreader
    Java基础 -3.2
    Java基础 -3
  • 原文地址:https://www.cnblogs.com/WHFF521/p/11544733.html
Copyright © 2020-2023  润新知