今日SGU 5.29

sgu 299

题意:给你n个线段,然后问你能不能选出其中三个组成一个三角形,数字很大

收获:另一个大整数模板

#include<bits/stdc++.h>
#define de(x) cout<<#x<<"="<<x<<endl;
#define dd(x) cout<<#x<<"="<<x<<" ";
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define repd(i,a,b) for(int i=a;i>=(b);--i)
#define repp(i,a,b,t) for(int i=a;i<(b);i+=t)
#define ll long long
#define mt(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
#define pii pair<int,int>
#define pdd pair<double,double>
#define pdi pair<double,int>
#define mp(u,v) make_pair(u,v)
#define sz(a) (int)a.size()
#define ull unsigned long long
#define ll long long
#define pb push_back
#define PI acos(-1.0)
#define qc std::ios::sync_with_stdio(false)
#define db double
#define all(a) a.begin(),a.end()
const int mod = 1e9+7;
const int maxn = 1e3+6;
const double eps = 1e-6;
using namespace std;
class bign
{
public:
    int len, s[maxn];//数的长度,记录数组
//构造函数
    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, 0, sizeof(s));
    len = 1;
    sign = 1;
}  

bign::bign(const char *num)
{
    *this = num;
}  

bign::bign(int num)
{
    *this = num;
}  

string bign::toStr() const
{
    string res;
    res = "";
    for (int i = 0; i < len; i++)
        res = (char)(s[i] + ‘0‘) + res;
    if (res == "")
        res = "0";
    if (!sign&&res != "0")
        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, 0, sizeof(s));
    char a[maxn] = "";
    if (num[0] != ‘-‘)
        strcpy(a, num);
    else
        for (int i = 1; i < strlen(num); i++)
            a[i - 1] = num[i];
    sign = !(num[0] == ‘-‘);
    len = strlen(a);
    for (int i = 0; i < strlen(a); i++)
        s[i] = a[len - i - 1] - 48;
    return *this;
}  

bign bign::operator=(int num)
{
    if (num < 0)
        sign = 0, num = -num;
    else
        sign = 1;
    char temp[maxn];
    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 - 1; i >= 0; 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 = 1;
        return sign ? *this - tmp : num - tmp;
    }
    bign result;
    result.len = 0;
    int temp = 0;
    for (int i = 0; temp || i < (max(len, num.len)); i++)
    {
        int t = s[i] + num.s[i] + temp;
        result.s[result.len++] = t % 10;
        temp = t / 10;
    }
    result.sign = sign;
    return result;
}  

bign bign::operator++()
{
    *this = *this + 1;
    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=1;
        a.sign=1;
        return b-a;
    }
    if (!b.sign)
    {
        b.sign=1;
        return a+b;
    }
    if (!a.sign)
    {
        a.sign=1;
        b=bign(0)-(a+b);
        return b;
    }
    if (a<b)
    {
        bign c=(b-a);
        c.sign=false;
        return c;
    }
    bign result;
    result.len = 0;
    for (int i = 0, g = 0; i < a.len; i++)
    {
        int x = a.s[i] - g;
        if (i < b.len) x -= b.s[i];
        if (x >= 0) g = 0;
        else
        {
            g = 1;
            x += 10;
        }
        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 = 0; i < len; i++)
        for (int j = 0; j < num.len; j++)
            result.s[i + j] += s[i] * num.s[j];  

    for (int i = 0; i < result.len; i++)
    {
        result.s[i + 1] += result.s[i] / 10;
        result.s[i] %= 10;
    }
    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;
}
void bign::clean()
{
    if (len == 0) len++;
    while (len > 1 && s[len - 1] == ‘\0‘)
        len--;
}
bign::~bign()
{
}
bign a[maxn];
int main(){
    int n;
    scanf("%d",&n);
    rep(i,1,n+1) cin>>a[i];
    sort(a+1,a+n+1);
    rep(i,3,n+1) if(a[i] < a[i-1] + a[i-2]) {
        cout<<a[i]<<" "<<a[i-1]<<" "<<a[i-2]<<endl;
        return 0;
    }
    puts("0 0 0");
    return 0;
}

