题目传送门

 /*
贪心:全排列函数使用,更新最值
*/
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <iostream>
#include <queue>
using namespace std; typedef long long ll;
const int MAXN = ;
const int INF = 0x3f3f3f3f;
int b[MAXN];
char a[MAXN][MAXN]; int main(void) //CodeForces 124B Permutations
{
// freopen ("A.in", "r", stdin); int n, k;
while (scanf ("%d%d", &n, &k) == )
{
for (int i=; i<=n; ++i)
{
scanf ("%s", a[i] + );
}
for (int i=; i<=k; ++i) b[i] = i; ll ans = INF;
do
{
ll mx = , mn = INF; ll sum = ;
for (int i=; i<=n; ++i)
{
sum = ;
for (int j=; j<=k; ++j)
{
sum = sum * + (a[i][b[j]] - '');
}
if (sum > mx) mx = sum;
if (sum < mn) mn = sum;
}
ans = min (ans, mx - mn);
}while (next_permutation (b+, b++k)); printf ("%I64d\n", ans);
} return ;
}

贪心 CodeForces 124B Permutations的更多相关文章

  1. CodeForces 124B Permutations

    http://codeforces.com/problemset/problem/124/B Description You are given nk-digit integers. You have ...

  2. 贪心 Codeforces Round #288 (Div. 2) B. Anton and currency you all know

    题目传送门 /* 题意:从前面找一个数字和末尾数字调换使得变成偶数且为最大 贪心:考虑两种情况:1. 有偶数且比末尾数字大(flag标记):2. 有偶数但都比末尾数字小(x位置标记) 仿照别人写的,再 ...

  3. 贪心 Codeforces Round #301 (Div. 2) B. School Marks

    题目传送门 /* 贪心:首先要注意,y是中位数的要求:先把其他的都设置为1,那么最多有(n-1)/2个比y小的,cnt记录比y小的个数 num1是输出的1的个数,numy是除此之外的数都为y,此时的n ...

  4. 线段树+dp+贪心 Codeforces Round #353 (Div. 2) E

    http://codeforces.com/contest/675/problem/E 题目大意:有n个车站,每个车站只能买一张票,这张票能从i+1到a[i].定义p[i][j]为从i到j所需要买的最 ...

  5. 贪心 Codeforces Round #297 (Div. 2) C. Ilya and Sticks

    题目传送门 /* 题意:给n个棍子,组成的矩形面积和最大,每根棍子可以-1 贪心:排序后,相邻的进行比较,若可以读入x[p++],然后两两相乘相加就可以了 */ #include <cstdio ...

  6. 贪心 Codeforces Round #304 (Div. 2) B. Soldier and Badges

    题目传送门 /* 题意:问最少增加多少值使变成递增序列 贪心:排序后,每一个值改为前一个值+1,有可能a[i-1] = a[i] + 1,所以要 >= */ #include <cstdi ...

  7. 贪心 Codeforces Round #303 (Div. 2) B. Equidistant String

    题目传送门 /* 题意:找到一个字符串p,使得它和s,t的不同的总个数相同 贪心:假设p与s相同,奇偶变换赋值,当是偶数,则有答案 */ #include <cstdio> #includ ...

  8. 找规律/贪心 Codeforces Round #310 (Div. 2) A. Case of the Zeros and Ones

    题目传送门 /* 找规律/贪心:ans = n - 01匹配的总数,水 */ #include <cstdio> #include <iostream> #include &l ...

  9. 字符串处理/贪心 Codeforces Round #307 (Div. 2) B. ZgukistringZ

    题目传送门 /* 题意:任意排列第一个字符串,使得有最多的不覆盖a/b字符串出现 字符串处理/贪心:暴力找到最大能不覆盖的a字符串,然后在b字符串中动态得出最优解 恶心死我了,我最初想输出最多的a,再 ...

随机推荐

  1. Desert King (poj 2728 最优比率生成树 0-1分数规划)

    Language: Default Desert King Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 22113   A ...

  2. Shell 脚本小试牛刀(5) -- 超便捷脚本之高速ssh 登录其它主机

    假设你也是以Linux 为工作环境的童鞋,那么此文真是捷报!由于我的学习/工作中(特别是近期玩耍树莓派)常常会使用到ssh 登录其它主机,而每次使用ssh 登录都须要输入老长一大串让我非常烦.所以我写 ...

  3. VC++ error C1083 无法打开包括文件 fstream.h,iostream.h怎么办

    1 如下图所示,VS中不支持iostream.h和fstream.h的说法   2 改成下面三行就可以编译通过了 #include<iostream> #include <fstre ...

  4. 在XX公司工作第二天,维护已有代码

    根据<C++ More Exception>所述的规则: Rule #1: Never write using-directives in header files. Rule #2: N ...

  5. fedora下安装xdot和objgraph

    前提:安装好了python 1.先下载xdot-0.6.tar.gz和objgraph-1.8.0-py27-none-any.whl,你也可以在官网上下载其他版本. 2.下载完后,解压. 3.打开终 ...

  6. 浅谈 ZipArchive 类

    Microsoft .NET Framework 4.5 新增了 ZipArchive 类 Microsoft Windows 8 Consumer Preview 操作系统已经内置了 Microso ...

  7. Chapter1-data access reloaded:Entity Framework(下)

    1.4 Delving deep into object/relational differences 深入挖掘对象关系的不同 理解面向对象和关系世界的不同是重要的,因为他会影响你设计一个对象模型或者 ...

  8. 自己写的Android端HttpUtil工具类

    package com.sxt.jcjd.util; import java.io.IOException; import java.io.UnsupportedEncodingException; ...

  9. Linux 对比 Windows 缺点

      SELinux_百度百科 https://baike.baidu.com/item/SELinux/8865268?fr=aladdin   虽然Linux比起 Windows来说,它的可靠性,稳 ...

  10. 创建javaScript 对象

    创建新实例person 并向其添加四个属性: person=new Object(); person.firstname="Bill"; person.lastname=" ...