zoukankan      html  css  js  c++  java
  • Codeforces_849

    A.只要考虑分成一个串的情况就可以了。

    #include<bits/stdc++.h>
    using namespace std;
    
    int n,a[105];
    
    int main()
    {
        ios::sync_with_stdio(0);
        cin >> n;
        for(int i = 1;i <= n;i++)   cin >> a[i];
        if(a[1]%2 && a[n]%2 && n%2)    cout << "Yes" << endl;
        else    cout << "No" << endl;
        return 0;
    }
    View Code

    B.1.若所有点在一条直线,则no。

    2.若a[1]单独一组,剩余点在一条直线,则yes。

    3.枚举a[1]和后面点组成的直线,判断是否能把点分成两组。

    #include<bits/stdc++.h>
    using namespace std;
    
    int n,a[1005];
    
    int main()
    {
        ios::sync_with_stdio(0);
        cin >> n;
        for(int i = 1;i <= n;i++)   cin >> a[i];
        int t = a[3]-a[2];
        int ok = 0;
        for(int i = 3;i <= n;i++)
        {
            if(a[i]-a[i-1] != t)    ok = 1;
        }
        if(!ok)
        {
            if(a[2]-a[1] == t)  cout << "No" << endl;
            else    cout << "Yes" << endl;
            return 0;
        }
        ok = 0;
        for(int i = 2;i <= n;i++)
        {
            double t = 1.0*(a[i]-a[1])/(i-1);
            vector<int> v;
            for(int j = 2;j <= n;j++)
            {
                if(abs(1.0*(a[j]-a[1])/(j-1)-t) > 1e-8) v.push_back(j);
            }
            int flag = 1;
            for(int j = 1;j < v.size();j++)
            {
                if(abs(1.0*(a[v[j]]-a[v[0]])/(v[j]-v[0])-t) > 1e-8)   flag = 0;
            }
            if(flag)    ok = 1;
        }
        if(ok)  cout << "Yes" << endl;
        else    cout << "No" << endl;
        return 0;
    }
    View Code

    C.首先,每个字母相互独立。对于每个字母,最优的方案是一个一个加,打个表,每次加个最大可行量。注意0的特殊情况。

    #include<bits/stdc++.h>
    using namespace std;
    
    int n,x[500];
    string ans = "z";
    
    int main()
    {
        ios::sync_with_stdio(0);
        x[1] = 0;
        for(int i = 2;i <= 440;i++) x[i] = x[i-1]+i-1;
        cin >> n;
        for(char c = 'a';c <= 'z';c++)
        {
            if(n == 0)  break;
            int t = 440;
            while(x[t] > n) t--;
            n -= x[t];
            while(t--)  ans.append(1,c);
        }
        cout << ans << endl;
        return 0;
    }
    View Code

    D.分成两组,按照g-t排序,这个顺序保证相遇顺序。

    之后双指针模拟,遇到连续的几个相同时,画个图便知道那个点从哪里出了。

    #include<bits/stdc++.h>
    using namespace std;
    
    int n,w,h,tx[100005],ty[100005],ansx[100005],ansy[100005];
    struct xx
    {
        int x,t,id;
        friend bool operator<(xx a,xx b)
        {
            if(a.x-a.t != b.x-b.t)  return a.x-a.t < b.x-b.t;
            return a.x < b.x;
        }
    }a[100005],b[100005];
    
    int main()
    {
        ios::sync_with_stdio(0);
        cin >> n >> w >> h;
        int cnt1 = 0,cnt2 = 0;
        for(int i = 1;i <= n;i++)
        {
            int x,y,t;
            cin >> x >> y >> t;
            if(x == 1)
            {
                a[++cnt1].x = y;
                a[cnt1].t = t;
                a[cnt1].id = i;
                tx[i] = y;
                ty[i] = h;
            }
            else
            {
                b[++cnt2].x = y;
                b[cnt2].t = t;
                b[cnt2].id = i;
                tx[i] = w;
                ty[i] = y;
            }
        }
        sort(a+1,a+1+cnt1);
        sort(b+1,b+1+cnt2);
        int now1 = 1,now2 = 1;
        while(now1 <= cnt1 && now2 <= cnt2)
        {
            if(a[now1].x-a[now1].t == b[now2].x-b[now2].t)
            {
                int t1 = now1+1,t2 = now2+1;
                while(t1 <= cnt1 && a[now1].x-a[now1].t == a[t1].x-a[t1].t) t1++;
                while(t2 <= cnt2 && b[now2].x-b[now2].t == b[t2].x-b[t2].t) t2++;
                vector<int> v1,v2;
                for(int i = now1;i < t1;i++)    v1.push_back(a[i].id);
                for(int i = t2-1;i >= now2;i--) v1.push_back(b[i].id);
                for(int i = t2-1;i >= now2;i--) v2.push_back(b[i].id);
                for(int i = now1;i < t1;i++)    v2.push_back(a[i].id);
                for(int i = 0;i < v1.size();i++)
                {
                    ansx[v2[i]] = tx[v1[i]];
                    ansy[v2[i]] = ty[v1[i]];
                }
                now1 = t1;
                now2 = t2;
            }
            else if(a[now1].x-a[now1].t < b[now2].x-b[now2].t)
            {
                ansx[a[now1].id] = tx[a[now1].id];
                ansy[a[now1].id] = ty[a[now1].id];
                now1++;
            }
            else
            {
                ansx[b[now2].id] = tx[b[now2].id];
                ansy[b[now2].id] = ty[b[now2].id];
                now2++;
            }
        }
        while(now1 <= cnt1)
        {
            ansx[a[now1].id] = tx[a[now1].id];
            ansy[a[now1].id] = ty[a[now1].id];
            now1++;
        }
        while(now2 <= cnt2)
        {
            ansx[b[now2].id] = tx[b[now2].id];
            ansy[b[now2].id] = ty[b[now2].id];
            now2++;
        }
        for(int i = 1;i <= n;i++)   cout << ansx[i] << " " << ansy[i] <<endl;
        return 0;
    }
    View Code

  • 相关阅读:
    FusionCharts ScrollColumn2D图
    Java Web项目部署Tomcat运行出错
    Eclipse部署Java Web项目到Tomcat出错
    JavaScript过滤特殊字符
    pl/sql 在一个程序块里打印日志输出到表格
    Java中过滤出字母、数字和中文的正则表达式
    pl/sql 程序块里打印问题
    C++函数的Boost内存池性能介绍
    boost内存池的使用介绍
    内存管理 Boost::singleton_pool
  • 原文地址:https://www.cnblogs.com/zhurb/p/7465604.html
Copyright © 2011-2022 走看看