贪心 不是很难  各种细节注意

#include <cstdio>
#include <cstring>
#include <algorithm> using namespace std; int num1[10],num2[10];
int cc(int i, int j)
{
for(int k = 0; k <= 9; k++)
{
if( (k+i)%10 == j )
return k;
}
return 0;
}
int main()
{
int t,ca = 1;
scanf("%d",&t);
getchar();
while(t--)
{
memset(num1, 0, sizeof(num1));
memset(num2, 0, sizeof(num2));
char a[1000010];
gets(a);
int len = strlen(a);
for(int i = 0; i < len; i++)
num1[a[i]-'0']++;
gets(a);
len = strlen(a);
for(int i = 0; i < len; i++)
num2[a[i]-'0']++;
int flag = 0, flag1 = 0;
printf("Case #%d: ",ca++);
for(int i = 9; i >= 0; i--)
{
for(int j = 0; j <= 9; j++)
{
int k = cc(j, i);
if(j != 0 && k != 0 && num1[j] && num2[k])
{
num1[j]--, num2[k]--;
flag = 1;
if(i != 0)
{
flag1 = 1;
printf("%d",i);
}
break;
}
}
if(flag)
break;
}
for(int i = 9; i >= 0; i--)
{
if(!flag1 && i == 0)
{
printf("0");
break;
}
for(int j = 0; j <= 9; j++)
{
int k = cc(j, i);
int d = min(num1[j], num2[k]);
num1[j] -= d;
num2[k] -= d;
for(int q = 0; q < d; q++)
{
if(i != 0)
flag1 = 1;
printf("%d",i);
}
}
}
puts("");
}
return 0;
}

hdu 4726的更多相关文章

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

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

  2. hdu 4726 Kia's Calculation

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

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

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

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

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

  5. hdu 4726(贪心)

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

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

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

  7. 2013 ACM/ICPC Asia Regional Online —— Warmup2

    HDU 4716 A Computer Graphics Problem 水题.略 HDU 4717 The Moving Points 题目:给出n个点的起始位置以及速度矢量,问任意一个时刻使得最远 ...

  8. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  9. 【HDU 3037】Saving Beans Lucas定理模板

    http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...

随机推荐

  1. 导出Private API

    首先介绍下private API 它共分为两类: 1 在官方文档中没有呈现的API(在frameworks 下隐藏) 2 苹果明确申明不能使用的API ,在privateFrameworks 下 然后 ...

  2. 第五篇、Uber用视频播放做启动动画

    import UIKit import AVFoundation class GuidePage: FxBasePage { @IBOutlet var backImageView:UIImageVi ...

  3. HTML+CSS学习笔记(1) - Html介绍

    HTML+CSS学习笔记(1) - Html介绍 1.代码初体验,制作我的第一个网页 <!DOCTYPE HTML> <html> <head> <meta ...

  4. JQuery验证工具

    一.写法一 var Validator = { // 邮箱isEmail : function(s) {var p = "^[-!#$%&\'*+\\./0-9=?A-Z^_`a-z ...

  5. (转)Tomcat内存设置

    Java内存溢出详解 一.常见的Java内存溢出有以下三种: 1. java.lang.OutOfMemoryError: Java heap space ----JVM Heap(堆)溢出 JVM在 ...

  6. 本地安装discuz

    出处:http://jingyan.baidu.com/article/b87fe19eb57ff252183568d9.html 网站建目前都很简单,建站容易,管理难,网站做大优化更难.本人有建站经 ...

  7. java查询WFS服务

    在我们访问wfs服务时候,有时候会遇到前台访问时候的跨域问题.这里给出java访问的一个小例子. import java.io.BufferedReader; import java.io.IOExc ...

  8. PHP 测试程序运行时间 microtime函数用法

    PHP microtime() 函数PHP Date / Time 函数定义和用法microtime() 函数返回当前 Unix 时间戳和微秒数.语法microtime(get_as_float)参数 ...

  9. JQuery 判断某个属性是否存在 hasAttr

    $(".fengye a").each(function () { if (typeof($(this).attr("href")) != "unde ...

  10. StringBuilder的Append()方法会比+=效率高

    StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 id from " + databa ...