Kia's Calculation hdu4726
Kia's Calculation
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1367 Accepted Submission(s): 327
Now Kia has two integers A and B, she can shuffle the digits in each number as she like, but leading zeros are not allowed. That is to say, for A = 11024, she can rearrange the number as 10124, or 41102, or many other, but 02411 is not allowed.
After she shuffles A and B, she will add them together, in her own way. And what will be the maximum possible sum of A "+" B ?
For each test case there are two lines. First line has the number A, and the second line has the number B.
Both A and B will have same number of digits, which is no larger than 106, and without leading zeros.
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <math.h>
#include <algorithm>
using namespace std;
int a[],b[];
int fun()
{
int i,j,k;
for(k=; k>=; k--)
{
for(i=; i>=; i--)
{
for(j=; j>=; j--)
{
if(a[i]&&b[j]&&(i+j)%==k)
{
a[i]--,b[j]--;
printf("%d",k);
return k;
}
}
}
}
}
int main()
{
int t,i,j,k,r;
char x;
scanf("%d",&t);
getchar();
for(r=; r<=t; r++)
{
memset(a,,sizeof(a));
memset(b,,sizeof(b));
while(x=getchar())
{
if(x=='\n')break;
a[x-'']++;
}
while(x=getchar())
{
if(x=='\n')break;
b[x-'']++;
}
printf("Case #%d: ",r);
if(fun())
for(k=; k>=; k--)
{
for(i=; i>=; i--)
{
for(j=; j>=; j--)
{
while(a[i]&&b[j]&&(i+j)%==k)
{
a[i]--,b[j]--;
printf("%d",k);
}
}
}
}
puts("");
}
}
Kia's Calculation hdu4726的更多相关文章
- 贪心 HDOJ 4726 Kia's Calculation
题目传送门 /* 这题交给队友做,做了一个多小时,全排列,RE数组越界,赛后发现读题读错了,囧! 贪心:先确定最高位的数字,然后用贪心的方法,越高位数字越大 注意:1. Both A and B wi ...
- HDU 4726 Kia's Calculation (贪心算法)
Kia's Calculation Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...
- K - Kia's Calculation (贪心)
Kia's Calculation Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- HDU 4726 Kia's Calculation(贪心)
Kia's Calculation Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- K - Kia's Calculation(贪心)
Kia's Calculation Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- HDU-4726 Kia's Calculation 贪心
题目链接:http://acm.hdu.edu.cn/userstatus.php?user=zhsl 题意:给两个大数,他们之间的加法法则每位相加不进位.现在可以对两个大数的每位重新排序,但是首位不 ...
- HDU4726——Kia's Calculation——2013 ACM/ICPC Asia Regional Online —— Warmup2
题目的意思是给你两个数字(多达10^6位) 做加法,但是有一点,没有进位(进位不算,相当于这一位相加后对10取模) 你可以任意排列两个数字中的每一位,但是不能是0开头. 现在题目要求以这种不进位的算法 ...
- Kia's Calculation(HDU 4267)
Problem Description Doctor Ghee is teaching Kia how to calculate the sum of two integers. But Kia is ...
- ACM学习历程—HDU 4726 Kia's Calculation( 贪心&&计数排序)
DescriptionDoctor Ghee is teaching Kia how to calculate the sum of two integers. But Kia is so carel ...
随机推荐
- Android持续集成之Jenkins 部署
Android持续集成之Jenkins 部署 [TOC] 0x00安装 准备工作如下: Tomcat8.5下载地址 Jenkins下载链接 1 将下载的jenkins.war包放至tomcat下的we ...
- Bootstrap-table事件使用
HTML <div class="alert alert-danger" id="eventInfo"></div> <table ...
- SVG坐标系统及图形变换
前面的话 前面介绍过SVG视野后,本文将开始介绍SVG坐标系统及图形变换 坐标定位 对于所有元素,SVG使用的坐标系统或者说网格系统,和Canvas用的差不多(所有计算机绘图都差不多).这种坐标系统是 ...
- java中的jdk切换(无需卸载原有jdk)
该转自 : http://blog.csdn.net/u010011371/article/details/50749954 很好的一片文章,适合我这种小白,方便以后使用. 之前一直使用的是JDK1 ...
- 猜数字游戏--基于python
"""题目:练习使用python写一个猜数字的游戏,数字范围0-100,每次猜错,需要给出缩小后的范围,每个人只有10次的猜测机会,猜测机会用完游戏结束!"&q ...
- 如何将ASP.NET-WebApi发布到IIS6.0上(转)
关于"如何将ASP.NET-WebApi发布到IIS6.0上"的这方面的学习,一开始项目组长让我们接触的时候,我的心情是这样的 哇呜.jpg 当时真的是一脸懵逼啊,对于刚接触asp ...
- Liunx-常用命令的总结(5)
cd ../dir 上一节目录下dir目录 cd - 返回上次目录 ifconfig 查看IP地址 sudo if ...
- NHibernate教程(11)--多对多关联查询
本节内容 多对多关系引入 多对多映射关系 多对多关联查询 1.原生SQL关联查询 2.HQL关联查询 3.Criteria API关联查询 结语 多对多关系引入 让我们再次回顾在第二篇中建立的数据模型 ...
- 【深入Java虚拟机】之一:Java内存区域与内存溢出
转载请注明出处:http://blog.csdn.net/ns_code/article/details/17565503 内存区域 Java虚拟机在执行Java程序的过程中会把他所管理的内存划分为若 ...
- 【集美大学1411_助教博客】团队作业1——团队展示&选题 成绩
第一次团队作业已经新鲜出炉啦,各位同学请查收.截止日期前,全班都按时提交了作业,而且有的团队还提交了两次呢,下次不要这样啦~ 题目 团队作业1--团队展示&选题 回顾 个人作业1--四则运算题 ...