gym 100735I

Description

standard input/output
Statements

You are given three numbers. Is there a way to replace variables A, B and C with these numbers so the equality A + B = C is correct?

Input

There are three numbers X1, X2 and X3 (1 ≤ Xi ≤ 10100), each on a separate line of input.

Output

Output either "YES", if there is a way to substitute variables A, B and C with given numbers so the equality is correct, or "NO" otherwise.

Sample Input

Input
1
2
3
Output
YES
Input
1
2
4
Output
YES
Input
1
3
5
Output
NO
题意: 给你3 个数,让你判断其中任意两个数的和是否可以组成这三个树种的一个,这些数都可以重复使用。
分析: 高精度
  1 #include<string>
  2 #include<iostream>
  3 #include<iosfwd>
  4 #include<cmath>
  5 #include<cstring>
  6 #include<stdlib.h>
  7 #include<stdio.h>
  8 #include<cstring>
  9 #define MAX_L 2005 //最大长度,可以修改
 10 using namespace std;
 11 
 12 class bign
 13 {
 14 public:
 15     int len, s[MAX_L];//数的长度,记录数组
 16 //构造函数
 17     bign();
 18     bign(const char*);
 19     bign(int);
 20     bool sign;//符号 1正数 0负数
 21     string toStr() const;//转化为字符串,主要是便于输出
 22     friend istream& operator>>(istream &,bign &);//重载输入流
 23     friend ostream& operator<<(ostream &,bign &);//重载输出流
 24 //重载复制
 25     bign operator=(const char*);
 26     bign operator=(int);
 27     bign operator=(const string);
 28 //重载各种比较
 29     bool operator>(const bign &) const;
 30     bool operator>=(const bign &) const;
 31     bool operator<(const bign &) const;
 32     bool operator<=(const bign &) const;
 33     bool operator==(const bign &) const;
 34     bool operator!=(const bign &) const;
 35 //重载四则运算
 36     bign operator+(const bign &) const;
 37     bign operator++();
 38     bign operator++(int);
 39     bign operator+=(const bign&);
 40     bign operator-(const bign &) const;
 41     bign operator--();
 42     bign operator--(int);
 43     bign operator-=(const bign&);
 44     bign operator*(const bign &)const;
 45     bign operator*(const int num)const;
 46     bign operator*=(const bign&);
 47     bign operator/(const bign&)const;
 48     bign operator/=(const bign&);
 49 //四则运算的衍生运算
 50     bign operator%(const bign&)const;//取模(余数)
 51     bign factorial()const;//阶乘
 52     bign Sqrt()const;//整数开根(向下取整)
 53     bign pow(const bign&)const;//次方
 54 //一些乱乱的函数
 55     void clean();
 56     ~bign();
 57 };
 58 #define max(a,b) a>b ? a : b
 59 #define min(a,b) a<b ? a : b
 60 
 61 bign::bign()
 62 {
 63     memset(s, 0, sizeof(s));
 64     len = 1;
 65     sign = 1;
 66 }
 67 
 68 bign::bign(const char *num)
 69 {
 70     *this = num;
 71 }
 72 
 73 bign::bign(int num)
 74 {
 75     *this = num;
 76 }
 77 
 78 string bign::toStr() const
 79 {
 80     string res;
 81     res = "";
 82     for (int i = 0; i < len; i++)
 83         res = (char)(s[i] + '0') + res;
 84     if (res == "")
 85         res = "0";
 86     if (!sign&&res != "0")
 87         res = "-" + res;
 88     return res;
 89 }
 90 
 91 istream &operator>>(istream &in, bign &num)
 92 {
 93     string str;
 94     in>>str;
 95     num=str;
 96     return in;
 97 }
 98 
 99 ostream &operator<<(ostream &out, bign &num)
