zoukankan      html  css  js  c++  java
  • Codeforces_794

    A.统计两个guard之间的钞票数。

    #include<bits/stdc++.h>
    #define MOD 1000000009
    using namespace std;
    
    int a,b,c,n;
    
    int main()
    {
        ios::sync_with_stdio(false);
        cin >> a >> b >> c >> n;
        int ans = 0;
        while(n--)
        {
            int x;
            cin >> x;
            if(b < x && x < c)  ans++;
        }
        cout << ans << endl;
        return 0;
    }
    View Code

    B.面积x倍,边长sqrt(x)倍。

    #include<bits/stdc++.h>
    #define MOD 1000000009
    using namespace std;
    
    int n,h;
    
    int main()
    {
        ios::sync_with_stdio(false);
        cin >> n >> h;
        for(int i = 1;i < n;i++)
        {
            cout << fixed << setprecision(10) << h*sqrt(1.0*i/n) << " ";
        }
        cout << endl;
        return 0;
    }
    View Code

    C.首先可以得知,选取s1中最小的(n+1)/2个,s2中最大的n/2个,整个过程有以下两步骤。

    1.当s1中最小的比s2中最小的要小是,显然,s1每次选最小的放在串首,s2每次选最小的放在串首。

    2.否则,s1每次选最大的放在串尾,s2每次选最大的放在串尾。

    #include<bits/stdc++.h>
    using namespace std;
    
    string s1,s2;
    
    int main()
    {
        ios::sync_with_stdio(false);
        cin >> s1;
        sort(s1.begin(),s1.end());
        cin >> s2;
        sort(s2.begin(),s2.end());
        reverse(s2.begin(),s2.end());
        int n = (s1.length()+1)/2,m = s1.length()/2;
        int now1 = 0,now2 = 0;
        char ans[300005] = {0};
        int num = 0,l = 0,r = s1.length()-1;
        while(num < s1.length() && s1[now1] < s2[now2])
        {
            if(num%2 == 0)  ans[l++] = s1[now1++];
            else    ans[l++] = s2[now2++];
            num++;
        }
        now1 = n-1,now2 = m-1;
        while(num < s1.length())
        {
            if(num%2 == 0)  ans[r--] = s1[now1--];
            else    ans[r--] = s2[now2--];
            num++;
        }
        cout << ans << endl;
        return 0;
    }
    View Code

    D.用hash缩点,之后的图每个点最多只能有两条边,dfs。

    #include<bits/stdc++.h>
    using namespace std;
    
    int n,m;
    int hashh[300005],pre[300005],ans[300005] = {0},vis[300005] = {0},visc[600005] = {0};
    vector <int> v[300005];
    
    void dfs(int now)
    {
        vis[now] = true;
        if(ans[now] == 0)   return;
        for(int i = 0;i < v[now].size();i++)
        {
            int t = v[now][i];
            if(hashh[t] == hashh[now])  ans[t] = ans[now];
        }
        for(int i = 0;i < v[now].size();i++)
        {
            int t = v[now][i];
            if(vis[t])    continue;
            if(!ans[t])
            {
                if(!visc[ans[now]-1])
                {
                    visc[ans[now]-1] = 1;
                    ans[t] = ans[now]-1;
                }
                else if(!visc[ans[now]+1])
                {
                    visc[ans[now]+1] = 1;
                    ans[t] = ans[now]+1;
                }
            }
            dfs(t);
        }
    }
    
    int main()
    {
        ios::sync_with_stdio(0);
        cin >> n >> m;
        pre[0] = 0;
        for(int i = 1;i <= n;i++)   pre[i] = pre[i-1]*31+i;
        for(int i = 1;i <= n;i++)   hashh[i] = pre[i];
        for(int i = 1;i <= m;i++)
        {
            int x,y;
            cin >> x >> y;
            v[x].push_back(y);
            v[y].push_back(x);
            hashh[x] += pre[y];
            hashh[y] += pre[x];
        }
        ans[1] = 300000;
        visc[300000] = 1;
        dfs(1);
        for(int i=1;i<=n;i++)
        {
            if(!ans[i])
            {
                cout << "NO" << endl;
                return 0;
            }
        }
        cout << "YES" << endl;
        for(int i = 1;i <= n;i++)   cout << ans[i] << " ";
        cout << endl;
        return 0;
    }
    View Code

  • 相关阅读:
    三种常见的编码:ASCII码、UTF-8编码、Unicode编码等字符占领的字节数
    快学Scala习题解答—第十章 特质
    [LeedCode OJ]#63 Unique Paths II
    收集互联网博客
    Android 内存监测工具 DDMS --> Heap(转)
    (转载)测试工具monkey
    (转载)Git使用教程
    时间戳转换为时间字符串
    二维码相关知识点
    教你跳转到系统指定页面
  • 原文地址:https://www.cnblogs.com/zhurb/p/6851478.html
Copyright © 2011-2022 走看看