1. 程式人生 > >Lyft Level 5 Challenge 2018 - Elimination Round 題解

Lyft Level 5 Challenge 2018 - Elimination Round 題解

A題:

女王棋子將棋盤劃分為四個象限,判斷兩個棋子的座標是否在同一象限即可

#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<list>
#include<map>
#include<set>
#include<vector>

typedef long long int ll;
const int  maxn =100000+10;
const int  mod =998244353;
const int INF=0x3f3f3f3f;

using namespace std;

int main()
{
    int n;scanf("%d",&n);
    int a,b;scanf("%d%d",&a,&b);
    int c,d;scanf("%d%d",&c,&d);
    int e,v;scanf("%d%d",&e,&v);
    if(c<a&&d<b)
    {
        if(e<a&&v<b) cout<<"yes";
        else cout<<"no";
    }
    if(c<a&&d>b)
    {
        if(e<a&&v>b)cout<<"yes";
        else cout<<"no";
    }
    if(c>a&&d<b)
    {
        if(e>a&&v<b)cout<<"yes";
        else cout<<"no";
    }
    if(c>a&&d>b)
    {
        if(e>a&&v>b)cout<<"yes";
        else cout<<"no";
    }
    return 0;
}

B題:

a-b=1,a+b是質數

#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<list>
#include<map>
#include<set>
#include<vector>

typedef long long int ll;
const int  maxn =100000+10;
const int  mod =998244353;
const int INF=0x3f3f3f3f;

using namespace std;
int solve(ll a)
{
	int flag=1;
	for(ll i=2;i<=sqrt(a);i++)
		if(a%i==0) {flag=0;break;}
	return flag;
}
int main()
{
	int t;scanf("%d",&t);
	while(t--)
	{
		ll a,b;cin>>a>>b;
		if(a-b==1)
		{
			if(solve(a+b)==1) cout<<"yes"<<endl;
			else cout<<"no"<<endl;
		}
		else cout<<"no"<<endl;
	}
	return 0;
}

C題:

DP。 待補