UVa 10730 Antiarithmetic? (想法题)
来源:互联网 发布:前线seo 编辑:程序博客网 时间:2024/06/05 18:37
10730 - Antiarithmetic?
Time limit: 3.000 seconds
http://uva.onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=1671
A permutation of n is a bijective function of the initial n natural numbers: 0, 1, ... n-1. A permutation p is called antiarithmetic if there is no subsequence of it forming an arithmetic progression of length bigger than 2, i.e. there are no three indices 0 ≤ i < j < k < n such that (pi , pj , pk) forms an arithmetic progression.
For example, the sequence (2, 0, 1, 4, 3) is an antiarithmetic permutation of 5. The sequence (0, 5, 4, 3, 1, 2) is not an antiarithmetic permutation as its first, fifth and sixth term (0, 1, 2) form an arithmetic progression; and so do its second, forth and fifth term (5, 3, 1).
Your task is to check whether a given permutation of n is antiarithmetic.
There are several test cases, followed by a line containing 0. Each test case is a line of the input file containing a natural number 3 ≤ n ≤ 10000 followed by a colon and then followed by n distinct numbers separated by whitespace. All n numbers are natural numbers smaller than n.
For each test case output one line with yes or no stating whether the permutation is antiarithmetic or not.
Sample input
3: 0 2 1 5: 2 0 1 3 46: 2 4 3 5 0 10
Output for sample input
yesnoyes
思路:
由于是全排列,我们可以先做下预处理,即标记每个数的位置。
然后对从公差j=1开始扫描序列,判断数字的相对位置即可。
复杂度:O(N^2)
完整代码:
/*0.019s*/#include<cstdio>int num[10010], n;inline bool check(){for (int i = 0; i < n; ++i)for (int j = 1; i + (j << 1) < n; ++j)if (num[i] < num[i + j] && num[i + j] < num[i + (j << 1)])return false;return true;}int main(void){int a;while (scanf("%d", &n), n){getchar();for (int i = 0; i < n; ++i){scanf("%d", &a);num[a] = i;}puts(check() ? "yes" : "no");}return 0;}
- UVa 10730 Antiarithmetic? (想法题)
- UVa 11129 An antiarithmetic permutation (构造题&想法题&分治)
- uva 10730 - Antiarithmetic?
- UVA 10730 - Antiarithmetic?
- uva 10730 - Antiarithmetic?
- UVA 10730 Antiarithmetic?
- uva 10730 - Antiarithmetic?(枚举)
- uva - 10730 - Antiarithmetic?(暴力枚举)
- UVA 10730 - Antiarithmetic?(技巧枚举)
- UVa 11129 - An antiarithmetic permutation
- UVa 11129 - An antiarithmetic permutation
- uva 11129 - An antiarithmetic permutation
- UVA 11129 - An antiarithmetic permutation
- UVA 11129 An antiarithmetic permutation
- uva 11129 - An antiarithmetic permutation
- uva 11129 An antiarithmetic permutation
- uva 11129 - An antiarithmetic permutation
- UVa 11129 - An antiarithmetic permutation
- UML 2.0 -- Class Diagram
- UVa 11129 An antiarithmetic permutation (构造题&想法题&分治)
- mysql中修改root密码
- 视频码流分析工具
- 【aabb 7744】
- UVa 10730 Antiarithmetic? (想法题)
- U盘分区,格式化及其相关
- 14. 排序数组中找和为n的两数
- POJ3468 线段树||伸展树
- 学习笔记-概率问题
- Linux系统服务 3 ---- FTP服务原理及vsftpd服务配置
- 解读C指针(4)——指针运算
- 研究了一下关于图片预览的方法
- 15. 转换二叉查找树