next_permutation测试
来源:互联网 发布:绿色破解软件 编辑:程序博客网 时间:2024/06/16 23:44
今天做poj 2718 wa的一血 2718的一些坑
1 中间二分判断 中间a[mid]肯定不能为零 为零位数都不会一样(逃qaq)
2 a[0]也不能为零
不会排列的下看
#include<cstdio>#include<algorithm> //包含next_permutationusing namespace std;int main( ) {int n, p[10];scanf("%d", &n);for(int i = 0; i < n; i++) scanf("%d", &p[i]);sort(p, p+n); //排序,得到p的最小排列do { if(p[0]!=0){for(int i = 0; i < n; i++) printf("%d ", p[i]);} //输出排列pprintf("\n");} while(next_permutation(p, p+n)); //求下一个排列return 0;}
此时输入的三个数全排列都是开始非零
还可以直接加条件
do { if(a[mid]&& a[0]) { int x=a[0],y=a[mid]; for(int i=1;i<mid;i++) x=x*10+a[i]; for(int i=mid+1;i<n;i++) y=y*10+a[i]; if(ans>abs(x-y)) ans=abs(x-y); } }while(next_permutation(a,a+n)); cout<<ans<<endl;
还要注意一下这个
while((c=getchar())!='\n') { if(c!=' '){ a[n]=c-'0'; n+=1;
阅读全文
0 0
- next_permutation测试
- next_permutation
- next_permutation
- next_permutation
- next_permutation
- next_permutation
- next_permutation
- next_permutation
- next_permutation
- next_permutation
- next_permutation
- next_permutation
- next_permutation
- next_permutation
- next_permutation
- next_permutation
- next_permutation
- next_permutation
- 数组a[i++]是等于a[i]还是a[i+1]?
- ELK+Filebeat的安装和联调
- StarGAN-多领域图像翻译
- 两个div并排的方法
- record
- next_permutation测试
- jUnit EclEmma 白盒测试
- 如何成为高效率的程序员
- POJ 1125(用floyd算法的 + 贪心)
- 4.java的api测试
- 《机器学习实战》学习笔记——K-近邻算法(KNN)(二)海伦约会网站匹配实战
- SSH(spring、struts2、hibernate)三大框架整合
- Ubuntu 14.04 安装 chkconfig 服务管理程序
- LeetCode746. Min Cost Climbing Stairs