zoukankan      html  css  js  c++  java
  • Codeforces Round #388 (Div. 2) A,B,C,D

    A. Bachgold Problem
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Bachgold problem is very easy to formulate. Given a positive integer n represent it as a sum of maximum possible number of prime numbers. One can prove that such representation exists for any integer greater than 1.

    Recall that integer k is called prime if it is greater than 1 and has exactly two positive integer divisors — 1 and k.

    Input

    The only line of the input contains a single integer n (2 ≤ n ≤ 100 000).

    Output

    The first line of the output contains a single integer k — maximum possible number of primes in representation.

    The second line should contain k primes with their sum equal to n. You can print them in any order. If there are several optimal solution, print any of them.

    Examples
    input
    5
    output
    2
    2 3
    input
    6
    output
    3
    2 2 2

     题意:给你一个数n,求n最多由多少个素数和相加;

    思路:去最小的2,3即可;

    #include<bits/stdc++.h>
    using namespace std;
    #define ll long long
    #define mod 1000000007
    #define esp 0.00000000001
    const int N=1e5+10,M=1e6+10,inf=1e9;
    const ll INF=1e18+10;
    int main()
    {
        int n;
        scanf("%d",&n);
        if(n%2)
        {
            printf("%d
    ",(n-3)/2+1);
            printf("3 ");
            for(int i=0;i<(n-3)/2;i++)
                printf("2 ");
        }
        else
        {
            printf("%d
    ",n/2);
            for(int i=0;i<n/2;i++)
                printf("2 ");
        }
        return 0;
    }
    B. Parallelogram is Back
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Long time ago Alex created an interesting problem about parallelogram. The input data for this problem contained four integer points on the Cartesian plane, that defined the set of vertices of some non-degenerate (positive area) parallelogram. Points not necessary were given in the order of clockwise or counterclockwise traversal.

    Alex had very nice test for this problem, but is somehow happened that the last line of the input was lost and now he has only three out of four points of the original parallelogram. He remembers that test was so good that he asks you to restore it given only these three points.

    Input

    The input consists of three lines, each containing a pair of integer coordinates xi and yi ( - 1000 ≤ xi, yi ≤ 1000). It's guaranteed that these three points do not lie on the same line and no two of them coincide.

    Output

    First print integer k — the number of ways to add one new integer point such that the obtained set defines some parallelogram of positive area. There is no requirement for the points to be arranged in any special order (like traversal), they just define the set of vertices.

    Then print k lines, each containing a pair of integer — possible coordinates of the fourth point.

    Example
    input
    0 0
    1 0
    0 1
    output
    3
    1 -1
    -1 1
    1 1
    Note

    If you need clarification of what parallelogram is, please check Wikipedia page:

    https://en.wikipedia.org/wiki/Parallelogram

    题意:给你一个平行四边行的三个点求第四个点的可能位置;

    思路:模拟;

    #include<bits/stdc++.h>
    using namespace std;
    #define ll long long
    #define mod 1000000007
    #define esp 0.00000000001
    const int N=1e5+10,M=1e6+10,inf=1e9;
    const ll INF=1e18+10;
    int x[18],y[20];
    set<pair<int,int> >s;
    set<pair<int,int> >::iterator it;
    void getans(int pos,int dx,int dy)
    {
        s.insert(make_pair(x[pos]+dx,y[pos]+dy));
        s.insert(make_pair(x[pos]-dx,y[pos]-dy));
    }
    int main()
    {
        int n;
        for(int i=1;i<=3;i++)
        {
            scanf("%d%d",&x[i],&y[i]);
        }
        getans(1,x[2]-x[3],y[2]-y[3]);
        getans(2,x[1]-x[3],y[1]-y[3]);
        getans(3,x[1]-x[2],y[1]-y[2]);
        printf("%d
    ",s.size());
        for(it=s.begin();it!=s.end();it++)
        {
            cout<<it->first<<" "<<it->second<<endl;
        }
        return 0;
    }
    C. Voting
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    There are n employees in Alternative Cake Manufacturing (ACM). They are now voting on some very important question and the leading world media are trying to predict the outcome of the vote.

    Each of the employees belongs to one of two fractions: depublicans or remocrats, and these two fractions have opposite opinions on what should be the outcome of the vote. The voting procedure is rather complicated:

    1. Each of n employees makes a statement. They make statements one by one starting from employees 1 and finishing with employeen. If at the moment when it's time for the i-th employee to make a statement he no longer has the right to vote, he just skips his turn (and no longer takes part in this voting).
    2. When employee makes a statement, he can do nothing or declare that one of the other employees no longer has a right to vote. It's allowed to deny from voting people who already made the statement or people who are only waiting to do so. If someone is denied from voting he no longer participates in the voting till the very end.
    3. When all employees are done with their statements, the procedure repeats: again, each employees starting from 1 and finishing withn who are still eligible to vote make their statements.
    4. The process repeats until there is only one employee eligible to vote remaining and he determines the outcome of the whole voting. Of course, he votes for the decision suitable for his fraction.

    You know the order employees are going to vote and that they behave optimal (and they also know the order and who belongs to which fraction). Predict the outcome of the vote.

    Input

    The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the number of employees.

    The next line contains n characters. The i-th character is 'D' if the i-th employee is from depublicans fraction or 'R' if he is from remocrats.

    Output

    Print 'D' if the outcome of the vote will be suitable for depublicans and 'R' if remocrats will win.

    Examples
    input
    5
    DDRRR
    output
    D
    input
    6
    DDRRRR
    output
    R
    Note

    Consider one of the voting scenarios for the first sample:

    1. Employee 1 denies employee 5 to vote.
    2. Employee 2 denies employee 3 to vote.
    3. Employee 3 has no right to vote and skips his turn (he was denied by employee 2).
    4. Employee 4 denies employee 2 to vote.
    5. Employee 5 has no right to vote and skips his turn (he was denied by employee 1).
    6. Employee 1 denies employee 4.
    7. Only employee 1 now has the right to vote so the voting ends with the victory of depublicans.

    题意:n个人,分成两个党派,从1-n,每个人有投票的权利,从1-n按顺序开始投票

        如果被人投了票,那么就没有投票的权利了; 也可以选择不投票

        问最后一个有投票权利的党派是那个;

    思路:贪心,对于一个人,需要投他后面离他最近的不同党派的人,因为前面的已经决定了,要让后面的人没有投票的人失去权利,并且离他近的更优;

    #include<bits/stdc++.h>
    using namespace std;
    #define ll long long
    #define mod 1000000007
    #define esp 0.00000000001
    const int N=2e5+10,M=1e6+10,inf=1e9;
    const ll INF=1e18+10;
    char a[N];
    char b[N];
    queue<char>q;
    int check(int si,char c)
    {
        for(int i=1;i<=si;i++)
            if(a[i]!=c)
        return 0;
        return 1;
    }
    int main()
    {
        int n;
        scanf("%d",&n);
        scanf("%s",a+1);
        int si=n;
        while(1)
        {
            if(check(si,'D'))break;
            if(check(si,'R'))break;
            int p=0;
            for(int i=1;i<=si;i++)
            {
                if(q.empty())
                    q.push(a[i]);
                else if(q.front()==a[i])
                    q.push(a[i]);
                else
                {
                    b[++p]=q.front();
                    q.pop();
                }
            }
            int k=0;
            while(!q.empty())
            {
                a[++k]=q.front();
                q.pop();
            }
            for(int i=1;i<=p;i++)
                a[++k]=b[i];
            si=k;
        }
        printf("%c
    ",a[1]);
        return 0;
    }
    D. Leaving Auction
    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    There are n people taking part in auction today. The rules of auction are classical. There were n bids made, though it's not guaranteed they were from different people. It might happen that some people made no bids at all.

    Each bid is define by two integers (ai, bi), where ai is the index of the person, who made this bid and bi is its size. Bids are given in chronological order, meaning bi < bi + 1 for all i < n. Moreover, participant never makes two bids in a row (no one updates his own bid), i.e. ai ≠ ai + 1 for all i < n.

    Now you are curious with the following question: who (and which bid) will win the auction if some participants were absent? Consider that if someone was absent, all his bids are just removed and no new bids are added.

    Note, that if during this imaginary exclusion of some participants it happens that some of the remaining participants makes a bid twice (or more times) in a row, only first of these bids is counted. For better understanding take a look at the samples.

    You have several questions in your mind, compute the answer for each of them.

    Input

    The first line of the input contains an integer n (1 ≤ n ≤ 200 000) — the number of participants and bids.

    Each of the following n lines contains two integers ai and bi (1 ≤ ai ≤ n, 1 ≤ bi ≤ 109, bi < bi + 1) — the number of participant who made the i-th bid and the size of this bid.

    Next line contains an integer q (1 ≤ q ≤ 200 000) — the number of question you have in mind.

    Each of next q lines contains an integer k (1 ≤ k ≤ n), followed by k integers lj (1 ≤ lj ≤ n) — the number of people who are not coming in this question and their indices. It is guarenteed that lj values are different for a single question.

    It's guaranteed that the sum of k over all question won't exceed 200 000.

    Output

    For each question print two integer — the index of the winner and the size of the winning bid. If there is no winner (there are no remaining bids at all), print two zeroes.

    Examples
    input
    6
    1 10
    2 100
    3 1000
    1 10000
    2 100000
    3 1000000
    3
    1 3
    2 2 3
    2 1 2
    output
    2 100000
    1 10
    3 1000
    input
    3
    1 10
    2 100
    1 1000
    2
    2 1 2
    2 2 3
    output
    0 0
    1 10
    Note

    Consider the first sample:

    • In the first question participant number 3 is absent so the sequence of bids looks as follows:
      1. 10
      2. 100
      3. 10 000
      4. 100 000
      Participant number 2 wins with the bid 100 000.
    • In the second question participants 2 and 3 are absent, so the sequence of bids looks:
      1. 10
      2. 10 000
      The winner is, of course, participant number 1 but the winning bid is 10 instead of 10 000 as no one will ever increase his own bid (in this problem).
    • In the third question participants 1 and 2 are absent and the sequence is:
      1. 1 000
      2. 1 000 000
      The winner is participant 3 with the bid 1 000.

    题意:拍卖一个东西,n个操作,表示第i个人出价,并且出价递增,

         q个询问,每个询问去掉k个人,即把这k个人的相关出价全部去掉;

       求能拍卖下这个东西的人是那个,并且出价多少;

            没有输出0 0;

    思路:线段树+二分;

       开始觉得一个人出价多次,怎么写,都不行;

       但是后来你会发现,一个人的出价只是最大值有用;

       k个人只要把最大值改成0即可;

       你留下最大值就可以知道是必然是那个人拍下的东西;

       把拍下东西的人的值改成0;

       二分拍东西人的出价,>=其他人的出价最小值即可;

       详见代码;

    #include<bits/stdc++.h>
    using namespace std;
    #define ll long long
    #define mod 1000000007
    #define esp 0.00000000001
    const int N=2e5+10,M=1e6+10,inf=1e9;
    const ll INF=1e18+10;
    int maxx[N<<2];
    vector<int>v[N];
    void build(int l,int r,int pos)
    {
        if(l==r)
        {
            maxx[pos]=0;
            return;
        }
        int mid=(l+r)>>1;
        build(l,mid,pos<<1);
        build(mid+1,r,pos<<1|1);
        maxx[pos]=max(maxx[pos<<1],maxx[pos<<1|1]);
    }
    void update(int p,int c,int l,int r,int pos)
    {
        if(l==r&&l==p)
        {
            maxx[pos]=c;
            return;
        }
        int mid=(l+r)>>1;
        if(p<=mid)
            update(p,c,l,mid,pos<<1);
        else
            update(p,c,mid+1,r,pos<<1|1);
        maxx[pos]=max(maxx[pos<<1],maxx[pos<<1|1]);
    }
    int query(int m,int l,int r,int pos)
    {
        if(l==r)
        {
            return l;
        }
        int mid=(l+r)>>1;
        if(maxx[pos<<1]==m)
            query(m,l,mid,pos<<1);
        else
            query(m,mid+1,r,pos<<1|1);
    }
    int a[N];
    int main()
    {
        int n;
        scanf("%d",&n);
        build(1,n,1);
        for(int i=1; i<=n; i++)
        {
            int a,b;
            scanf("%d%d",&a,&b);
            v[a].push_back(b);
            update(a,b,1,n,1);
        }
        int q;
        scanf("%d",&q);
        while(q--)
        {
            int k;
            scanf("%d",&k);
            for(int i=1;i<=k;i++)
            {
                scanf("%d",&a[i]);
                update(a[i],0,1,n,1);
            }
            if(maxx[1]==0)
            {
                printf("0 0
    ");
                for(int i=1;i<=k;i++)
                {
                int l=v[a[i]].size()-1;
                if(l<0)
                    continue;
                update(a[i],v[a[i]][l],1,n,1);
                }
                continue;
            }
            int pos=query(maxx[1],1,n,1);
            update(pos,0,1,n,1);
            int st=0;
            int en=v[pos].size()-1,ans;
            while(st<=en)
            {
                int mid=(st+en)>>1;
                if(v[pos][mid]>=maxx[1])
                {
                    ans=v[pos][mid];
                    en=mid-1;
                }
                else
                    st=mid+1;
            }
            printf("%d %d
    ",pos,ans);
            int l=v[pos].size()-1;
            update(pos,v[pos][l],1,n,1);
            for(int i=1;i<=k;i++)
            {
                int l=v[a[i]].size()-1;
                if(l<0)continue;
                update(a[i],v[a[i]][l],1,n,1);
            }
        }
        return 0;
    }
  • 相关阅读:
    MySql 用户 及权限操作
    MAC 重置MySQL root 密码
    在mac系统安装Apache Tomcat的详细步骤[转]
    Maven:mirror和repository 区别
    ES6 入门系列
    转场动画CALayer (Transition)
    OC 异常处理
    Foundation 框架
    Enum枚举
    Invalid App Store Icon. The App Store Icon in the asset catalog in 'xxx.app' can’t be transparent nor contain an alpha channel.
  • 原文地址:https://www.cnblogs.com/jhz033/p/6202232.html
Copyright © 2011-2022 走看看