题目链接:http://codeforces.com/problemset/problem/910/C
题目大意:将a~j分别赋值0~9,然后计算表达式的最小值
一道普通的模拟题,思路在于将a~j的权重计算清楚,然后排序分配0~9,同时注意一下前导零的问题。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
| #include<cstring> #include<cstdio> #include<map> #include<algorithm> using namespace std; char dic[1000][10]; int cnt_appear[15][10]; struct node { int index; int rate; }; int f(int x) { int res = 1; for(int i = 1; i <= x; i ++) { res *=10; } return res; } map<char,int>mymap; bool cmp(node n1, node n2) { return n1.rate > n2.rate; } node rating[15]; bool can_not_zero[15]; int main() { for(int i = 1; i <= 10; i ++) { rating[i].index = i; } int n; scanf("%d", &n); for(int i = 1; i <= n; i ++) { scanf("%s", dic[i]); can_not_zero[dic[i][0] - 'a' + 1] = 1; int temp_len = strlen(dic[i]); for(int j = 0; j < temp_len; j ++) { rating[dic[i][j] - 'a' + 1].rate += f(temp_len - j); } } sort(rating + 1,rating + 11, cmp); int flag = 0; int rk = 1; for(int i = 1; i <= 10; i ++) { if(flag == 0) { if(can_not_zero[rating[i].index] == 1) { char c = rating[i].index + 'a' - 1; mymap[c] = rk; rk++; } else { char c = rating[i].index + 'a' - 1; mymap[c] = 0; flag = 1; } } else if(flag == 1) { char c = rating[i].index + 'a' - 1; mymap[c] = rk; rk++; } } long long sum = 0; for(int i = 1; i <= n; i ++) { long long temp_sum = 0; for(int j = 0; j < strlen(dic[i]); j ++) { temp_sum = temp_sum * 10 + mymap[dic[i][j]]; } sum+=temp_sum; } printf("%lld\n",sum); return 0; }
|