Codeforce 1494B. Berland Crossword (Thinking)

Topic link

General idea

Give you an n*n matrix, which is always a color at the beginning, let you map its color on the top, right, bottom, and left. Give you the number of blocks you paint and ask if you can Paint to meet the requirements.

Ideas

u (up), (d), down, l (left), r (right)
First of all, when u == n, then it means that l and r need to use one and move to the top of them, the same if d It also means that both nl and r must be used and moved to the bottom of them. At this time, it is necessary to judge whether l and r are feasible.
The second is that if u is equal to n-1, then one of l and r needs to be used. One, d is the same, combined with the above is actually us. Only need to judge the number of l + r is greater than or equal to ((the number of u = n) + (the number of d = n)) * 2 (that is, l and The amount that r needs to occupy]+((the number of u=n-1)+(the number of d=n-1)) [that is, the number of l and r only needs one].
Similarly, l and r are also upward Just judge that way.

#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;
}

Guess you like

Origin blog.csdn.net/weixin_45911397/article/details/114818004
Recommended