Codeforce 1494B。Berland Crossword(思考)

トピックリンク

一般的なアイデア

常に最初の色であるn * n行列を与え、その色を上、右、下、左にマッピングします。ペイントするブロックの数を指定し、ペイントして要件。

アイデア

u(上)、(d)、下、l(左)、r(右)
まず、u == nの場合、lとrは1つを使用して、それらの上部に移動する必要があることを意味します。 dの場合も同じnlとrの両方を使用して、それらの一番下に移動する必要があることも意味します。このとき、lとrが実行可能かどうかを判断する必要があります
。2つ目は、uがn-1に等しい場合です。、次にlとrのいずれかを使用する必要があります。1つ、dは同じであり、上記と組み合わせると実際には私たちです。l+ rの数が((uの数= n)+(d = nの数))* 2(つまり、lとrが占める必要のある量] +((u = n-1の数)+(d = n-1の数))[つまり、lとrの数は1つだけ必要です]。
同様に、lとrも上向きです。そのように判断してください。

#include <map>
#include <queue>
#include <string>
#include<iostream>
#include<stdio.h>
#include<string.h>
#include <algorithm>
#include <math.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
typedef pair<ll,ll> pii;
#define mem(a,x) memset(a,x,sizeof(a))
#define debug(x) cout << #x << ": " << x << endl;
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<=(b);++i)
#define repr(i,b,a) for(int i=int(b);i>=(a);--i)
const int maxn=2e5+1010;
#define inf 0x3f3f3f3f
#define sf scanf
#define pf printf
const int mod=998244353;
const int MOD=10007;

inline int read() {
    
    
    int x=0;
    bool t=false;
    char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
    if(ch=='-')t=true,ch=getchar();
    while(ch<='9'&&ch>='0')x=x*10+ch-48,ch=getchar();
    return t?-x:x;
}

/*
vector<ll> m1;
vector<ll> m2;
priority_queue<ll , vector<ll> , greater<ll> > mn;//上  小根堆 		小到大
priority_queue<ll , vector<ll> , less<ll> > mx;//下   	大根堆  	大到小
*/
map<ll,ll>mp;
map<ll,ll>mpp;
ll n,u,d,r,l;
#define read read()
int main() {
    
    
    ll t;
    cin>>t;
    while(t--) {
    
    
        cin>>n>>u>>r>>d>>l;
        ll u1,u2,l1,l2;
        bool flag=1;
        u1=u2=l1=l2=0;
        if(u==n) u2++;
        if(d==n) u2++;
        if(u==n-1) u1++;
        if(d==n-1) u1++;
        if(l<u2||r<u2) flag=0;
        if(l+r<2*u2+u1) flag=0;

        if(l==n) l2++;
        if(r==n) l2++;
        if(l==n-1) l1++;
        if(r==n-1) l1++;

        if(u<l2||d<l2) flag=0;
        if(u+d<2*l2+l1) flag=0;
        if(flag) puts("YES");
        else puts("NO");



    }
    return 0;
}

おすすめ

転載: blog.csdn.net/weixin_45911397/article/details/114818004