HDUOJ---------Kia's Calculation
Kia's Calculation
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 624 Accepted Submission(s): 178
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#define maxn 1000000 //1e6
using namespace std;
char a[maxn+5],b[maxn+5],c[maxn+5];
void cal(int *str,char *a,int len)
{
for(int i=0;i<len;i++)
{
str[a[i]-'0']++;
}
}
int main()
{
int t,i,j,count=1,max,posi,posj,len1,k;
//freopen("test.in","r",stdin);
//freopen("test.out","w",stdout);
scanf("%d",&t);
while(t--)
{
int A[10]={0},B[10]={0},flag=0;
memset(a,'\0',sizeof a);
memset(b,'\0',sizeof b);
memset(c,'\0',sizeof c);
scanf("%s%s",a,b);
len1=strlen(a);
cal(A,a,len1);
cal(B,b,len1);
printf("Case #%d: ",count++);
for(k=1;k<=len1;k++)
{
max=-1;
for(i=9;i>=0;i--)
{
if(k==1&&i==0&&len1!=1) continue;
if(A[i])
{
for(j=9;j>=0;j--)
{
if(k==1&&j==0&&len1!=1) continue;
if(B[j])
{
int temp=(i+j)%10;
if(max<temp)
{
max=temp;
posi=i;
posj=j;
}
}
if(max==9)break;
}
}
if(max==9)break;
}
A[posi]--;
B[posj]--;
c[flag++]=max+'0';
}
if(flag>1)
{
if(c[0]>'0')
printf("%c",c[0]);
for(i=1;i<flag;i++)
{
printf("%c",c[i]);
if(c[0]<='0'&&c[i]=='0') break;
}
puts("");
}
else
printf("%c\n",c[0]);
}
return 0;
}
HDUOJ---------Kia's Calculation的更多相关文章
- 贪心 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 ...
- Kia's Calculation hdu4726
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(贪心)
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 ...
- 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 ...
- hdu 4726 Kia's Calculation
思路:刚开始想复杂了. 看解题报告后才知道这题挺简单的,看来还是要多训练啊!!! 单独处理首位的数字,不能为0.其他的就好处理了,从大到小依次找下去就可以了…… 代码如下: #include<i ...
- HDU 4726 Kia's Calculation(贪心构造)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4726 题意:给出两个n位的数字,均无前缀0.重新排列两个数字中的各个数,重新排列后也无前缀0.得到的两 ...
随机推荐
- Vmware esx/esxi Vlan三种配置模式(VST、EST和VGT)
在Vmware esx/esxi中使用虚拟Lan(Vlan)时,一般是指Vlan Trunk的使用,使用的Vlan配置还有其它三种类型: Virtual Switch Tagging(虚拟交换机标记, ...
- E470 外放没声音问题解决
到官网下载声卡驱动.和热键驱动,安装就ok了
- Ceph rgws客户端验证
修改/etc/ceph/ceph.conf文件,加入rados gw监听的端口 [client.rgw.rgws] rgw_frontends = "civetweb port=80&quo ...
- Kmeans算法原理极其opencv实现(转帖)
原帖地址:http://blog.csdn.net/qll125596718/article/details/8243404 1.基本Kmeans算法[1] 选择K个点作为初始质心 repeat ...
- 数学图形之Breather surface
这是一种挺漂亮的曲面图形,可惜没有找到太多的相关解释. In differential equations, a breather surface is a mathematical surface ...
- insert-delete-getrandom-o1-duplicates-allowed
https://leetcode.com/problems/insert-delete-getrandom-o1-duplicates-allowed/ public class Randomized ...
- Android Studio体验(二)--创建项目和Genymotion试用
上周日已经体验了一把Android Studio顺便没事点了点其他功能,不过还是从自己创建项目开始说吧,首先我们要熟悉Android Studio中的Project 和 Module 两个概念.And ...
- eclipse maven 报错Could not get the value for parameter encoding for plugin execution default
问题描述:更改默认的maven仓库路径完成后.即存maven项目或者新建maven项目的时候出现如下错误 Could not get the value for parameter encoding ...
- 拍案惊奇!9款神奇的jQuery/CSS3经典插件
款非常给力的jQuery/CSS3经典插件,插件包括CSS3图片特效.jQuery动画菜单.jQuery时尚登录表单等,一起来看看这些jQuery插件. .CSS3图片重力感应特效 这是一款应用重力感 ...
- CI框架入门中的简单MVC样例
最简单的CI模型: 注意:模型须要用到数据库 配置文件在appcation/config.php 这里我们要用到数据库,须要将databases.php中的 相关參数填写一下,详细不再赘述. 直接进入 ...