• Codeforces Round #381 (Div. 2) 复习倍增//


    刷了这套题  感触良多  

    我想 感觉上的差一点就是差很多吧 。

    每次都差一点  就是差很多了。。。

    不能气馁。。要更加努力去填补那一点点。  老天不是在造物弄人,而是希望你用更好的自己去迎接自己。

    A. Alyona and copybooks

    有n本书  还需要买k本使得(n+k)%4==0 

    有三种  一本 a元  两本 b元  三本 c元的 不能分开卖

    问至少花多少

    枚举一下即可  。。。 我居然一开始搞了个dp记录买1-4本的最优策略....还wa了....

    #include <stdio.h>
    #include <iostream>
    #include <algorithm>
    //#include <>
    #include <vector>
    using namespace std;
    typedef long long ll;
    const int N = 2e5+10;
    ll v[10];
    int main()
    {
        int n;
        cin>>n;
        for(int i=1;i<=3;i++)
            cin>>v[i];
        ll ans = LONG_LONG_MAX;
        for(int i=0;i<=4;i++)
            for(int j=0;j<=4;j++)
                for(int k=0;k<=4;k++)
                {
                    if((n+i+j*2+k*3)%4==0)
                    {
                        ans = min(ans,i*v[1]+j*v[2]+k*v[3]);
                    }
                }
        cout<<ans<<endl;
        return 0;
    }
    AC代码

    B. Alyona and flowers

    给你m个区间  问选任意的区间使得和最大  

    发现区间和为负不要选就好

    #include <stdio.h>
    #include <iostream>
    #include <algorithm>
    //#include <>
    #include <vector>
    using namespace std;
    typedef long long ll;
    const int N = 2e5+10;
    ll v[110];
    int main()
    {
        int n,k;
        cin>>n>>k;
        for(int i=1;i<=n;i++)
        {    cin>>v[i];
            v[i]+=v[i-1];
        }
        ll ans = 0;
        while(k--)
        {
            int x;int y;
            cin>>x>>y;
            ll val = v[y] - v[x-1];
            if(val>0) ans+=val;
        }
        cout<<ans<<endl;
        return 0;
    }
    AC代码

    C. Alyona and mex

    给你长度为n的序列和m个区间,为区间中没出现过的最小的非负整数最大是多少。

    那么区间最短的那个决定ans

    接下来我们按照 

    [0,ans-1]这样循环填充n个位置。这样的话在任意的区间内都有[0,ans-1]

    这个很机智啊。。。。

    #include <stdio.h>
    #include <iostream>
    #include <algorithm>
    //#include <>
    #include <vector>
    using namespace std;
    typedef long long ll;
    
    int main()
    {
        int n,k;
        cin>>n>>k;
        int ans = INT_MAX;
        for(int i=0;i<k;i++)
        {
            int x;int y;
            cin>>x>>y;
            if((y-x)<ans)
            {
                ans = y-x; 
            }
        }
        ans++;
        cout<<ans<<endl;
        for(int i=0;i<n;i++)
        {
            printf("%d ",i%ans);
        }
        return 0;
    }
    AC代码

    D.倍增LCA 

    想一想  MK一下

  • 相关阅读:
    perl next和last
    用 Flask 来写个轻博客 (26) — 使用 Flask-Celery-Helper 实现异步任务
    mysql 更新唯一主键列 被堵塞
    perl + 匹配前导模式一次或者多次
    跨域
    日志处理
    FineBI:一个简单易用的自助BI工具
    FineBI:一个简单易用的自助BI工具
    bootstrap-treeview
    Bootstrap树形菜单插件TreeView.js使用方法详解
  • 原文地址:https://www.cnblogs.com/Geek-xiyang/p/6188137.html
Copyright © 2020-2023  润新知