A. Remainder

output
standard output

You are given a huge decimal number consisting of 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 10x.

Input

The first line of the input contains three integers y, respectively.

The second line of the input contains one decimal number consisting of 1.

Output

Print one integer — the minimum number of operations you should perform to obtain the number having remainder 10x.

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 100000.

In the second example the number will be 100000.

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

代码:

#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 k problems.

Polycarp has a list of k-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 1≤n≤2⋅105) — the number of contests.

The second line of the input contains i-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 s, you have to delete minimum number of characters from this string so that it becomes good.

Input

The first line contains one integer s.

The second line contains the string n lowercase Latin letters.

Output

In the first line, print one integer s to make it good.

In the second line, print the resulting string 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",n-sum);
   int cnt=0;
   while(!q.empty())
   {
       if(cnt==sum)
       {
           break;
    }
    cnt++;
       printf("%c",q.front());
       q.pop();
   }
   printf("\n");
   
   return 0;
}

D. Almost All Divisors

We guessed some integer number x in the list.

Your task is to find the minimum possible integer x 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 t independent queries.

Input

The first line of the input contains one integer t queries follow.

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

The second line of the query contains 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 x.

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 n.

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

Your task is to reorder the elements (choose an arbitrary order of elements) of the array minimize the answer but not its remainder.

Input

The first line of the input contains one integer b.

The second line of the input contains a.

The third line of the input contains b.

Output

Print one integer — the minimum possible value of 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;
}

 

 

相关文章: