标签:Educational Rated cout int 棋盘 Codeforces cin 棋子 include
题目名称: 棋盘
题干:
有一个n行n列的棋盘,初始情况下棋盘上无棋子,你可以在棋盘任意位置摆放棋子。
4个整数数U R D L,问该棋盘是否可以满足一下所有条件:
1.最上面一行恰好有U枚棋子
2.最右边一列恰好有R枚棋子
3.最下面一行恰好有D枚棋子
4.最左边一列恰好有L枚棋子
输入:
多组输入
一组为5个数 n U R D L
输出:
YSE or NO
INPUT
5 2 5 3 1
3 0 0 0 0
4 4 1 4 0
2 1 1 1 1
OUTPUT
YES
YES
NO
YES
提示:以下为样例1 2 4满足条件的可能情况
ac代码:
#include<iostream>
#include<algorithm>
#include<iomanip>
#include<set>
#include<queue>
#include<stack>
#include<vector>
#include<map>
#include<string.h>
#include<string>
#include<math.h>
#define IOS; ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define VNAME(value) (#value)
#define debug(x) {cout<<VNAME(x)<<"="<<(x)<<endl;}
using namespace std;
const int N = 1e5+5;
const int inf=0x3f3f3f3f;
typedef long long ll;
int a[5];
int main() {
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
IOS;
int t;cin>>t;
while(t--)
{
int flag=0;
int n;
cin>>n;
int a,b,c,d;
cin>>a>>b>>c>>d;
for(int i=0;i<=1;i++)
for(int j=0;j<=1;j++)
for(int k=0;k<=1;k++)
for(int z=0;z<=1;z++)
if(a-i-j<=n-2&&a-i-j>=0
&&b-j-k<=n-2&&b-j-k>=0
&&c-k-z<=n-2&&c-k-z>=0
&&d-i-z<=n-2&&d-i-z>=0)
flag=1;
if(flag)cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
return 0;
}
标签:Educational,Rated,cout,int,棋盘,Codeforces,cin,棋子,include 来源: https://blog.csdn.net/weixin_45756956/article/details/114377624
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。