题目传送门

 /*
这题交给队友做,做了一个多小时,全排列,RE数组越界,赛后发现读题读错了,囧!
贪心:先确定最高位的数字,然后用贪心的方法,越高位数字越大 注意:1. Both A and B will have same number of digits 两个数字位数相同
2. which is no larger than 10^6 不是大小,而是长度不超过1e6
*/
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
using namespace std; const int MAXN = 1e6 + ;
const int INF = 0x3f3f3f3f;
char s1[MAXN], s2[MAXN]; int main(void) //HDOJ 4726 Kia's Calculation
{
//freopen ("K.in", "r", stdin); int t, cas = ;
int cnt1[], cnt2[], cnt3[]; scanf ("%d", &t);
while (t--)
{
scanf ("%s", &s1);
scanf ("%s", &s2); printf ("Case #%d: ", ++cas); int len = strlen (s1);
if (strcmp (s1, "") == )
{
printf ("%s\n", s2); continue;
}
else if (strcmp (s2, "") == )
{
printf ("%s\n", s1); continue;
} memset (cnt1, , sizeof (cnt1));
memset (cnt2, , sizeof (cnt2));
memset (cnt3, , sizeof (cnt3)); for (int i=; i<len; ++i)
{
cnt1[s1[i]-'']++; cnt2[s2[i]-'']++;
} int ii = , jj = , mx = -;
for (int i=; i<=; ++i)
{
if (cnt1[i] == ) continue;
for (int j=; j<=; ++j)
{
if (cnt2[j] == ) continue;
int tmp = (i + j) % ;
if (tmp > mx)
{
mx = tmp; ii = i; jj = j;
}
}
}
cnt1[ii]--; cnt2[jj]--;
if (!mx)
{
puts (""); continue;
} for (int i=; i>=; --i)
{
for (int j=; j<=; ++j)
{
for (int k=; k<=; ++k)
{
if ((j+k)%==i && cnt1[j] && cnt2[k])
{
int tmp = min (cnt1[j], cnt2[k]);
cnt1[j] -= tmp; cnt2[k] -= tmp;
cnt3[i] += tmp;
}
}
}
} printf ("%d", mx);
for (int i=; i>=; --i)
{
for (int j=; j<cnt3[i]; ++j) printf ("%d", i);
}
puts ("");
} return ;
}

贪心 HDOJ 4726 Kia's Calculation的更多相关文章

  1. HDU 4726 Kia's Calculation (贪心算法)

    Kia's Calculation Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...

  2. HDU 4726 Kia's Calculation(贪心)

    Kia's Calculation Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

  3. ACM学习历程—HDU 4726 Kia's Calculation( 贪心&&计数排序)

    DescriptionDoctor Ghee is teaching Kia how to calculate the sum of two integers. But Kia is so carel ...

  4. HDU 4726 Kia's Calculation(贪心构造)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4726 题意:给出两个n位的数字,均无前缀0.重新排列两个数字中的各个数,重新排列后也无前缀0.得到的两 ...

  5. hdu 4726 Kia's Calculation

    思路:刚开始想复杂了. 看解题报告后才知道这题挺简单的,看来还是要多训练啊!!! 单独处理首位的数字,不能为0.其他的就好处理了,从大到小依次找下去就可以了…… 代码如下: #include<i ...

  6. K - Kia's Calculation(贪心)

    Kia's Calculation Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

  7. K - Kia's Calculation (贪心)

    Kia's Calculation Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

  8. Kia's Calculation hdu4726

    Kia's Calculation Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

  9. HDU-4726 Kia's Calculation 贪心

    题目链接:http://acm.hdu.edu.cn/userstatus.php?user=zhsl 题意:给两个大数,他们之间的加法法则每位相加不进位.现在可以对两个大数的每位重新排序,但是首位不 ...

随机推荐

  1. Q1微信用户增长11% 微信生态圈逐渐完善

    就在今天早些时候,腾讯公布了Q1财报,微信和手Q游戏收入达18亿元,微信用户环比增长11%,微信生态圈逐渐完善.和xmyanke一起来看看具体的财报数字分析. 微信和手Q游戏付费用户环比增长100%以 ...

  2. zhx's contest (矩阵快速幂 + 数学推论)

    zhx's contest Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) To ...

  3. iOS开发——底层OC篇&运行时常用

    运行时常用 什么是Runtime(前面的文章已经说的很清楚了,这里就简单的介绍一下) 我们写的代码在程序运行过程中都会被转化成runtime的C代码执行,例如[target doSomething]; ...

  4. [Effective JavaScript 笔记]第44条:使用null原型以防止原型污染

    第43条中讲到的就算是用了Object的直接实例,也无法完全避免,Object.prototype对象修改,造成的原型污染.防止原型污染最简单的方式之一就是不使用原型.在ES5之前,并没有标准的方式创 ...

  5. js中document.documentElement 和document.body 以及其属性 clientWidth等

    在设计页面时可能经常会用到固定层的位置,这就需要获取一些html对象的坐标以更灵活的设置目标层的坐标,这里可能就会用到document .body.scrollTop等属性,但是此属性在xhtml标准 ...

  6. 【leetcode】Sort List

    Sort List Sort a linked list in O(n log n) time using constant space complexity.   需要采用归并排序对链表进行操作. ...

  7. maven项目 Java compiler level does not match the version of the installed Java project facet

    因工作的关系,Eclipse开发的Java项目拷来拷去,有时候会报一个很奇怪的错误.明明源码一模一样,为什么项目复制到另一台机器上,就会报“java compiler level does not m ...

  8. Extjs的数据读取器store和后台返回类型简单解析

    工作中用到了Extjs,从后台获取数据的时候,用到了extjs自己的Ext.data.store方法,然后封装了ExtGridReturn方法, 目的:前台用到Ext.data.store读取从后台传 ...

  9. NEFU 2016省赛演练一 I题 (模拟题)

    这题没名字 Problem:I Time Limit:2000ms Memory Limit:65535K Description Now give you an interger m and a s ...

  10. @RequestBody, @ResponseBody 注解详解

    简介: @RequestBody 作用: i) 该注解用于读取Request请求的body部分数据,使用系统默认配置的HttpMessageConverter进行解析,然后把相应的数据绑定到要返回的对 ...