100 {
101     out<<num.toStr();
102     return out;
103 }
104 
105 bign bign::operator=(const char *num)
106 {
107     memset(s, 0, sizeof(s));
108     char a[MAX_L] = "";
109     if (num[0] != '-')
110         strcpy(a, num);
111     else
112         for (int i = 1; i < strlen(num); i++)
113             a[i - 1] = num[i];
114     sign = !(num[0] == '-');
115     len = strlen(a);
116     for (int i = 0; i < strlen(a); i++)
117         s[i] = a[len - i - 1] - 48;
118     return *this;
119 }
120 
121 bign bign::operator=(int num)
122 {
123     char temp[MAX_L];
124     sprintf(temp, "%d", num);
125     *this = temp;
126     return *this;
127 }
128 
129 bign bign::operator=(const string num)
130 {
131     const char *tmp;
132     tmp = num.c_str();
133     *this = tmp;
134     return *this;
135 }
136 
137 bool bign::operator<(const bign &num) const
138 {
139     if (sign^num.sign)
140         return num.sign;
141     if (len != num.len)
142         return len < num.len;
143     for (int i = len - 1; i >= 0; i--)
144         if (s[i] != num.s[i])
145             return sign ? (s[i] < num.s[i]) : (!(s[i] < num.s[i]));
146     return !sign;
147 }
148 
149 bool bign::operator>(const bign&num)const
150 {
151     return num < *this;
152 }
153 
154 bool bign::operator<=(const bign&num)const
155 {
156     return !(*this>num);
157 }
158 
159 bool bign::operator>=(const bign&num)const
160 {
161     return !(*this<num);
162 }
163 
164 bool bign::operator!=(const bign&num)const
165 {
166     return *this > num || *this < num;
167 }
168 
169 bool bign::operator==(const bign&num)const
170 {
171     return !(num != *this);
172 }
173 
174 bign bign::operator+(const bign &num) const
175 {
176     if (sign^num.sign)
177     {
178         bign tmp = sign ? num : *this;
179         tmp.sign = 1;
180         return sign ? *this - tmp : num - tmp;
181     }
182     bign result;
183     result.len = 0;
184     int temp = 0;
185     for (int i = 0; temp || i < (max(len, num.len)); i++)
186     {
187         int t = s[i] + num.s[i] + temp;
188         result.s[result.len++] = t % 10;
189         temp = t / 10;
190     }
191     result.sign = sign;
192     return result;
193 }
194 
195 bign bign::operator++()
196 {
197     *this = *this + 1;
198     return *this;
199 }
200 
201 bign bign::operator++(int)
202 {
203     bign old = *this;
204     ++(*this);
205     return old;
206 }
207 
208 bign bign::operator+=(const bign &num)
209 {
210     *this = *this + num;
211     return *this;
212 }
213 
214 bign bign::operator-(const bign &num) const
215 {
216     bign b=num,a=*this;
217     if (!num.sign && !sign)
218     {
219         b.sign=1;
220         a.sign=1;
221         return b-a;
222     }
223     if (!b.sign)
224     {
225         b.sign=1;
226         return a+b;
227     }
228     if (!a.sign)
229     {
230         a.sign=1;
231         b=bign(0)-(a+b);
232         return b;
233     }
234     if (a<b)
235     {
236         bign c=(b-a);
237         c.sign=false;
238         return c;
239     }
240     bign result;
241     result.len = 0;
242     for (int i = 0, g = 0; i < a.len; i++)
243     {
244         int x = a.s[i] - g;
245         if (i < b.len) x -= b.s[i];
246         if (x >= 0) g = 0;
247         else
248         {
249             g = 1;
250             x += 10;
251         }
252         result.s[result.len++] = x;
253     }
254     result.clean();
255     return result;
256 }
257 
258 bign bign::operator * (const bign &num)const
259 {
260     bign result;
261     result.len = len + num.len;
262 
263     for (int i = 0; i < len; i++)
264         for (int j = 0; j < num.len; j++)
265             result.s[i + j] += s[i] * num.s[j];
266 
267     for (int i = 0; i < result.len; i++)
268     {
269         result.s[i + 1] += result.s[i] / 10;
270         result.s[i] %= 10;
271     }
272     result.clean();
273     result.sign = !(sign^num.sign);
274     return result;
275 }
276 
277 bign bign::operator*(const int num)const
278 {
279     bign x = num;
280     bign z = *this;
281     return x*z;
282 }
283 bign bign::operator*=(const bign&num)
284 {
285     *this = *this * num;
286     return *this;
287 }
288 
289 bign bign::operator /(const bign&num)const
290 {
291     bign ans;
292     ans.len = len - num.len + 1;
293     if (ans.len < 0)
294     {
295         ans.len = 1;
296         return ans;
297     }
298 
299     bign divisor = *this, divid = num;
300     divisor.sign = divid.sign = 1;
301     int k = ans.len - 1;
302     int j = len - 1;
303     while (k >= 0)
304     {
305         while (divisor.s[j] == 0) j--;
306         if (k > j) k = j;
307         char z[MAX_L];
308         memset(z, 0, sizeof(z));
309         for (int i = j; i >= k; i--)
310             z[j - i] = divisor.s[i] + '0';
311         bign dividend = z;
312         if (dividend < divid) { k--; continue; }
313         int key = 0;
314         while (divid*key <= dividend) key++;
315         key--;
316         ans.s[k] = key;
317         bign temp = divid*key;
318         for (int i = 0; i < k; i++)
319             temp = temp * 10;
320         divisor = divisor - temp;
321         k--;
322     }
323     ans.clean();
324     ans.sign = !(sign^num.sign);
325     return ans;
326 }
327 
328 bign bign::operator/=(const bign&num)
329 {
330     *this = *this / num;
331     return *this;
332 }
333 
334 bign bign::operator%(const bign& num)const
335 {
336     bign a = *this, b = num;
337     a.sign = b.sign = 1;
338     bign result, temp = a / b*b;
339     result = a - temp;
340     result.sign = sign;
341     return result;
342 }
343 
344 bign bign::pow(const bign& num)const
345 {
346     bign result = 1;
347     for (bign i = 0; i < num; i++)
348         result = result*(*this);
349     return result;
350 }
351 
352 bign bign::factorial()const
353 {
354     bign result = 1;
355     for (bign i = 1; i <= *this; i++)
356         result *= i;
357     return result;
358 }
359 
360 void bign::clean()
361 {
362     if (len == 0) len++;
363     while (len > 1 && s[len - 1] == '\0')
364         len--;
365 }
366 
367 bign bign::Sqrt()const
368 {
369     if(*this<0)return -1;
370     if(*this<=1)return *this;
371     bign l=0,r=*this,mid;
372     while(r-l>1)
373     {
374         mid=(l+r)/2;
375         if(mid*mid>*this)
376             r=mid;
377         else
378             l=mid;
379     }
380     return l;
381 }
382 
383 bign::~bign()
384 {
385 }
386 
387 bign a,b,c;
388 
389 int main()
390 {
391     cin >> a >> b >> c;
392     bool flag = false;
393     if(a + b == c) flag = true;
394     if(a + c == b) flag = true;
395     if(a + a == b) flag = true;
396     if(a + a == c) flag = true;
397     if(b + b == a) flag = true;
398     if(b + b == c) flag = true;
399     if(b + c == a) flag = true;
400     if(c + c == a) flag = true;
401     if(c + c == b) flag = true;
402     if(flag) cout << "YES" << endl;
403     else cout << "NO" << endl;
404     return 0;
405 }

 

