一、题目

  A + B = C

二、分析

  比较考验码力的题。

  对于$c$,因为首位肯定不为0,那么$a$或者$b$至少有一个最高位是和$c$平齐的,或者少一位(相当于$a$+$b$进位得到)。

  那么这里,我们可以分四种情况

  1 让$a$与$c$变为等长$A$和$C$

    等长后判断$R = C - A$是否等于$b$,这里的等实际上是${R}\times{10^{d1}}$与${b}\times{10^{d2}}$比较,$d1$和$d2$都可能为结果做出贡献。

  2 让$a$与$c$变为等长$A$和$C$,但$C$继续增长一位变为$C = {C}\times{10}$

    判断$R = C - A$是否等于$b$,后面同上。

  3 让$b$与$c$变为等长$B$和$C$

    同情况1

  4 让$b$与$c$变为等长$B$和$C$,但$C$继续增长一位变为$C = {C}\times{10}$

    同情况2

  然后就是紧张刺激的码代码了,细节很多,因为变量太多,该初始化的要初始化,特别是X,Y,Z的变化一定要即时增长。

三、AC代码

  1 #include <bits/stdc++.h>
  2
  3 using namespace std;
  4 #define ll long long
  5 #define Min(a,b) ((a)>(b)?(b):(a))
  6 #define Max(a,b) ((a)>(b)?(a):(b))
  7 const int maxn = 1e5+13;
  8 char aa[maxn], bb[maxn], cc[maxn];
  9 int a[maxn], b[maxn], c[maxn];
 10 int lena, lenb, lenc;
 11 int la, lb, lc;
 12 int tx, ty, tz, deta1, deta2, deta3;
 13
 14 void debug()
 15 {
 16     cout << " a ";
 17     for(int i = 0; i < la; i++)
 18         cout << a[i];
 19     cout << endl << " c ";
 20     for(int i = 0; i < lc; i++)
 21         cout << c[i];
 22     cout << endl;
 23 }
 24
 25 // A - B == C
 26 bool check(int A[], int B[], int C[], int LA, int LB, int LC)
 27 {
 28     deta1 = deta2 = deta3 = 0;   //变化量
 29     if(A[0] < B[0])
 30         return false;
 31     int Res[maxn], L = LA;
 32     int pos = L - 1, tmp = 0;
 33     int i, j;
 34     for(i = LA - 1, j = LB - 1; i >= 0 && j >= 0; i--, j--, pos--)
 35     {
 36         A[i] -= tmp;
 37         tmp = 0;
 38         Res[pos] = A[i] - B[j];
 39         if(Res[pos] < 0)
 40         {
 41             tmp = 1;
 42             Res[pos] += 10;
 43         }
 44     }
 45     for(i; i >= 0; i--, pos--)
 46     {
 47         A[i] -= tmp;
 48         tmp = 0;
 49         Res[pos] = A[i];
 50         if(Res[pos] < 0)
 51         {
 52             tmp = 1;
 53             Res[pos] += 10;
 54         }
 55     }
 56     if(tmp > 0)
 57         return false;
 58     // 判断 Res  == C * 10^deta
 59     //  或者 Res * 10 ^ deta = C
 60     for(i = 0; i < L; i++)
 61     {
 62         if(Res[i] != 0)
 63             break;
 64     }
 65     for(j = 0; j < LC && i < L; j++, i++)
 66     {
 67         if(Res[i] != C[j])
 68             return false;
 69     }
 70     while(i < L)
 71     {
 72         if(Res[i] != 0)
 73             return false;
 74         deta3++;
 75         i++;
 76     }
 77     while(j < LC)
 78     {
 79         if(C[j] != 0)
 80             return false;
 81         deta1++;
 82         j++;
 83     }
 84     deta2 = deta1;
 85     // cout << "Res : ";
 86     // for(i = 0; i < L; i++)
 87     //     cout << Res[i];
 88     // cout << endl << "C : ";
 89     // for(i = 0; i < LC; i++)
 90     //     cout << C[i];
 91     // cout << endl;
 92     return true;
 93 }
 94
 95 void init1()
 96 {
 97     tx = 0, ty = 0, tz = 0;
 98     for(int i = 0; i < lena; i++)
 99         a[i] = aa[i] - '0';
100     for(int i = 0; i < lenb; i++)
101         b[i] = bb[i] - '0';
102     for(int i = 0; i < lenc; i++)
103         c[i] = cc[i] - '0';
104     la = lena, lb = lenb, lc = lenc;
105     if(la > lc)
106     {
107         lc = la;
108         tz += (lc - lenc);
109         for(int i = lenc; i < lc; i++)
110         {
111             c[i] = 0;
112         }
113     }
114     else if(la < lc)
115     {
116         la = lc;
117         tx += (la - lena);
118         for(int i = lena; i < la; i++)
119         {
120             a[i] = 0;
121         }
122     }
123     //cout << "tx : " << tx << " ty : " << ty << " tz : " << tz << endl;
124 }
125 void init2()
126 {
127     tx = 0, ty = 0, tz = 0;
128     for(int i = 0; i < lena; i++)
129         a[i] = aa[i] - '0';
130     for(int i = 0; i < lenb; i++)
131         b[i] = bb[i] - '0';
132     for(int i = 0; i < lenc; i++)
133         c[i] = cc[i] - '0';
134     la = lena, lb = lenb, lc = lenc;
135     if(lb > lc)
136     {
137         lc = lb;
138         tz += lc - lenc;
139         for(int i = lenc; i < lc; i++)
140         {
141             c[i] = 0;
142         }
143     }
144     else if(lb < lc)
145     {
146         lb = lc;
147         ty += lb - lenb;
148         for(int i = lenb; i < lb; i++)
149         {
150             b[i] = 0;
151         }
152     }
153 }
154
155 int main()
156 {
157     //freopen("input.txt", "r", stdin);
158     //freopen("out.txt", "w", stdout);
159     int T;
160     scanf("%d", &T);
161     while(T--)
162     {
163         scanf("%s%s%s", aa, bb, cc);
164         lena = strlen(aa);
165         lenb = strlen(bb);
166         lenc = strlen(cc);
167         init1();
168         //c - a == b
169         if(check(c, a, b, lc, la, lb))
170         {
171             // cout << " c - a ?= b " << deta << endl;
172             tx += deta2, ty += deta3, tz += deta1;
173             printf("%d %d %d\n", tx, ty, tz);
174             continue;
175         }
176         init1();
177         //c*10 - a == b
178         c[lc++] = 0;
179         tz++;
180         if(check(c, a, b, lc, la, lb))
181         {
182             // cout << " c*10 - a ?= b" << endl;
183             tx += deta2, ty += deta3, tz += deta1;
184             printf("%d %d %d\n", tx, ty, tz);
185             continue;
186         }
187         init2();
188         //c - b == a
189         if(check(c, b, a, lc, lb, la))
190         {
191             // cout << " c - b ?= a" << endl;
192             tx += deta3, ty += deta2, tz += deta1;
193             printf("%d %d %d\n", tx, ty, tz);
194             continue;
195         }
196         init2();
197         //c*10 - b == a
198         c[lc++] = 0;
199         tz++;
200         if(check(c, b, a, lc, lb, la))
201         {
202             // cout << " c*10 - b ?= a" << endl;
203             tx += deta3, ty += deta2, tz += deta1;
204             printf("%d %d %d\n", tx, ty, tz);
205             continue;
206         }
207         puts("-1");
208     }
209     return 0;
210 }

