UVa 11129 - An antiarithmetic permutation
来源:互联网 发布:人工智能硬件 编辑:程序博客网 时间:2024/05/17 15:17
本来以为是比较简单的一个题,结果是理解错题意了,本以为题意是相邻的三个数不能为等差数列,结果WA了,看了其他人的代码才知道题目的意思是不相邻的只要是一个方向的也不能为等差数列。这样难度就比较大了,思考了半天也没想出什么好办法来,参考了他人的代码,基本思路是用递归将序列不断分为奇偶序列(按位置分),然后在合并,直到不能分为止,得到的便是没有等差子序列的排序。
代码如下:
#include<iostream>#include<cstdlib>#include<cstring>#include<cstdio>#include<cmath>#include<ctime>using namespace std;int a[10002], t[10002];void divide(int l, int r){ if(l + 1 >= r) return ; int i, j; for(i = l; i <= r; i++) t[i] = a[i]; for(i = l, j = l; j <= r; i++, j += 2) a[i] = t[j]; for(j = l + 1; j <= r; i++, j += 2) a[i] = t[j]; divide(l, (l + r) / 2); divide((l + r) / 2 + 1, r);}int main(){#ifdef test freopen("in.txt", "r", stdin);#endif int n; while(scanf("%d", &n), n) { printf("%d: ", n); for(int i = 0; i < n; i++) a[i] = i; divide(0, n - 1); for(int i = 0; i < n; i++) printf("%d%c", a[i], i == n - 1 ? '\n' : ' '); } return 0;}
- 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
- UVA - 11129 An antiarithmetic permutation
- uva 11129 An antiarithmetic permutation
- An antiarithmetic permutation UVA, 11129
- uva 11129An antiarithmetic permutation
- uva 11129 - An antiarithmetic permutation(递归)
- uva - 11129 - An antiarithmetic permutation(分治)
- 【分治】UVa 11129 An antiarithmetic permutation
- UVA-11129 - An antiarithmetic permutation (分治)
- uva--11129An antiarithmetic permutation+分治
- 明确where, group by以及having的关系,非常透彻。以及时间戳timestamp
- 硬盘低级格式化需谨记
- 世界各国货币名称
- MFC 对话框标题动态设置
- 嵌入式软件开发------------------Qt之QSettings类的常用函数
- UVa 11129 - An antiarithmetic permutation
- sed 变量替换
- SOA 基础知识
- oracle sql注入测试
- MySQL命令简单应用
- Java播放器
- Spring Security3.1 最新配置实例
- android/linux源码在线阅读地址汇总
- js 中 常用 frameset iframe 页面跳转 传参数值 方法示例大全