gym 100735I
Description
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
1
2
3
YES
1
2
4
YES
1
3
5
NO
题意: 给你3 个数,让你判断其中任意两个数的和是否可以组成这三个树种的一个,这些数都可以重复使用。
分析: 高精度
#include<string>
#include<iostream>
#include<iosfwd>
#include<cmath>
#include<cstring>
#include<stdlib.h>
#include<stdio.h>
#include<cstring>
#define MAX_L 2005 //最大长度,可以修改
using namespace std; class bign
{
public:
int len, s[MAX_L];//数的长度,记录数组
//构造函数
bign();
bign(const char*);
bign(int);
bool sign;//符号 1正数 0负数
string toStr() const;//转化为字符串,主要是便于输出
friend istream& operator>>(istream &,bign &);//重载输入流
friend ostream& operator<<(ostream &,bign &);//重载输出流
//重载复制
bign operator=(const char*);
bign operator=(int);
bign operator=(const string);
//重载各种比较
bool operator>(const bign &) const;
bool operator>=(const bign &) const;
bool operator<(const bign &) const;
bool operator<=(const bign &) const;
bool operator==(const bign &) const;
bool operator!=(const bign &) const;
//重载四则运算
bign operator+(const bign &) const;
bign operator++();
bign operator++(int);
bign operator+=(const bign&);
bign operator-(const bign &) const;
bign operator--();
bign operator--(int);
bign operator-=(const bign&);
bign operator*(const bign &)const;
bign operator*(const int num)const;
bign operator*=(const bign&);
bign operator/(const bign&)const;
bign operator/=(const bign&);
//四则运算的衍生运算
bign operator%(const bign&)const;//取模(余数)
bign factorial()const;//阶乘
bign Sqrt()const;//整数开根(向下取整)
bign pow(const bign&)const;//次方
//一些乱乱的函数
void clean();
~bign();
};
#define max(a,b) a>b ? a : b
#define min(a,b) a<b ? a : b bign::bign()
{
memset(s, , sizeof(s));
len = ;
sign = ;
} bign::bign(const char *num)
{
*this = num;
} bign::bign(int num)
{
*this = num;
} string bign::toStr() const
{
string res;
res = "";
for (int i = ; i < len; i++)
res = (char)(s[i] + '') + res;
if (res == "")
res = "";
if (!sign&&res != "")
res = "-" + res;
return res;
} istream &operator>>(istream &in, bign &num)
{
string str;
in>>str;
num=str;
return in;
} ostream &operator<<(ostream &out, bign &num)
{
out<<num.toStr();
return out;
} bign bign::operator=(const char *num)
{
memset(s, , sizeof(s));
char a[MAX_L] = "";
if (num[] != '-')
strcpy(a, num);
else
for (int i = ; i < strlen(num); i++)
a[i - ] = num[i];
sign = !(num[] == '-');
len = strlen(a);
for (int i = ; i < strlen(a); i++)
s[i] = a[len - i - ] - ;
return *this;
} bign bign::operator=(int num)
{
char temp[MAX_L];
sprintf(temp, "%d", num);
*this = temp;
return *this;
} bign bign::operator=(const string num)
{
const char *tmp;
tmp = num.c_str();
*this = tmp;
return *this;
} bool bign::operator<(const bign &num) const
{
if (sign^num.sign)
return num.sign;
if (len != num.len)
return len < num.len;
for (int i = len - ; i >= ; i--)
if (s[i] != num.s[i])
return sign ? (s[i] < num.s[i]) : (!(s[i] < num.s[i]));
return !sign;
} bool bign::operator>(const bign&num)const
{
return num < *this;
} bool bign::operator<=(const bign&num)const
{
return !(*this>num);
} bool bign::operator>=(const bign&num)const
{
return !(*this<num);
} bool bign::operator!=(const bign&num)const
{
return *this > num || *this < num;
} bool bign::operator==(const bign&num)const
{
return !(num != *this);
} bign bign::operator+(const bign &num) const
{
if (sign^num.sign)
{
bign tmp = sign ? num : *this;
tmp.sign = ;
return sign ? *this - tmp : num - tmp;
}
bign result;
result.len = ;
int temp = ;
for (int i = ; temp || i < (max(len, num.len)); i++)
{
int t = s[i] + num.s[i] + temp;
result.s[result.len++] = t % ;
temp = t / ;
}
result.sign = sign;
return result;
} bign bign::operator++()
{
*this = *this + ;
return *this;
} bign bign::operator++(int)
{
bign old = *this;
++(*this);
return old;
} bign bign::operator+=(const bign &num)
{
*this = *this + num;
return *this;
} bign bign::operator-(const bign &num) const
{
bign b=num,a=*this;
if (!num.sign && !sign)
{
b.sign=;
a.sign=;
return b-a;
}
if (!b.sign)
{
b.sign=;
return a+b;
}
if (!a.sign)
{
a.sign=;
b=bign()-(a+b);
return b;
}
if (a<b)
{
bign c=(b-a);
c.sign=false;
return c;
}
bign result;
result.len = ;
for (int i = , g = ; i < a.len; i++)
{
int x = a.s[i] - g;
if (i < b.len) x -= b.s[i];
if (x >= ) g = ;
else
{
g = ;
x += ;
}
result.s[result.len++] = x;
}
result.clean();
return result;
} bign bign::operator * (const bign &num)const
{
bign result;
result.len = len + num.len; for (int i = ; i < len; i++)
for (int j = ; j < num.len; j++)
result.s[i + j] += s[i] * num.s[j]; for (int i = ; i < result.len; i++)
{
result.s[i + ] += result.s[i] / ;
result.s[i] %= ;
}
result.clean();
result.sign = !(sign^num.sign);
return result;
} bign bign::operator*(const int num)const
{
bign x = num;
bign z = *this;
return x*z;
}
bign bign::operator*=(const bign&num)
{
*this = *this * num;
return *this;
} bign bign::operator /(const bign&num)const
{
bign ans;
ans.len = len - num.len + ;
if (ans.len < )
{
ans.len = ;
return ans;
} bign divisor = *this, divid = num;
divisor.sign = divid.sign = ;
int k = ans.len - ;
int j = len - ;
while (k >= )
{
while (divisor.s[j] == ) j--;
if (k > j) k = j;
char z[MAX_L];
memset(z, , sizeof(z));
for (int i = j; i >= k; i--)
z[j - i] = divisor.s[i] + '';
bign dividend = z;
if (dividend < divid) { k--; continue; }
int key = ;
while (divid*key <= dividend) key++;
key--;
ans.s[k] = key;
bign temp = divid*key;
for (int i = ; i < k; i++)
temp = temp * ;
divisor = divisor - temp;
k--;
}
ans.clean();
ans.sign = !(sign^num.sign);
return ans;
} bign bign::operator/=(const bign&num)
{
*this = *this / num;
return *this;
} bign bign::operator%(const bign& num)const
{
bign a = *this, b = num;
a.sign = b.sign = ;
bign result, temp = a / b*b;
result = a - temp;
result.sign = sign;
return result;
} bign bign::pow(const bign& num)const
{
bign result = ;
for (bign i = ; i < num; i++)
result = result*(*this);
return result;
} bign bign::factorial()const
{
bign result = ;
for (bign i = ; i <= *this; i++)
result *= i;
return result;
} void bign::clean()
{
if (len == ) len++;
while (len > && s[len - ] == '\0')
len--;
} bign bign::Sqrt()const
{
if(*this<)return -;
if(*this<=)return *this;
bign l=,r=*this,mid;
while(r-l>)
{
mid=(l+r)/;
if(mid*mid>*this)
r=mid;
else
l=mid;
}
return l;
} bign::~bign()
{
} bign a,b,c; int main()
{
cin >> a >> b >> c;
bool flag = false;
if(a + b == c) flag = true;
if(a + c == b) flag = true;
if(a + a == b) flag = true;
if(a + a == c) flag = true;
if(b + b == a) flag = true;
if(b + b == c) flag = true;
if(b + c == a) flag = true;
if(c + c == a) flag = true;
if(c + c == b) flag = true;
if(flag) cout << "YES" << endl;
else cout << "NO" << endl;
return ;
}
gym 100735I的更多相关文章
- ACM: Gym 101047M Removing coins in Kem Kadrãn - 暴力
Gym 101047M Removing coins in Kem Kadrãn Time Limit:2000MS Memory Limit:65536KB 64bit IO Fo ...
- ACM: Gym 101047K Training with Phuket's larvae - 思维题
Gym 101047K Training with Phuket's larvae Time Limit:2000MS Memory Limit:65536KB 64bit IO F ...
- ACM: Gym 101047E Escape from Ayutthaya - BFS
Gym 101047E Escape from Ayutthaya Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I6 ...
- ACM: Gym 101047B Renzo and the palindromic decoration - 手速题
Gym 101047B Renzo and the palindromic decoration Time Limit:2000MS Memory Limit:65536KB 64 ...
- Gym 101102J---Divisible Numbers(反推技巧题)
题目链接 http://codeforces.com/gym/101102/problem/J Description standard input/output You are given an a ...
- Gym 100917J---Judgement(01背包+bitset)
题目链接 http://codeforces.com/gym/100917/problem/J Description standard input/outputStatements The jury ...
- Gym 100917J---dir -C(RMQ--ST)
题目链接 http://codeforces.com/gym/100917/problem/D problem description Famous Berland coder and IT mana ...
- Gym 101102D---Rectangles(单调栈)
题目链接 http://codeforces.com/gym/101102/problem/D problem description Given an R×C grid with each cel ...
- Gym 101102C---Bored Judge(区间最大值)
题目链接 http://codeforces.com/gym/101102/problem/C problem description Judge Bahosain was bored at ACM ...
随机推荐
- java String字符串操作 字符串加密等
子串加密 1,设计思想 (1)输入一个字符串 (2)通过toCharArray()的方法将字符串转换成字符数组 (3)新建一个字符数组用来存储修改后的字符数组 2,程序流程图 3,源代码 packag ...
- poj1284 && caioj 1159 欧拉函数1:原根
这道题不知道这个定理很难做出来. 除非暴力找规律. 我原本找的时候出了问题 暴力找出的从13及以上的答案就有问题了 因为13的12次方会溢出 那么该怎么做? 快速幂派上用场. 把前几个素数的答案找出来 ...
- NYIST 46 最少乘法次数
最少乘法次数 时间限制:1000 ms | 内存限制:65535 KB 难度:3 描述 给你一个非零整数,让你求这个数的n次方,每次相乘的结果可以在后面使用,求至少需要多少次乘.如24:2*2 ...
- Python学习第一天-编写登陆接口
编写登陆接口 输入用户名密码 认证成功后显示欢迎信息 输错三次后锁定 帐号文件user.txt内容如下: qaz 123qwe 12345qweqwr 12321424...... 锁文件user_l ...
- c++_benchMark_vector_list_deque
title: c++_benchMark_vector_list_deque date: 2015-08-01 22:32:39 作者:titer1 + ZhangYu 出处:www.drysalte ...
- Perfect Rectangle(完美矩形)
我们有 N 个与坐标轴对齐的矩形, 其中 N > 0, 判断它们是否能精确地覆盖一个矩形区域. 每个矩形用左下角的点和右上角的点的坐标来表示.例如, 一个单位正方形可以表示为 [1,1,2,2] ...
- mysql-总结select各子句及其顺序
顺序:from->where ->group by->having ->order by
- QtWebkit里RenderLayer树的绘制具体流程分析
更新:RenderLayer树的绘制对RenderObject的绘制.同一时候补足绘制阶段的描写叙述. QtWebkit里,QWebView,QWebPage和QWebFr ...
- 【BZOJ 1660】 [Usaco2006 Nov]Bad Hair Day 乱发节
1660: [Usaco2006 Nov]Bad Hair Day 乱发节 Time Limit: 2 Sec Memory Limit: 64 MB Submit: 678 Solved: 32 ...
- lucene LZ4 会将doc存储在一个chunk里进行Lz4压缩 ES的_source便如此
默认情况下,Elasticsearch 用 JSON 字符串来表示文档主体保存在 _source 字段中.像其他保存的字段一样,_source 字段也会在写入硬盘前压缩.The _source is ...