贪心 CodeForces 124B Permutations
/*
贪心:全排列函数使用,更新最值
*/
#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的更多相关文章
- CodeForces 124B Permutations
http://codeforces.com/problemset/problem/124/B Description You are given nk-digit integers. You have ...
- 贪心 Codeforces Round #288 (Div. 2) B. Anton and currency you all know
题目传送门 /* 题意:从前面找一个数字和末尾数字调换使得变成偶数且为最大 贪心:考虑两种情况:1. 有偶数且比末尾数字大(flag标记):2. 有偶数但都比末尾数字小(x位置标记) 仿照别人写的,再 ...
- 贪心 Codeforces Round #301 (Div. 2) B. School Marks
题目传送门 /* 贪心:首先要注意,y是中位数的要求:先把其他的都设置为1,那么最多有(n-1)/2个比y小的,cnt记录比y小的个数 num1是输出的1的个数,numy是除此之外的数都为y,此时的n ...
- 线段树+dp+贪心 Codeforces Round #353 (Div. 2) E
http://codeforces.com/contest/675/problem/E 题目大意:有n个车站,每个车站只能买一张票,这张票能从i+1到a[i].定义p[i][j]为从i到j所需要买的最 ...
- 贪心 Codeforces Round #297 (Div. 2) C. Ilya and Sticks
题目传送门 /* 题意:给n个棍子,组成的矩形面积和最大,每根棍子可以-1 贪心:排序后,相邻的进行比较,若可以读入x[p++],然后两两相乘相加就可以了 */ #include <cstdio ...
- 贪心 Codeforces Round #304 (Div. 2) B. Soldier and Badges
题目传送门 /* 题意:问最少增加多少值使变成递增序列 贪心:排序后,每一个值改为前一个值+1,有可能a[i-1] = a[i] + 1,所以要 >= */ #include <cstdi ...
- 贪心 Codeforces Round #303 (Div. 2) B. Equidistant String
题目传送门 /* 题意:找到一个字符串p,使得它和s,t的不同的总个数相同 贪心:假设p与s相同,奇偶变换赋值,当是偶数,则有答案 */ #include <cstdio> #includ ...
- 找规律/贪心 Codeforces Round #310 (Div. 2) A. Case of the Zeros and Ones
题目传送门 /* 找规律/贪心:ans = n - 01匹配的总数,水 */ #include <cstdio> #include <iostream> #include &l ...
- 字符串处理/贪心 Codeforces Round #307 (Div. 2) B. ZgukistringZ
题目传送门 /* 题意:任意排列第一个字符串,使得有最多的不覆盖a/b字符串出现 字符串处理/贪心:暴力找到最大能不覆盖的a字符串,然后在b字符串中动态得出最优解 恶心死我了,我最初想输出最多的a,再 ...
随机推荐
- POJ-2240 -Arbitrage(Bellman)
题目链接:Arbitrage 让这题坑了,精度损失的厉害.用赋值的话.直接所有变成0.00了,无奈下,我仅仅好往里输了,和POJ1860一样找正环,代码也差点儿相同,略微改改就能够了,可是这个题精度损 ...
- 使用 maskView 设计动画
1.maskView(maskLayer) 基本原理 :可类比于多张png图片叠加遮罩 2.maskView配合CAGradientLayer,alpha通道图片的使用.maskView是iOS8以上 ...
- map集合排序
默认情况下,HashMap.HashTable.TreeMap.LinkedHashMap的排列顺序比较: package com.per.sdg.demo; import java.util.Has ...
- Windows下的Jupyter Notebook 的介绍(写给新手)(图文详解)
不多说,直接上干货! Windows下的Python 3.6.1的下载与安装(适合32bits和64bits)(图文详解) Windows下的Jupyter Notebook 安装与自定义启动(图文详 ...
- 10 逻辑完善以及bug修复
进行到这里,我们应用开发已经接近尾声,我这里基本就是应用开发的记录过程,讲解的东西很少,有问题可以在评论区讨论呦.下面进入最后调整的阶段. 预览我们的应用,会发现首页的职位列表,也会显示收藏的星星图标 ...
- android抓log
1.Logcat(能截取除了Kernel以外的所有Log信息),连接USB到电脑上,执行如下命令:User版本也可以使用adb logcat –v time >c:\ logcat.txtadb ...
- (八)unity4.6Ugui中文教程文档-------概要-UGUI Rich Text
大家好,我是孙广东. 转载请注明出处:http://write.blog.csdn.net/postedit/38922399 更全的内容请看我的游戏蛮牛地址:mod=guide&view ...
- R.layout引用不了布局文件
删除import android.R 引用包所在的R文件..
- centos7下tomcat7 或tomcat8启动超慢原因
1,找到你的jdk安装的位置 ${JAVA_HOME}/jre/lib/security/java.security 2,vi 打开后找到 securerandom.source=file:/dev/ ...
- javascript来实现详细时间提醒信息效果
我们经常在社交网络上面看到很人性化的时间提示比如,你的朋友几分钟前更新了什么,你的朋友几天前更新了什么信息. 这些小tips比直接显示某年某月人性化很多.我们可以用不同的程序实现这种效果.中国音效网下 ...