Codeforces Round #602 (Div. 2)

A题:https://codeforces.com/contest/1262/problem/A

思路:这道题的话,是给你x轴上n个线段,每个线段都有区间,然后让你找一个段,这个段和每一个区间都相交,然后让你找最小的这个段,换句话说,就是找到a-b的最小值。
下面看一下代码吧。

#include 
const int maxx=0x3f3f3f3f;
using namespace std;
int main()
{
    int t,n,x,y;
    scanf("%d",&t);
    while(t--)
    {
        int l=0,r=maxx;
        scanf("%d",&n);
        for(int i=1;i<=n;i++)
        {
            scanf("%d%d",&x,&y);
            if(ly)
                r=y;
        }
        if(l<=r)
            printf("0\n");
        else
            printf("%d\n",l-r);
    }
    return 0;
}

B题:https://codeforces.com/contest/1262/problem/B

思路:这道题的话,就是先给你一个排列p,从1-n(不重复),然后再给你一个前缀q,q1=p1,q2=max(p1,p2),q3=max(p1,p2,p3),按照这个规律,现在给你一些前缀数,并问你存不存在这样一个排列
下面看一下代码吧。用贪心的思想,是最大值放最大值,不是最大值,放最小值。

#include 
using namespace std;
vectorq;
void solve()
{
    int n;
    scanf("%d",&n);
    q.clear();
    vectorans;
    setp;
    int x;
    for(int i=0; imaxx)
        {
            if(p.count(q[i]))
            {
                p.erase(q[i]);
                ans.push_back(q[i]);
            }
            else
            {
                printf("-1\n");
                return;
            }
            maxx=q[i];
        }
        else
        {
            if(*p.begin()>maxx)
            {
                printf("-1\n");
                return ;
            }
            else
            {
                ans.push_back(*p.begin());
                p.erase(p.begin());
            }
        }
    }
    for(int i=0; i

C题:https://codeforces.com/contest/1262/problem/C

思路:这道题的话,给你n个括号,这个括号可以进行翻转操作,如 "("->")",最多进行n次翻转操作,再给你k个前缀,让你实现进行不多于n次的翻转实现k个前缀、
下面看看代码,因为要实现k个前缀,所以我们可以让前k-1次都是"()"这样,最后一次是"(())"这样。

#include 
using namespace std;
int n,k,t;
string s;
void swap_swap(int x,int y)
{
    while(x>n>>k;
    cin>>s;
    vector>ans;
    string last=add(n,k);
    for(int i=0; i>t;
    while(t--)
    {
        solve();
    }
    return 0;
}

 

你可能感兴趣的:(cf,思路)