洛谷 UVA13130 题解

题目传送门


题意:

给定 \(T\) 个含有 \(5\) 个骰子状态的有序序列,判断序列是否为公差为 \(1\) 的等差数列,输出 \(Y\)\(N\)


思路:

由于骰子所有面上的数字只有 \(1∼6\),所以满足条件的等差数列只有两个,分别是:

  • \(1,2,3,4,5\)
  • \(2,3,4,5,6\)

由于给出的序列是有序的,所以我们只需要对每个序列进行判断即可。


code:

#include <bits/stdc++.h>
using namespace std;

int main(){
	int t;
	cin>>t;
	int c[10];
	while(t--){
		for(int i=0;i<5;i++)	cin>>c[i];
		if(c[0]==1&&c[1]==2&&c[2]==3&&c[3]==4&&c[4]==5)	cout<<"Y"<<endl;
		else if(c[0]==2&&c[1]==3&&c[2]==4&&c[3]==5&&c[4]==6)	cout<<"Y"<<endl;
		else	cout<<"N"<<endl; 
	} 
	return 0;
}


posted @ 2022-04-05 17:45  PandaBlack  阅读(76)  评论(0)    收藏  举报