博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
CodeForces-124B Permutations
阅读量:4123 次
发布时间:2019-05-25

本文共 1064 字,大约阅读时间需要 3 分钟。

#include 
#include
#include
#include
using namespace std;const int nk_max = 8 + 5;const int INF = 0x3fffffff;int n, k;char number[nk_max][nk_max];int bit[nk_max], sum, num_max, num_min, ans;int main(){ while(~scanf("%d %d", & n, & k)) { for(int i = 0; i < n; i ++) scanf("%s", number[i]); for(int i = 0; i < k; i ++) bit[i] = i; ans = INF; do { num_max = 0, num_min = INF; for(int i = 0; i < n; i ++) { sum = 0; for(int j = 0; j < k; j ++) sum = sum * 10 + (number[i][bit[j]] - '0'); num_max = max(num_max, sum); num_min = min(num_min, sum); } ans = min(ans, num_max - num_min); }while(next_permutation(bit, bit + k)); printf("%d\n", ans); } return 0;}

输入n 和 k。之后输入n个长度为k的整数。每次都整列整列的变换位置。(比如第一列和第三列全部交换产生了n个新的数据)。问每次变化都产生最大值和最小值,问其差值的最小值是多少。

题解:

如果用next_permutation对位进行全排序的话,这道题也没什么难度的了..

转载地址:http://gctpi.baihongyu.com/

你可能感兴趣的文章
python数字逆序输出及多个print输出在同一行
查看>>
苏宁产品经理面经
查看>>
百度产品经理群面
查看>>
去哪儿一面+平安科技二面+hr面+贝贝一面+二面产品面经
查看>>
element ui 弹窗在IE11中关闭时闪现问题修复
查看>>
vue 遍历对象并动态绑定在下拉列表中
查看>>
Vue动态生成el-checkbox点击无法选中的解决方法
查看>>
python __future__
查看>>
MySQL Tricks1
查看>>
python 变量作用域问题(经典坑)
查看>>
pytorch
查看>>
pytorch(二)
查看>>
pytorch(三)
查看>>
pytorch(四)
查看>>
pytorch(5)
查看>>
ubuntu相关
查看>>
C++ 调用json
查看>>
nano中设置脚本开机自启动
查看>>
动态库调动态库
查看>>
Kubernetes集群搭建之CNI-Flanneld部署篇
查看>>