http://codeforces.com/contest/118/problem/C
题意:给n长度的串,要求通过一系列替换操作,至少要有k个数字相同。
替换的代价为原数字到新数字的绝对值
那么我们直接枚举替换为0-9的方案,每次算出每个数字替换为i 的代价,
然后按代价从小到大排序,代价相同的 按 【改变了该数字为i 字典序会变大还是变小排序】(主要这里写好了就OK了)
最后选择一个总代价最小的输出,如果有多个,选字典序最小的输出。
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <iostream>
using namespace std;
const double pi=acos(-1.0);
double eps=0.000001;
int tm[10005];
struct node
{
int x,id;
int val;
};
node ss[10005];
int cur=-1;
bool cmp(node a,node b)
{
if (a.val!=b.val) //优先按代价排序
return a.val<b.val;
if (a.id<b.id) //代价相同时,看位置,优先考虑前面的
{
if ( a.x>cur) //如果原