转载于:https://www.cnblogs.com/PrayG/p/5732648.html

CSDN海神之光上传的代码均可运行,亲测可用,直接替换数据即可,适合小白; 1、代码压缩包内容 主函数:main.m; 调用函数:其他m文件;无需运行 运行结果效果图; 2、代码运行版本 Matlab 2019b或2023b;若运行有误,根据提示修改;若不会,私信博主; 3、运行操作步骤 步骤一:将所有文件放到Matlab的当前文件夹中; 步骤二:双击打开main.m文件; 步骤三:点击运行,等程序运行完得到结果; 4、仿真咨询 如需其他服务,可私信博主或扫描博客文章底部QQ名片; 4.1 博客或资源的完整代码提供 4.2 期刊或参考文献复现 4.3 Matlab程序定制 4.4 科研合作 功率谱估计: 故障诊断分析: 雷达通信:雷达LFM、MIMO、成像、定位、干扰、检测、信号分析、脉冲压缩 滤波估计:SOC估计 目标定位:WSN定位、滤波跟踪、目标定位 生物电信号:肌电信号EMG、脑电信号EEG、心电信号ECG 通信系统:DOA估计、编码译码、变分模态分解、管道泄漏、滤波器、数字信号处理+传输+分析+去噪(CEEMDAN)、数字信号调制、误码率、信号估计、DTMF、信号检测识别融合、LEACH协议、信号检测、水声通信 1. EMD(经验模态分解,Empirical Mode Decomposition) 2. TVF-EMD(时变滤波的经验模态分解,Time-Varying Filtered Empirical Mode Decomposition) 3. EEMD(集成经验模态分解,Ensemble Empirical Mode Decomposition) 4. VMD(变分模态分解,Variational Mode Decomposition) 5. CEEMDAN(完全自适应噪声集合经验模态分解,Complementary Ensemble Empirical Mode Decomposition with Adaptive Noise) 6. LMD(局部均值分解,Local Mean Decomposition) 7. RLMD(鲁棒局部均值分解, Robust Local Mean Decomposition) 8. ITD(固有时间尺度分解,Intrinsic Time Decomposition) 9. SVMD(逐次变分模态分解,Sequential Variational Mode Decomposition) 10. ICEEMDAN(改进的完全自适应噪声集合经验模态分解,Improved Complementary Ensemble Empirical Mode Decomposition with Adaptive Noise) 11. FMD(特征模式分解,Feature Mode Decomposition) 12. REMD(鲁棒经验模态分解,Robust Empirical Mode Decomposition) 13. SGMD(辛几何模态分解,Spectral-Grouping-based Mode Decomposition) 14. RLMD(鲁棒局部均值分解,Robust Intrinsic Time Decomposition) 15. ESMD(极点对称模态分解, extreme-point symmetric mode decomposition) 16. CEEMD(互补集合经验模态分解,Complementary Ensemble Empirical Mode Decomposition) 17. SSA(奇异谱分析,Singular Spectrum Analysis) 18. SWD(群分解,Swarm Decomposition) 19. RPSEMD(再生相移正弦辅助经验模态分解,Regenerated Phase-shifted Sinusoids assisted Empirical Mode Decomposition) 20. EWT(经验小波变换,Empirical Wavelet Transform) 21. DWT(离散小波变换,Discraete wavelet transform) 22. TDD(时域分解,Time Domain Decomposition) 23. MODWT(最大重叠离散小波变换,Maximal Overlap Discrete Wavelet Transform) 24. MEMD(多元经验模态分解,Multivariate Empirical Mode Decomposition) 25. MVMD(多元变分模态分解,Multivariate Variational Mode Decomposition)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值