Codeforces Round #660 (Div. 2)

A:http://codeforces.com/contest/1388/problem/A

题意:

定义近素数:m=x*y,x和y均为素数

给出n,求出a+b+c+d==n

四个不同数中至少三个数为近素数

解析:

先列出前三个近素数:6  10  14

那么满足条件的最小组合为:6  10  14  1

那么n<31,肯定无解

而对于n>=31来讲,可能存在重复,而这种构造方式无非就是与它三个重复,所以直接一个一个判就可以了

#include<bits/stdc++.h>
#include<iostream>
#include<cstring>
#include<string.h>
#include<cmath>
#include<map>
using namespace std;
typedef long long ll;
const int maxn=1e5+20;
int a[maxn],p[maxn],s[maxn];
int main()
{

    int t;
    scanf("%d",&t);
    while(t--)
    {
        int n;
        cin>>n;
        if(n<31)
            cout<<"NO"<<endl;
        else
        {
            cout<<"YES"<<endl;
        //    cout<<"6 10 14 "<<n-30<<endl;
            int md=n-30;
            if(md==6||md==10||md==14)
                cout<<"6 10 15 "<<md-1<<endl;
            else
                cout<<"6 10 14 "<<n-30<<endl;
        }
    }    
}

B:http://codeforces.com/contest/1388/problem/B

题意:

n

求一个n位数x,满足:将每位变成二进制,末尾去掉n位后,它的十进制为最大,而且x为最小。

解析:

7:111

8:1000

9:1001

很明显,删除8是最好的,因为它的0最多,9做为前几位也是最大的。长度越长,越大。

n<=4,最后一位为8

n>4,n/4向上取整即可,便为8的数目

#include<bits/stdc++.h>
#include<iostream>
#include<cstring>
#include<string.h>
#include<cmath>
#include<map>
using namespace std;
typedef long long ll;
const int maxn=1e5+20;
int a[maxn];
int main()
{

    int t;
    scanf("%d",&t);
    while(t--)
    {
        int n;
        cin>>n;
        if(n<=4)
        {
            for(int i=2;i<=n;i++)
                cout<<"9";
            cout<<"8"<<endl;    
        }else
        {
            int md;
            if(n%4==0)
                md=n/4;
            else
                md=n/4+1;
            int yu=n-md;
            for(int i=1;i<=yu;i++)
                cout<<"9";
            for(int i=1;i<=md;i++)
                cout<<"8";
                cout<<endl;
        }
    }    
}
原文地址:https://www.cnblogs.com/liyexin/p/13415717.html