1004 -- “顺”序列
来源:互联网 发布:懒角落 淘宝 编辑:程序博客网 时间:2024/04/28 19:54
“顺”序列
Time Limit:1000MS Memory Limit:32768K
Total Submit:331 Accepted:150
Description
贝贝5岁了。她从一堆数字卡片中选出了4张卡片:5、7、6、8。她摆布了一阵这些卡片后,发现它们可以排成比较顺的序列:5、6、7、8。她同样拿了另4张卡片:5、7、1、2,可是怎么也排不成“顺”的序列。原来,贝贝的所谓“顺”序列是我们所知道的等差数列!贝贝一边拿起一堆数字卡片,一边就在摆布它们,尝试着让它们“顺”起来,可总是有些“顺”,有些不“顺”。这个问题得靠你给她帮忙了,设计一个程序,能够判断对于给定的一堆数字,能“顺”还是不能“顺”。
Input
输入中第一行为一个整数n(1≤n≤10),描述后面一共有n组卡片,每组卡片的第一个数m(1≤m≤100),表示后面会出现m张卡片。
Output
针对每组卡片,判断是否能构成“顺”序列。如果能构成“顺”序列,则输出“yes”,否则就输出“no”。每个结果应分别不同行显示。
Sample Input
34 5 7 6 88 1 7 3 2 8 12 78 32 1 2
Sample Output
yesnoyes
Source
ahstu@ICPC03
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace AK1004 { class Program { static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); while (n-- > 0) { string[] sb = Console.ReadLine().Split(); int m = int.Parse(sb[0]); int[] a = new int[105]; for (int i = 1; i <= m; i++) a[i] = int.Parse(sb[i]); Array.Sort(a, 1, m); int d = a[2] - a[1]; bool flag = true; for (int i = 3; i <= m; i++) if (a[i] - a[i - 1] != d) { flag = false; Console.WriteLine("no"); break; } if (flag) Console.WriteLine("yes"); } } } }
0 0
- 1004 -- “顺”序列
- 【AKOJ】1004-“顺”序列
- 1178: “顺”序列
- 1178: “顺”序列
- 序列
- 序列
- 序列
- 序列
- 序列
- 序列
- 序列
- 序列
- 序列
- 序列
- 序列
- 序列
- 序列
- 序列
- 1002 -- 手机靓号
- Hello World Using Struts 2
- 1003 -- 计算N!
- LeetCode Palindrome Linked List
- 2、iOS 开发之字典转模型和 xib
- 1004 -- “顺”序列
- 1005 -- 构造表达式
- 1006 -- 5个数求最值
- 3、iOS 开发之 UIScrollView UIPageController NSTimer
- 1007 -- Fibonacci 数
- 1008 -- 大小写互换
- 1009 -- 公约数和公倍数
- Binary Tree Paths
- 1010 -- 青蛙的约会