题目传送门

 /*
这题交给队友做,做了一个多小时,全排列,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. 关闭火车头dedecms发布模块自动关键词,解决火车头发布dedecms文章关键词过多问题

    用火车头发布dedecms文章时,经常会自动添加关键词,这些关键词默认有10个,数量过多,而且是随机提取的,乱七八糟的词都进去了,如下图所示: 这些关键词可能会成为se判断你作弊的依据,现在se也弱化 ...

  2. editplus快捷键大全之editplus文件快捷键

    editplus快捷键大全之editplus文件快捷键 新建普通文本 Ctrl+N 新建普通的文本文档 新建浏览器窗口 Ctrl+Shift+B 新建浏览器窗口 新建 HTML 页 Ctrl+Shif ...

  3. hdu 5183. Negative and Positive (哈希表)

    Negative and Positive (NP) Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 65536/65536 K (Ja ...

  4. 淘宝(阿里百川)手机客户端开发日记第六篇 Service详解(六)

    Service和Thread的关系 不少初学者都可能会有这样的疑惑,Service和Thread到底有什么关系呢?什么时候应该用Service,什么时候又应该用Thread? 答案是Service和T ...

  5. TCP协议漏洞影响大量Linux设备

    导读 本周三在得州奥斯丁举行的 USENIX 安全研讨会上,加州大学河滨分校研究生 Yue Cao 将报告一个严重的TCP协议边信道漏洞(PDF),该漏洞允许攻击者远程劫持任意两主机之间的会话.该漏洞 ...

  6. sizeof()和strlen()的区别与联系

    参考:http://www.cnblogs.com/carekee/articles/1630789.html 1.sizeof是运算符,其值在编译时即计算好了,参数可以是数组.指针.类型.对象.函数 ...

  7. PHP声明

    1. <!DOCTYPE> 声明位于文档中的最前面的位置,处于 <html> 标签之前.2. 此标签可告知浏览器文档使用哪种 HTML 或 XHTML 规范. <!DOC ...

  8. Python的getattr()

    Python的getattr(),setattr(),delattr(),hasattr() getattr()函数是Python自省的核心函数,具体使用大体如下: 获取对象引用getattrGeta ...

  9. django inclusion_tag

    一种比较普遍的tag类型是只是渲染其它模块显示下内容,这样的类型叫做Inclusion Tag. 例如,实现以下tag: {% books_for_author author %} 渲染结果为: &l ...

  10. java 实现二分查找法

    /** * 二分查找又称折半查找,它是一种效率较高的查找方法. [二分查找要求]:1.必须采用顺序存储结构 2.必须按关键字大小有序排列. * @author Administrator * */ p ...