转载于:https://www.cnblogs.com/dybala21/p/11347189.html

2019HDU多校第七场 HDU6646 A + B = C 【模拟】相关推荐

  1. 2019HDU多校第七场 HDU6656 Kejin Player H 【期望递归】

    一.题目 Kejin Player H 二.分析 因为在当前等级$i$,如果升级失败可能会退回到原来的某一等级$x$,相当于就是失败的期望就是$E + (Sum[i-1] - Sum[x-1]) + ...

  2. 2019HDU多校第七场

    J Just Repeat 题意: 两个人玩游戏,每回合一方可以放另一方没有放过的卡,谁最后没卡放谁输 每个人优先出的牌的颜色肯定是场上没出过的, 对方也持有的, 并且两个人手中持有数量最多的牌.对方 ...

  3. 杭电多校第七场 1011 Kejin Player HDU(6656)

    杭电多校第七场 1011 Kejin Player 题意:给你N行,代表从i级有花费a[i]元的r[i]/s[i]的概率达到i+1级,剩下的概率中可能会到达x[i]级.然后询问从L级到R级的花费会是多 ...

  4. 2019杭电多校 第七场 Kejin Player 6656(求期望值)

    2019杭电多校 第七场 Kejin Player 6656(求期望值) 题目 http://acm.hdu.edu.cn/showproblem.php?pid=6656 题意 给你n,q.表示有n ...

  5. 2019HDU多校第十场

    (撒花!二十场打完了.虽然题解(riji)咕咕咕了好几场. 1003 Valentine's Day 传送:http://acm.hdu.edu.cn/showproblem.php?pid=6693 ...

  6. HDU 2020 多校第七场 游记

    又是被 djq 带飞的一场 orz,终场 rk2,又是罚时被锤了 1001,1002 俩 hard 先略过,不会做 /ll 1003 这种数数神题被 djq 一眼秒了,我还能说什么-- 首先我们考虑合 ...

  7. 2019牛客多校第七场E Find the median 权值线段树+离散化

    Find the median 题目链接: https://ac.nowcoder.com/acm/contest/887/E 题目描述 Let median of some array be the ...

  8. [2019HDU多校第四场][HDU 6617][D. Enveloping Convex]

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6617 题目大意:给出一凸包\(P\),求最小的与\(P\)相似且对应边平行的多边形,使得题目给出的\( ...

  9. 2019牛客多校 第七场 B Irreducible Polynomial 多项式因式分解判断

    链接:https://ac.nowcoder.com/acm/contest/887/B 来源:牛客网 Irreducible Polynomial 时间限制:C/C++ 1秒,其他语言2秒 空间限制 ...

最新文章

  1. 无线充电系统的功率与效率
  2. 链家前DBA判刑7年!你还敢不敢删库?
  3. A Complete Example
  4. C语言 const 笔记
  5. 6种常用Bean拷贝工具一览
  6. 解决miner.start() 返回null
  7. 信息抽取大一统:百度中科院发布通用抽取模型UIE,刷新13个IE数据集SOTA!
  8. CSS之立方体绘画步骤
  9. 基于HTML模板和JSON数据的JavaScript交互
  10. c语言实验报告问题错误分析,C语言实验报告(三)
  11. spssχ2检验_医学统计中常用的χ2检验在SPSS软件中的实现途径
  12. a4在html中的尺寸,网页设立A4大小
  13. oracle拆分分区语法详解大全_Oracle分区表详解
  14. Android 中奖滚动效果
  15. 全国计算机演示文稿,全国计算机统考押题——演示文稿
  16. 论文阅读笔记《Improving Unsupervised Defect Segmentation by Applying Structural Similarity To Autoencoders》
  17. Airbnb创始人:屌丝的逆袭之路
  18. 关于pbootcms中被挂马以后的处理
  19. Android自定义View实现方位刻度尺(类似于吃鸡手游)
  20. “沉浸式大型线下游戏”?看看这次腾讯TGC上如何玩很大!

热门文章

  1. android 普通蓝牙源码解读
  2. dobbo 什么时候流行_“ZBC”是什么意思?网络流行词看不懂就用它查
  3. [分享]PHP多城市版-房产系统源码,仿贝壳房产。
  4. 闪讯客户端 linux,Linux操做系统下链接闪讯的方法(支持有线与无线)
  5. 语音信号处理-基础(一):声学基础知识
  6. asp核酸检测预登记系统源码
  7. unity手势插件《FingerGestures 》使用入门
  8. 如何使用Susy:超强大的Sass网格
  9. Android高级工程师面试题整理
  10. 51单片机(8051系列)外部时钟