hdu 4726 Kia's Calculation
思路:刚开始想复杂了。
看解题报告后才知道这题挺简单的,看来还是要多训练啊!!!
单独处理首位的数字,不能为0.其他的就好处理了,从大到小依次找下去就可以了……
代码如下:
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<vector>
#define ll __int64
#define pi acos(-1.0)
#define MAX 1000005
using namespace std;
char a[MAX],b[MAX];
int c[],d[];
int first()
{
int i,j;
for(i=;i>=;i--){
for(j=;j<=;j++){
if(i-j>&&c[j]&&d[i-j]){
c[j]--;
d[i-j]--;
break;
}
if(+i-j<=&&c[j]&&d[+i-j]){
c[j]--;
d[+i-j]--;
break;
}
}
if(j<=) break;
}
return i;
}
int solve(int x)
{
int t,ans=;
for(int i=;i<=;i++){
if(x-i>=&&c[i]&&d[x-i]){
t=min(c[i],d[x-i]);
c[i]-=t;
d[x-i]-=t;
ans+=t;
}
if(+x-i<=&&c[i]&&d[+x-i]){
t=min(c[i],d[+x-i]);
c[i]-=t;
d[+x-i]-=t;
ans+=t;
}
}
return ans;
}
int main(){
int i,j,t,ca=;
scanf("%d",&t);
while(t--){
scanf("%s%s",&a,&b);
int len=strlen(a);
memset(c,,sizeof(c));
memset(d,,sizeof(d));
for(i=;i<len;i++){
c[a[i]-'']++;
d[b[i]-'']++;
}
int tt=first();
printf("Case #%d: %d",++ca,tt);
if(tt==){
printf("\n");
continue;
}
for(i=;i>=;i--){
int m=solve(i);
for(j=;j<=m;j++)
printf("%d",i);
}
printf("\n");
}
return ;
}
hdu 4726 Kia's Calculation的更多相关文章
- HDU 4726 Kia's Calculation (贪心算法)
Kia's Calculation Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...
- HDU 4726 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/showproblem.php?pid=4726 题意:给出两个n位的数字,均无前缀0.重新排列两个数字中的各个数,重新排列后也无前缀0.得到的两 ...
- ACM学习历程—HDU 4726 Kia's Calculation( 贪心&&计数排序)
DescriptionDoctor Ghee is teaching Kia how to calculate the sum of two integers. But Kia is so carel ...
- 贪心 HDOJ 4726 Kia's Calculation
题目传送门 /* 这题交给队友做,做了一个多小时,全排列,RE数组越界,赛后发现读题读错了,囧! 贪心:先确定最高位的数字,然后用贪心的方法,越高位数字越大 注意:1. Both A and B wi ...
- hdu 4965 Fast Matrix Calculation(矩阵高速幂)
题目链接.hdu 4965 Fast Matrix Calculation 题目大意:给定两个矩阵A,B,分别为N*K和K*N. 矩阵C = A*B 矩阵M=CN∗N 将矩阵M中的全部元素取模6,得到 ...
- 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 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
随机推荐
- 论C# java的基本类型
http://blog.csdn.net/com360/article/details/8201930 http://www.360doc.com/content/13/0818/13/8074294 ...
- [笔记]一个测试浏览器对html5支持的网站
用需要测试的浏览器打开这个地址:http://html5test.com/
- 28335 sci fifo send
#include "DSP2833x_Device.h"#include "DSP2833x_Examples.h"char buf[]={0x30,0x32, ...
- -25299 reason: 'Couldn't add the Keychain Item.'
今天在用苹果官方demo 提供的KeychainItemWrapper类时遇到-25299 reason: 'Couldn't add the Keychain Item.'错误,再4s上可以正常运 ...
- C++ STL中Map的按Key排序和按Value排序
map是用来存放<key, value>键值对的数据结构,可以很方便快速的根据key查到相应的value.假如存储学生和其成绩(假定不存在重名,当然可以对重名加以区 分),我们用map来进 ...
- JSON WEB TOKENS
用JWT来保护我们的ASP.NET Core Web API 在上一篇博客中,自己动手写了一个Middleware来处理API的授权验证,现在就采用另外一种方式来处理这个授权验证的问题,毕竟现在也 ...
- asdoc 档案
1.asdoc air项目会出现无法找到NativeApplication等错误 解决办法:add args -load-config ....../frameworks/air-config.x ...
- String、StringBuilder、StringBuffer
String String ...
- github实践操作
一.本地仓库的创建和提交 1.下载并安装Git http://msysgit.github.io/,安装完成后在本地电脑创建一个git仓库并初始化本地仓库 2.在git目录下创建一个Readme.tx ...
- 随机产生30个两个两位数相加的题目(java)
编程思路: 1首先遇到JAVA产生随机数的问题. 2把产生的随机数设定范围. 3把划分的范围再分四个小区段分别对应四则运算法则加减乘除. 4打印输出. 题目源代码(Java) package coun ...