原文地址:https://www.cnblogs.com/chinacwj/p/9107414.html

时间: 2024-10-04 06:27:48

今日SGU 5.29的相关文章

今日SGU

SGU 100 题意: 普通的a+b #include<bits/stdc++.h> #define de(x) cout<<#x<<"="<<x<<endl; #define dd(x) cout<<#x<<"="<<x<<" "; #define rep(i,a,b) for(int i=a;i<(b);++i) #define

今日SGU 5.12

SGU 149 题意:求每一个点的距离最远距离的点的长度 收获:次大值和最大值,dfs #include<bits/stdc++.h> #define de(x) cout<<#x<<"="<<x<<endl; #define dd(x) cout<<#x<<"="<<x<<" "; #define rep(i,a,b) for(int i

今日SGU 5.14

//SGU 131 还没完全想清楚 留坑 SGU 259 题意:一个机器处理n个任务,每个任务有时间t和传送时间l 收获:贪心 #include<bits/stdc++.h> #define de(x) cout<<#x<<"="<<x<<endl; #define dd(x) cout<<#x<<"="<<x<<" "; #define

今日SGU 5.15

最近事情好多,数据库作业,没天要学2个小时java,所以更新的sgu就比较少了 SGU 131 题意:给你两种小块一种,1*1,一种2*2-1*1,问你填满一个m*n的矩形有多少钟方法,n和m小于等于9, 收获:状态压缩,每一行都最多由上一行转移过来,因为上一行,那么最多有7情况,详情看代码 #include<bits/stdc++.h> #define de(x) cout<<#x<<"="<<x<<endl; #defin

今日SGU 5.18

SGU 125 题意:给你一个数组b[i][j],表示i,j的四周有多少个数字大于它的,问你能不能构造出一个a矩形 收获:dfs  + 剪枝 一行一行的dfs,然后第一行去枚举0-9,下一行判断当前选择能否满足上一行对应列的情况,可以的话就继续dfs #include<bits/stdc++.h> #define de(x) cout<<#x<<"="<<x<<endl; #define dd(x) cout<<#

今日SGU 5.19

SGU 142 题意:给你一个长度为n的串(由a,b组成),让你找出一个串不是n的子串,长度最下 收获:思维题,思路在代码里 #include<bits/stdc++.h> #define de(x) cout<<#x<<"="<<x<<endl; #define dd(x) cout<<#x<<"="<<x<<" "; #define r

今日SGU 5.20

SGU 404 题意:.. 收获:取模 #include<bits/stdc++.h> #define de(x) cout<<#x<<"="<<x<<endl; #define dd(x) cout<<#x<<"="<<x<<" "; #define rep(i,a,b) for(int i=a;i<(b);++i) #define

今日SGU 5.

SGU 122 题意:给你n个人,每个人有大于 N / 2(向上取整)的朋友,问你1这个人有一个书,每个人都想看,只能从朋友之间传递,然后最后回到了1这个人,问你 是否有解,然后有解输出路径 收获:哈密尔顿路 一:Dirac定理(充分条件) 设一个无向图中有N个顶点,若所有顶点的度数大于等于N/2,则哈密顿回路一定存在.(N/2指的是?N/2?,向上取整) 二:基本的必要条件 设图G=<V, E>是哈密顿图,则对于v的任意一个非空子集S,若以|S|表示S中元素的数目,G-S表示G中删除了S中的

今日小结 4.29

布局layout,视图view  OK 1.布局layout是盛放视图view的容器 再说一遍,视图view是放在layout布局中的! 通过改变布局大小来改变视图大小 布局layout的参数一般是大小,位置,内容(内部视图控件)的排列方式(水平,垂直等) 所以在视图控件(比如Button)的设置中,关于layout_的都是布局的参数,比如 layout_width 是改变Button所在的布局的宽度的,如果选择matchparent则是充满整个布局 2.LayoutInflate 常用于动态加