Codeforces Round #440 (Div. 2, based on Technocup 2018 Elimination Round 2)

一场挺简单的CF,但是我打炸了啊

A. Search for Pretty Integers
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You are given two lists of non-zero digits.

Let's call an integer pretty if its (base 10) representation has at least one digit from the first list and at least one digit from the second list. What is the smallest positive pretty integer?

Input

The first line contains two integers n and m (1 ≤ n, m ≤ 9) — the lengths of the first and the second lists, respectively.

The second line contains n distinct digits a1, a2, ..., an (1 ≤ ai ≤ 9) — the elements of the first list.

The third line contains m distinct digits b1, b2, ..., bm (1 ≤ bi ≤ 9) — the elements of the second list.

Output

Print the smallest pretty integer.

Examples
input
2 3
4 2
5 7 6
output
25
input
8 8
1 2 3 4 5 6 7 8
8 7 6 5 4 3 2 1
output
1
Note

In the first example 25, 46, 24567 are pretty, as well as many other integers. The smallest among them is 25. 42and 24 are not pretty because they don't have digits from the second list.

In the second example all integers that have at least one digit different from 9 are pretty. It's obvious that the smallest among them is 1, because it's the smallest positive integer.

 按照0~99枚举这个方法也可以嘛,但是直接枚举也没事嘛

当时忘记1位数肯定小于两位数wa一次,删错ifwa一次,最近的智商是真的低

#include<bits/stdc++.h>
using namespace std;
int a[10],b[10];
int main()
{
    int n,m;
    int c=9,d=9;
    cin>>n>>m;
    while(n--)
    {
        int x;
        cin>>x;
        c=min(c,x);
        a[x]++;
    }
    while(m--)
    {
        int x;
        cin>>x;
        d=min(d,x);
        b[x]++;
    }
    for(int i=1; i<=9; i++)
        if(a[i]&&b[i])
        {
            cout<<i;
            return 0;
        }
    if(c>d)swap(c,d);
    cout<<c<<d;
    return 0;
}
B. Maximum of Maximums of Minimums
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You are given an array a1, a2, ..., an consisting of n integers, and an integer k. You have to split the array into exactly k non-empty subsegments. You'll then compute the minimum integer on each subsegment, and take the maximum integer over the k obtained minimums. What is the maximum possible integer you can get?

Definitions of subsegment and array splitting are given in notes.

Input

The first line contains two integers n and k (1 ≤ k ≤ n ≤  105) — the size of the array a and the number of subsegments you have to split the array to.

The second line contains n integers a1,  a2,  ...,  an ( - 109  ≤  ai ≤  109).

Output

Print single integer — the maximum possible integer you can get if you split the array into k non-empty subsegments and take maximum of minimums on the subsegments.

Examples
input
5 2
1 2 3 4 5
output
5
input
5 1
-4 -5 -3 -2 -1
output
-5
Note

A subsegment [l,  r] (l ≤ r) of array a is the sequence al,  al + 1,  ...,  ar.

Splitting of array a of n elements into k subsegments [l1, r1], [l2, r2], ..., [lk, rk] (l1 = 1, rk = nli = ri - 1 + 1 for all i > 1) is k sequences (al1, ..., ar1), ..., (alk, ..., ark).

In the first example you should split the array into subsegments [1, 4] and [5, 5] that results in sequences (1, 2, 3, 4) and (5). The minimums are min(1, 2, 3, 4) = 1 and min(5) = 5. The resulting maximum is max(1, 5) = 5. It is obvious that you can't reach greater result.

In the second example the only option you have is to split the array into one subsegment [1, 5], that results in one sequence ( - 4,  - 5,  - 3,  - 2,  - 1). The only minimum is min( - 4,  - 5,  - 3,  - 2,  - 1) =  - 5. The resulting maximum is  - 5.

 把一个集合拆成k个非空集合,问你这个集合最小的数最大能是什么

k>=3就按照前面一段,后面一段,中间一段,无论这个最大值在前后都能取到啊,但是k==1,就只能选最小的

k==2前面一段。后面一段,按照断点进行找最小的数,因为从1到n-2个数都是前面取到,后面也能取到,所以只要找到0,n-1最大的数就好了,被自己蠢哭

#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int a[N];
int b[N],c[N];
int main()
{
    int n,k,ma=-(1<<30),mi=1<<30;
    scanf("%d%d",&n,&k);
    for(int i=1; i<=n; i++)
    {
        scanf("%d",&a[i]);
        ma=max(ma,a[i]);
        mi=min(mi,a[i]);
    }
    if(k>=3)
        printf("%d",ma);
    else if(k==1)
        printf("%d",mi);
    else
    {
        int ans=-(1<<30);
        b[1]=a[1];
        ans=max(ans,a[1]);
        ans=max(ans,a[n]);
        for(int i=2; i<=n; i++)
            b[i]=min(b[i-1],a[i]);
        c[n]=a[n];
        for(int i=n-1; i>0; i--)
        {
            c[i]=min(c[i+1],a[i]);
            ans=max(ans,max(c[i],b[i]));
        }
        printf("%d",ans);
    }
    return 0;
}
C. Maximum splitting
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

You are given several queries. In the i-th query you are given a single positive integer ni. You are to represent nias a sum of maximum possible number of composite summands and print this maximum number, or print -1, if there are no such splittings.

An integer greater than 1 is composite, if it is not prime, i.e. if it has positive divisors not equal to 1 and the integer itself.

Input

The first line contains single integer q (1 ≤ q ≤ 105) — the number of queries.

q lines follow. The (i + 1)-th line contains single integer ni (1 ≤ ni ≤ 109) — the i-th query.

Output

For each query print the maximum possible number of summands in a valid splitting to composite summands, or -1, if there are no such splittings.

Examples
input
1
12
output
3
input
2
6
8
output
1
2
input
3
1
2
3
output
-1
-1
-1
Note

12 = 4 + 4 + 4 = 4 + 8 = 6 + 6 = 12, but the first splitting has the maximum possible number of summands.

8 = 4 + 4, 6 can't be split into several composite summands.

1, 2, 3 are less than any composite number, so they do not have valid splittings.

把一个数最多能拆成多少个非素数,看4这个很神奇的数字就行了,最后发现真的和4有关,讨论下就行

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        int n;
        scanf("%d",&n);
        if(n<4||n==7||n==5||n==11)
        printf("-1
");
        else if(n&1)
        printf("%d
",(n-9)/4+1);
        else printf("%d
",n/4);
    }
    return 0;
}
原文地址:https://www.cnblogs.com/BobHuang/p/7682984.html