Yet another A + B——KTU Programming Camp (Day 1) I题
来源:互联网 发布:windows如何多线程 编辑:程序博客网 时间:2024/06/09 22:28
题目链接:
http://codeforces.com/gym/100735/problem/I分析:
给出3个数A,B,C,每个数可以用给出的这三个数替换,问是否能替换后使其满足A + B = C .由于题目给出的数据范围很大 1 ~ 10^100,所以不用多想,先敲一个高精度大数加法,单元测试过来再拿来用!题解:
大数加法敲完后,这题就完成60%了,为了精简之后的计算,所以我们还要写个大数比较大小(类型为 string )。这一步完成后,就已经完成90%了。我们挑出A, B, C中最大的一个数,和C互换位置后,接下来计算除A+B(与C比较),A+A(与B,C比较),B+B(与A,C)比较,如果其中有一个相等就输出YES,否则输出NO。AC代码:
#include <iostream>#include <cstring>#include <cstdio>#include <queue>#include <algorithm>#include <cmath>using namespace std;string A, B, C;bool dayu(string a, string b){ int len1 = a.length(); int len2 = b.length(); if(len1 > len2) { return true; } else if(len1<len2) { return false; } else { if(a<b) { return false; } else { return true; } }}string Add(string a, string b){ string c ,d; int flag = 0; int len1 = a.length(); int len2 = b.length(); if(len1 > len2) { c = a; d = b; } else if(len1<len2) { c = b; d = a; } else { if(a<b) { c = b; d = a; } else { c = a; d = b; } } len1 = c.length(); len2 = d.length(); int dd = len1 - len2; //cout << c << endl; for(int i =len1-1; i>=0; i--) { //cout << c[i]<<": " <<flag<< endl; int he = c[i] - 48; if(i-dd>=0) he = c[i] - 48 + d[i-dd] - 48; while(flag) { he++; flag--; } flag += he/10; he%=10; c[i] = he+48; //cout << c[i] << endl; } if(flag) { string ans; ans+='1'; ans+=c; c = ans; } return c;}/*int main(){ cin >> A >> B; C = Add(A, B); cout << C << endl;}*/int main(){ cin >> A >> B >>C; if(dayu(A,B) && dayu(A,C)) { string tmp = C; C = A; A = tmp; } if(dayu(B,C) && dayu(B,A)) { string tmp = C; C = B; B = tmp; } //cout << A << B << C << endl; int flag = 0; string a1 = Add(A, A); string a2 = Add(B,B); string a3 = Add(A,B); //cout<<a3<<endl; if(a1 == B || a1 == C || a2 == A ||a2 == C|| a3 == C) { flag = 1; } if(flag) cout << "YES" << endl; else cout << "NO" << endl;}
0 0
- Yet another A + B——KTU Programming Camp (Day 1) I题
- Restore——KTU Programming Camp (Day 1) E题
- KTU Programming Camp (Winter Training Day 1)
- KTU Programming Camp (Day 3) A. Queries - 线段树
- KTU Programming Camp (Day 2) Problem I. Lazy mobile users - 树形dp
- Gym 100735 - I. Yet another A + B
- Gym 100735I Yet another A + B (java大数)
- KTU Programming Camp (Day 2) Problem F. Sequence of words 后缀数组+线段树
- Java大数简单题---Yet another A + B
- 2013资格赛——Another A+B
- Yet Another Web Framework 1
- HDU 4474 Yet Another Multiple Problem 搜索——BFS
- HDU 4569——Yet another end of the world
- 1001 - Another A+B
- Another A+B
- Another a+b FZU
- 剑指Offer——构建数组B[i]=A[0]*A[1]*....A[i-1]*A[i+1]*A[i+2]*...A[n-1],不能使用除法
- [****Camp Day 1]C. Control Point(乱搞)
- NYOJ取石子(一)23题
- 在office中嵌入mathtype
- iOS多线程
- Struts2的简单使用(四)action向页面传值
- android权限大全
- Yet another A + B——KTU Programming Camp (Day 1) I题
- 拦截匪徒 (枚举+判断图的连通性)
- 双系统ubuntu+ros indigo安装
- 【Wireless】【加密】WPA/2-PSK密码格式
- 统计并找出一句英文句子中最长的一个单词
- hitTest:withEvent使用
- Unsupported major.minor version 51.0 异常处理方法
- iOS开发中WiFi相关功能总结
- KJFrameForAndroid 资料——KJBitmap使用方法