码迷,mamicode.com
首页 > 其他好文 > 详细

2018青岛现场赛

时间:2018-11-11 23:29:51      阅读:261      评论:0      收藏:0      [点我收藏+]

标签:oss   scan   int   for   分享图片   ace   algorithm   main   \n   

A - Sequence and Sequence

留坑

 

B - Kawa Exam

留坑

 

C - Flippy Sequence

留坑

 

D - Magic Multiplication

技术分享图片
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<sstream>
#include<cmath>
#include<cstdlib>
#include<queue>
using namespace std;

#define ll long long
#define llu unsigned long long
#define INF 0x3f3f3f3f
#define PI acos(-1.0)

const int maxn=2e5+5;
int N,M,len;
char str[maxn];
int A[maxn];
int B[maxn];
int pos;
bool getB()
{
    for(int i=0;i<M;i++)
    {
        int now=str[pos++]-0;
        if(A[0]>now && now!=0)
            now=now*10+str[pos++]-0;
        if(now%A[0]==0)
        {
            B[i]=now/A[0];
            if(B[i]>=10)
                return false;
        }
        else
            return false;
    }
    return true;
}

bool getA()
{
    for(int i=1;i<N;i++)
    {
        int now=str[pos++]-0;
        if(B[0]>now && now != 0)
            now=now*10+str[pos++]-0;
        if(now%B[0]==0)
        {
            A[i]=now/B[0];
            if(A[i]>=10)
                return false;
        }
        else
            return false;
        for(int j=1;j<M;j++)
        {
            int now=str[pos++]-0;
            if(A[i]>now && now != 0)
                now=now*10+str[pos++]-0;
            if(A[i]*B[j]!=now)
                return false;
        }
    }
    return true;
    
}
bool solve()
{
    int one=str[0]-0;
    int two=one*10+str[1]-0;
    for(int i=1;i<=9;i++)
    {
        pos=0;
        if(one % i == 0)
        {
            A[0]=i;
            if(getB() && getA() && pos == len)
                return true;
        }
    }
    for(int i=1;i<=9;i++)
    {
        pos=0;
        if(two % i == 0 && two / i <10)
        {
            A[0]=i;
            if(getB() && getA() && pos == len)
                return true;
        }
    }
    return false;
}
int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        scanf("%d%d",&N,&M);
        scanf("%s",str);
        len=strlen(str);
        if(solve())
        {
            for(int i=0;i<N;i++)
                printf("%d",A[i]);
            printf(" ");
            for(int i=0;i<M;i++)
                printf("%d",B[i]);
            puts("");
        }
        else
            puts("Impossible");
    }
    return 0;
}
View Code

 

 

E - Plants vs. Zombies

留坑

 

F - Tournament

留坑

 

G - Repair the Artwork

留坑

 

H - Mirror

 

I - Soldier Game

 

J - Books

技术分享图片
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<sstream>
#include<cmath>
#include<cstdlib>
#include<queue>
using namespace std;

#define ll long long
#define llu unsigned long long
#define INF 0x3f3f3f3f
#define PI acos(-1.0)
const int maxn = 1e5 + 5;

int a[maxn];
int b[maxn];
int main()
{
    int t;
    scanf("%d",&t);
    while (t--)
    {
        int n, m;
        scanf("%d%d", &n, &m);
        int minn = INF;
        int num0 = 0;
        int ca = 1;
        for (int i = 1; i <= n; i++)
        {
            scanf("%d", &a[i]);
            if (a[i] != 0)
            {
                minn = min(minn, a[i]);
                b[ca] = a[i];
                ca++;
            }

            if (a[i] == 0)
                num0++;
        }
        if (n == m)
            puts("Richman");
        else if (num0 > m)
            puts("Impossible");
        else if (num0==0 && m == 0)
        {
            printf("%d\n", minn - 1);
        }
        else
        {
            ll sum=0;
            int book = m - num0;
            for (int i = 1; i <= book ; i++)
                sum += b[i];
            int num=INF;
            for (int i = book + 1; i < ca; i++)
                num = min(num, b[i]);
            printf("%lld\n", sum+num - 1);
        }


    }
    return 0;
}
View Code

 

 

K - Airdrop

 

L - Sub-cycle Graph

 

M - Function and Function

2018青岛现场赛

标签:oss   scan   int   for   分享图片   ace   algorithm   main   \n   

原文地址:https://www.cnblogs.com/smallhester/p/9943408.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!