zoukankan      html  css  js  c++  java
  • Codeforces Round #188 (Div. 2) 解题报告 //缺E

    ----------------------------

    A. Even Odds

    将1到n中的奇数排到前面偶数排到后面,问第k个数是多少。

    ----

    嗯。。。math

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    using namespace std;
    
    typedef long long LL;
    
    LL n,d,k,m;
    
    int main()
    {
        cin>>n>>k;
        m=(n+1)/2;
        if (k<=m) d=k*2-1;
        else d=(k-m)*2;
        cout<<d<<endl;
        return 0;
    }
    ----------------------------

    B. Strings of Power

    给一个字符串,求以"heavy"为开头以"metal"为结尾的字串数。

    ----

    从前往后扫描,记录heavy的数目,对于每个metal,答案数+heavy。

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    #include <string>
    
    using namespace std;
    typedef long long LL;
    const int maxn=111111;
    string s;
    LL ans;
    char tc[2][10]={"heavy","metal"};
    int main()
    {
        LL hy=0;
        cin>>s;
        ans=0;
        int len=s.length();
        for (int i=0;i<len;i++)
        {
            if (s.substr(i,5)==tc[0]) hy++;
            if (s.substr(i,5)==tc[1]) ans+=hy;
        }
        cout<<ans<<endl;
        return 0;
    }
    ----------------------------

    C. Perfect Pair

    给一个数对(a,b),可以将其中一个数加到另一个上,问最少多少次变换后其中最大的数能大于等于m。

     ----

    对于两个正数(a,b),满足斐波那契数列的性质变换次数最小。

    对于一正一负,将正数不停加到负数上,直到得到两个正数。

    对于两个负数,若一开始不能大于等于m,则永远不可能大于等于m,答案为0或-1。

    #include <iostream>
    #include <cstring>
    #include <cstdio>
    #include <algorithm>
    
    using namespace std;
    
    typedef long long LL;
    LL a,b,m;
    LL ans;
    int main()
    {
        cin>>a>>b>>m;
        if (a>b) swap(a,b);
        if (b>=m) ans=0;
        else if (b<=0) ans=-1;
        else
        {
            ans=0;
            if (a<0)
            {
                if ((-a)%b==0) ans=-a/b;
                else ans=-a/b+1;
                a+=ans*b;
            }
            while (b<m)
            {
                a=a+b;
                if (a>b) swap(a,b);
                ans++;
            }
        }
        cout<<ans<<endl;
        return 0;
    }
    ----------------------------

    D. Ants

    一开始在(0,0)处有n个蚂蚁,对于一群蚂蚁a,a/4分别向上下左右移动,不足4时不移动。

    问移动结束后,(x,y)处有多少只蚂蚁。

    ----------------------------

    直接广搜求解即可。

    由于0 ≤ n ≤ 30000所以当x或y大于 sqrt(sqrt(n)) 时候不会有蚂蚁存在。

    #include <iostream>
    #include <queue>
    #include <cstdio>
    #include <cstring>
    #include <cstdlib>
    using namespace std;
    
    const int maxn=1111;
    const int direct[4][2]={ {0,1},{1,0},{0,-1},{-1,0} };
    struct POINT{
        int x;
        int y;
        POINT(int a,int b):x(a),y(b){}
    };
    int map[maxn][maxn];
    int vis[maxn][maxn];
    queue<POINT>que;
    int num,T;
    int main()
    {
        memset(map,0,sizeof(map));
        memset(vis,0,sizeof(vis));
        while (!que.empty()) que.pop();
        cin>>num>>T;
        map[500][500]=num;
        que.push(POINT(500,500));
        vis[500][500]=true;
        while (!que.empty())
        {
            POINT p=que.front();
            int v=map[p.x][p.y]/4;
            que.pop();
            vis[p.x][p.y]=false;
            for (int i=0;i<4;i++)
            {
                int x=p.x+direct[i][0];
                int y=p.y+direct[i][1];
                map[x][y]+=v;
                if (!vis[x][y]&&map[x][y]>3)
                {
                    que.push(POINT(x,y));
                    vis[x][y]=true;
                }
            }
            map[p.x][p.y]%=4;
        }
        while (T--)
        {
            int x,y;
            cin>>x>>y;
            x=abs(x);
            y=abs(y);
            if (x>500||y>500) cout<<0<<endl;
            else cout<<map[500+x][500+y]<<endl;
        }
        return 0;
    }
    


    ----------------------------

  • 相关阅读:
    bzoj 3779 重组病毒——LCT维护子树信息
    bzoj 4010 [HNOI2015]菜肴制作——贪心
    bzoj 2535 && bzoj 2109 [Noi2010]Plane 航空管制——贪心
    bzoj 3671 [Noi2014]随机数生成器——贪心(时间复杂度分配)
    bzoj 2395 [Balkan 2011]Timeismoney——最小乘积生成树
    bzoj 3157 && bzoj 3516 国王奇遇记——推式子
    bzoj 1101 [POI2007]Zap——反演
    hdu 4372 Count the Buildings——第一类斯特林数
    bzoj 2406 矩阵——有源汇上下界可行流
    bzoj 2039 [2009国家集训队]employ人员雇佣——二元关系
  • 原文地址:https://www.cnblogs.com/cyendra/p/3226282.html
Copyright © 2011-2022 走看看