zoukankan      html  css  js  c++  java
  • Codeforces Round #560 (Div. 3)A-E

    A. Remainder

    output
    standard output

    You are given a huge decimal number consisting of nn digits. It is guaranteed that this number has no leading zeros. Each digit of this number is either 0 or 1.

    You may perform several (possibly zero) operations with this number. During each operation you are allowed to change any digit of your number; you may change 0 to 1 or 1 to 0. It is possible that after some operation you can obtain a number with leading zeroes, but it does not matter for this problem.

    You are also given two integers 0y<x<n0≤y<x<n. Your task is to calculate the minimum number of operations you should perform to obtain the number that has remainder 10y10y modulo 10x10x. In other words, the obtained number should have remainder 10y10y when divided by 10x10x.

    Input

    The first line of the input contains three integers n,x,yn,x,y (0y<x<n21050≤y<x<n≤2⋅105) — the length of the number and the integers xxand yy, respectively.

    The second line of the input contains one decimal number consisting of nn digits, each digit of this number is either 0 or 1. It is guaranteed that the first digit of the number is 1.

    Output

    Print one integer — the minimum number of operations you should perform to obtain the number having remainder 10y10y modulo 10x10x. In other words, the obtained number should have remainder 10y10y when divided by 10x10x.

    Examples
    input
    Copy
    11 5 2
    11010100101
    
    output
    Copy
    1
    
    input
    Copy
    11 5 1
    11010100101
    
    output
    Copy
    3
    
    Note

    In the first example the number will be 1101010010011010100100 after performing one operation. It has remainder 100100 modulo 100000100000.

    In the second example the number will be 1101010001011010100010 after performing three operations. It has remainder 1010 modulo 100000100000.

    思路:只需要看需要的位数

    代码:

    #include<cstdio>
    #include<iostream>
    #include<cstring>
    #include<algorithm>
    #include<queue>
    #include<stack>
    #include<set>
    #include<vector>
    #include<map>
    #include<cmath>
    const int maxn=1e5+5;
    typedef long long ll;
    using namespace std;
    
    char a[2*maxn];
    int main()
    {
       int n,x,y;
       cin>>n>>x>>y;
       scanf("%s",a);
       int sum=0;
       
       for(int t=n-1;t>=n-x;t--)
       {
         if(a[t]=='0'&&t!=n-y-1)
         {
             continue;
         }
         else if(a[t]=='1'&&t!=n-y-1)
         {
             sum++;
         }
         else if(a[t]=='1'&&t==n-y-1)
         {
             continue;
         }
         else if(a[t]=='0'&&t==n-y-1)
         {
             sum++;
         }
       }
       printf("%d",sum);
       return 0;
    }

    B. Polycarp Training

    Polycarp wants to train before another programming competition. During the first day of his training he should solve exactly 11 problem, during the second day — exactly 22 problems, during the third day — exactly 33 problems, and so on. During the kk-th day he should solve kk problems.

    Polycarp has a list of nn contests, the ii-th contest consists of aiai problems. During each day Polycarp has to choose exactly one of the contests he didn't solve yet and solve it. He solves exactly kk problems from this contest. Other problems are discarded from it. If there are no contests consisting of at least kk problems that Polycarp didn't solve yet during the kk-th day, then Polycarp stops his training.

    How many days Polycarp can train if he chooses the contests optimally?

    Input

    The first line of the input contains one integer nn (1n21051≤n≤2⋅105) — the number of contests.

    The second line of the input contains nn integers a1,a2,,ana1,a2,…,an (1ai21051≤ai≤2⋅105) — the number of problems in the ii-th contest.

    Output

    Print one integer — the maximum number of days Polycarp can train if he chooses the contests optimally.

    Examples
    input
    Copy
    4
    3 1 4 1
    
    output
    Copy
    3
    
    input
    Copy
    3
    1 1 1
    
    output
    Copy
    1
    
    input
    Copy
    5
    1 1 1 2 2
    
    output
    Copy
    2
    

     思路:优先队列

    代码:

    #include<cstdio>
    #include<cstring>
    #include<iostream>
    #include<algorithm>
    #include<queue>
    #include<stack>
    #include<set>
    #include<map>
    #include<algorithm>
    #include<vector>
    
    const int maxn=2e5+5;
    typedef long long ll;
    using namespace std;
    priority_queue<int,vector<int>,greater<int> >q;
    int main()
    {
        int n,x;
        cin>>n;
        for(int i=1;i<=n;i++)
        {
            cin>>x;
            q.push(x);
        }
        int ans=0;
        for(int i=1;;i++)
        {
            while(!q.empty())
            {
                x=q.top();q.pop();
                if(x>=i)
                {
                    x-=i;
                    ans=i;
                    break;
                }
            }
            if(q.empty())
                break;
        }
        cout<<ans;
    }

    C. Good String

    Let's call (yet again) a string good if its length is even, and every character in odd position of this string is different from the next character (the first character is different from the second, the third is different from the fourth, and so on). For example, the strings good, string and xyyx are good strings, and the strings bad, aa and aabc are not good. Note that the empty string is considered good.

    You are given a string ss, you have to delete minimum number of characters from this string so that it becomes good.

    Input

    The first line contains one integer nn (1n21051≤n≤2⋅105) — the number of characters in ss.

    The second line contains the string ss, consisting of exactly nn lowercase Latin letters.

    Output

    In the first line, print one integer kk (0kn0≤k≤n) — the minimum number of characters you have to delete from ss to make it good.

    In the second line, print the resulting string ss. If it is empty, you may leave the second line blank, or not print it at all.

    Examples
    input
    Copy
    4
    good
    
    output
    Copy
    0
    good
    
    input
    Copy
    4
    aabc
    
    output
    Copy
    2
    ab
    
    input
    Copy
    3
    aaa
    
    output
    Copy
    3
    
    

     用队列模拟一下取不取的过程

    代码:

    #include<cstdio>
    #include<iostream>
    #include<cstring>
    #include<algorithm>
    #include<queue>
    #include<stack>
    #include<set>
    #include<vector>
    #include<map>
    #include<cmath>
    const int maxn=1e5+5;
    typedef long long ll;
    using namespace std;
    char str[2*maxn];
    int main()
    {
       int n;
       cin>>n;
       scanf("%s",str+1);
       int sum=1;
       char ss=str[1];
       queue<char>q;
       q.push(ss);
       for(int t=2;t<=n;t++)
       {
           if(sum%2==1&&str[t]==ss)
           {
               continue;
        }
        sum++;
        ss=str[t];
        q.push(str[t]);
       }
       if(sum%2==1)
       {
           sum--;
       }
       printf("%d
    ",n-sum);
       int cnt=0;
       while(!q.empty())
       {
           if(cnt==sum)
           {
               break;
        }
        cnt++;
           printf("%c",q.front());
           q.pop();
       }
       printf("
    ");
       
       return 0;
    }

    D. Almost All Divisors

    We guessed some integer number xx. You are given a list of almost all its divisors. Almost all means that there are all divisors except 11 and xx in the list.

    Your task is to find the minimum possible integer xx that can be the guessed number, or say that the input data is contradictory and it is impossible to find such number.

    You have to answer tt independent queries.

    Input

    The first line of the input contains one integer tt (1t251≤t≤25) — the number of queries. Then tt queries follow.

    The first line of the query contains one integer nn (1n3001≤n≤300) — the number of divisors in the list.

    The second line of the query contains nn integers d1,d2,,dnd1,d2,…,dn (2di1062≤di≤106), where didi is the ii-th divisor of the guessed number. It is guaranteed that all values didi are distinct.

    Output

    For each query print the answer to it.

    If the input data in the query is contradictory and it is impossible to find such number xx that the given list of divisors is the list of almost all its divisors, print -1. Otherwise print the minimum possible xx.

    Example
    input
    Copy
    2
    8
    8 2 12 6 4 24 16 3
    1
    2
    
    output
    Copy
    48
    4
    

     前面有此题的思路和代码

    E. Two Arrays and Sum of Functions

    You are given two arrays aa and bb, both of length nn.

    Let's define a function f(l,r)=liraibif(l,r)=∑l≤i≤rai⋅bi.

    Your task is to reorder the elements (choose an arbitrary order of elements) of the array bb to minimize the value of 1lrnf(l,r)∑1≤l≤r≤nf(l,r). Since the answer can be very large, you have to print it modulo 998244353998244353. Note that you should minimize the answer but not its remainder.

    Input

    The first line of the input contains one integer nn (1n21051≤n≤2⋅105) — the number of elements in aa and bb.

    The second line of the input contains nn integers a1,a2,,ana1,a2,…,an (1ai1061≤ai≤106), where aiai is the ii-th element of aa.

    The third line of the input contains nn integers b1,b2,,bnb1,b2,…,bn (1bj1061≤bj≤106), where bjbj is the jj-th element of bb.

    Output

    Print one integer — the minimum possible value of 1lrnf(l,r)∑1≤l≤r≤nf(l,r) after rearranging elements of bb, taken modulo 998244353998244353. Note that you should minimize the answer but not its remainder.

    Examples
    input
    Copy
    5
    1 8 7 2 4
    9 7 2 9 3
    
    output
    Copy
    646
    
    input
    Copy
    1
    1000000
    1000000
    
    output
    Copy
    757402647
    
    input
    Copy
    2
    1 3
    4 2
    
    output
    Copy
    20
    

     思考贡献次数和排序

    注意取模

    代码:

    #include<cstdio>
    #include<cstring>
    #include<iostream>
    #include<algorithm>
    #include<queue>
    #include<stack>
    #include<set>
    #include<map>
    #include<algorithm>
    #include<vector>
    
    const int maxn=1e5+5;
    typedef long long ll;
    using namespace std;
    ll a[2*maxn],b[maxn*2];
    bool cmp(int x,int y)
    {
        return x>y;
    }
    int main()
    {
        int n;
        cin>>n;
        for(int t=0;t<n;t++)
        {
            scanf("%lld",&a[t]);
            a[t]=(a[t]*(n-t)*(t+1));
        }
        for(int t=0;t<n;t++)
        {
            scanf("%lld",&b[t]);
        }
        sort(a,a+n);
        sort(b,b+n,cmp);
        ll ans=0;
        for(int t=0;t<n;t++)
        {
            
            ans=(ans%998244353+((a[t]%998244353)*(b[t]%998244353))%998244353)%998244353;
        }
        printf("%lld",ans);
        
        return 0;
    }
  • 相关阅读:
    Laravel路由除了根目录全报404错误
    jQuery源码分析之整体框架
    JS进阶系列之this
    JS进阶系列之原型、原型链
    原生JavaScript实现的贪吃蛇
    html文档流和事件流
    (转)mysql执行计划分析
    (转)重定向和转发区别
    el表达式取值优先级
    (转)性能测试基本指标
  • 原文地址:https://www.cnblogs.com/Staceyacm/p/10876667.html
Copyright © 2011-2022 走看看