Educational Codeforces Round 106 (Rated for Div. 2) A. Domino on Windowsill 贪心水题
-  测试样例 input 
 5
 1 0 1
 1 0
 1 1 1
 0 0
 3 0 0
 1 3
 4 3 1
 2 2
 5 4 3
 3 1
 output
 NO
 YES
 NO
 YES
 YES
-  Note In the first test case, n = 1 , k 1 = 0 n=1, k_1=0 n=1,k1=0 and k 2 = 1. k_2=1. k2=1. It means that 2 × 1 2×1 2×1 board has black cell ( 1 , 1 ) (1,1) (1,1) and white cell ( 2 , 1 ) (2,1) (2,1). So, you can’t place any white domino, since there is only one white cell. 
 In the second test case, the board of the same size 2×1, but both cell are white. Since w=0 and b=0, so you can place 0+0=0 dominoes on the board.
 In the third test case, board 2 × 3 2×3 2×3, but fully colored in black (since k1=k2=0), so you can’t place any white domino.
 In the fourth test case, cells ( 1 , 1 ) , ( 1 , 2 ) , ( 1 , 3 ) (1,1), (1,2), (1,3) (1,1),(1,2),(1,3), and ( 2 , 1 ) (2,1) (2,1)are white and other cells are black. You can place 2 white dominoes at positions ( ( 1 , 1 ) , ( 2 , 1 ) ) ((1,1),(2,1)) ((1,1),(2,1)) and ( ( 1 , 2 ) , ( 1 , 3 ) ) ((1,2),(1,3)) ((1,2),(1,3)) and 2 2 2 black dominoes at positions ( ( 1 , 4 ) , ( 2 , 4 ) ) ( ( 2 , 2 ) , ( 2 , 3 ) ) . ((1,4),(2,4)) ((2,2),(2,3)). ((1,4),(2,4))((2,2),(2,3)).
-  解题思路 
 直接贪心填充,我们要竖着填充多骨诺牌,这样才能保证空间充分利用。
-  代码 
/**
* @filename:A.cbp
* @Author : pursuit
* @Blog:unique_pursuit
* @email: 2825841950@qq.com
* @Date : 2021-03-18-22.29.19
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int maxn=1e5+5;
const int mod=1e9+7;
int t,n,k1,k2;
int w,b;
void solve(){
    //简单的判断问题,k1,k2取最优。
    int minn=min(k1,k2);
    bool flag1=false,flag2=false;
    if(minn>=w){
        flag1=true;
    }
    else{
        w-=minn;
        if(w<=abs(k1-k2)/2){
            flag1=true;
        }
    }
    if(!flag1){
        cout<<"NO"<<endl;
        return;
    }
    minn=min(n-k1,n-k2);
    if(minn>=b){
        flag2=true;
    }
    else{
        b-=minn;
        if(b<=abs(n-k1-(n-k2))/2){
            flag2=true;
        }
    }
    if(flag2){
        cout<<"YES"<<endl;
    }
    else{
        cout<<"NO"<<endl;
    }
}
int main(){
    while(cin>>t){
        while(t--){
            cin>>n>>k1>>k2;
            cin>>w>>b;
            solve();
        }
    }
    return 0;
}


 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号