码迷,mamicode.com
首页 > 其他好文 > 详细

ICPC Asia Nanning 2017

时间:2019-09-04 09:17:05      阅读:66      评论:0      收藏:0      [点我收藏+]

标签:http   eof   abi   col   最小点覆盖   导致   字符串   def   for   

比赛地址:https://www.jisuanke.com/contest/3107?view=challenges

A、签到,大概就是输出几个字符串

#include <bits/stdc++.h>
using namespace std;

int t,n;

int main(){
    scanf("%d",&t);
    while(t--){
        scanf("%d",&n);
        for(int i=1;i<=n;++i)
            printf("Abiyoyo, Abiyoyo.\n");
        printf("Abiyoyo, yo yoyo yo yoyo.\n");
        printf("Abiyoyo, yo yoyo yo yoyo.\n");
    }
    return 0;
}

F、签到2.0,上大数板子搞一下,猜了个结论:答案为最大的k使得2^k<=n

后来跟rhy讨论了下,每轮淘汰掉第1、3、5、7、9个人的话,相当于不断把n除以2,最后留下的必定是一个2^k

#include <bits/stdc++.h>
#define MAXN 9999
#define MAXSIZE 1000
#define DLEN 4
using namespace std;

class BigNum
{
private:
    int a[210];
    int len;
public:
    BigNum(){ len = 1;memset(a,0,sizeof(a)); }
    void XD();
    BigNum(const int);
    BigNum(const long long int);
    BigNum(const char*);
    BigNum(const string &);
    BigNum(const BigNum &);
    BigNum &operator = (const BigNum &);
    BigNum &operator = (const int &);
    BigNum &operator = (const long long int &);

    friend istream& operator >> (istream&,  BigNum&);
    friend ostream& operator << (ostream&,  BigNum&);

    template<typename T> BigNum operator << (const T &) const;
    template<typename T> BigNum operator >> (const T &) const;

    BigNum operator + (const BigNum &) const;
    BigNum operator - (const BigNum &) const;
    BigNum operator * (const BigNum &) const;
    bool   operator > (const BigNum& b)const;
    bool   operator < (const BigNum& b) const;
    bool   operator == (const BigNum& b) const;
    template<typename T> BigNum operator / (const T  &) const;
    template<typename T> BigNum operator ^ (const T  &) const;
    template<typename T> T    operator % (const T  &) const;

    template<typename T> BigNum operator + (const T& b) const {BigNum t = b; t = *this + t; return t;}
    template<typename T> BigNum operator - (const T& b) const {BigNum t = b; t = *this - t; return t;}
    template<typename T> BigNum operator * (const T& b) const {BigNum t = b; t = (*this) * t; return t;}
    template<typename T> bool   operator < (const T& b) const {BigNum t = b; return ((*this) < t);}
    template<typename T> bool   operator > (const T& b) const {BigNum t = b; return ((*this) > t);}
    template<typename T> bool   operator == (const T& b) const {BigNum t = b; return ((*this) == t);}

    bool   operator <= (const BigNum& b) const {return (*this) < b || (*this) == b;}
    bool   operator >= (const BigNum& b) const {return (*this) > b || (*this) == b;}
    bool   operator != (const BigNum& b) const {return !((*this) == b);}

    template<typename T> bool   operator >= (const T& b) const {BigNum t = b; return !((*this) < t);}
    template<typename T> bool   operator <= (const T& b) const {BigNum t = b; return !((*this) > t);}
    template<typename T> bool   operator != (const T& b) const {BigNum t = b; return !((*this) == t);}

    BigNum& operator += (const BigNum& b) {*this = *this + b; return *this;}
    BigNum& operator -= (const BigNum& b) {*this = *this - b; return *this;}
    BigNum& operator *= (const BigNum& b) {*this = *this * b; return *this;}
    template<typename T> BigNum& operator /= (const T& b) {*this = *this/b; return *this;}
    template<typename T> BigNum& operator %= (const T& b) {*this = *this%b; return *this;}
    template<typename T> BigNum& operator += (const T& b) {*this = *this+b; return *this;}
    template<typename T> BigNum& operator -= (const T& b) {*this = *this-b; return *this;}
    template<typename T> BigNum& operator *= (const T& b) {*this = *this*b; return *this;}
    template<typename T> BigNum& operator ^= (const T& b) {*this = *this^b; return *this;}

    BigNum operator ++ (int) {BigNum t = *this; *this += 1; return t;}
    BigNum operator -- (int) {BigNum t = *this; *this -= 1; return t;}
    BigNum& operator -- () {*this -= 1; return *this;}
    BigNum& operator ++ () {*this += 1; return *this;}

    template<typename T> BigNum& operator <<= (const T& b) {*this = *this << b; return *this;}
    template<typename T> BigNum& operator >>= (const T& b) {*this = *this >> b; return *this;}

    template<typename T> BigNum friend operator + (const T& a, const BigNum& b) {BigNum t = a; t = t + a; return t;}
    template<typename T> BigNum friend operator - (const T& a, const BigNum& b) {BigNum t = a; t = t - b; return t;}
    template<typename T> BigNum friend operator * (const T& a, const BigNum& b) {BigNum t = a; t = t * b; return t;}
    template<typename T> friend bool operator < (const T& a, const BigNum& b) {return b > a;}
    template<typename T> friend bool operator > (const T& a, const BigNum& b) {return b < a;}
    template<typename T> friend bool operator <= (const T& a, const BigNum& b) {return b >= a;}
    template<typename T> friend bool operator >= (const T& a, const BigNum& b) {return b <= a;}
    template<typename T> friend bool operator == (const T& a, const BigNum& b) {return b == a;}
    template<typename T> friend bool operator != (const T& a, const BigNum& b) {return b != a;}

    void print();    
    int Size();        
    int the_first();  
    int the_last();      
    int to_int();   
    long long int to_long();
    string to_String();
};

BigNum::BigNum(const int b) 
{
    int c,d = b;
    len = 0;
    memset(a,0,sizeof(a));
    while(d > MAXN){
        c = d - (d / (MAXN+1)) * (MAXN+1);
        d = d / (MAXN+1);
        a[len++] = c;
    }
    a[len++] = d;
}
BigNum::BigNum(const long long int b)
{
    long long int c,d = b;
    len = 0;
    memset(a,0,sizeof(a));
    while(d > MAXN){
        c = d - (d / (MAXN+1)) * (MAXN+1);
        d = d / (MAXN+1);
        a[len++] = c;
    }
    a[len++] = d;
}
BigNum::BigNum(const string& s)
{
    int t,k,index,l,i;
    memset(a,0,sizeof(a));
    l = s.size();
    len = l/DLEN;
    if(l%DLEN)
        len++;
    index = 0;
    for(i = l-1; i >=0 ;i -= DLEN){
        t = 0;
        k = i-DLEN+1;
        if(k < 0) k = 0;
        for(int j = k; j <= i; j++)
            t = t*10 + s[j]-0;
        a[index++] = t;
    }
}
BigNum::BigNum(const char* s) 
{
    int t,k,index,l,i;
    memset(a,0,sizeof(a));
    l = strlen(s);
    len = l/DLEN;
    if(l%DLEN)
        len++;
    index = 0;
    for(i = l-1; i >= 0; i -= DLEN){
        t = 0;
        k = i - DLEN + 1;
        if(k < 0) k = 0;
        for(int j = k; j <= i; j++)
            t = t*10 + s[j] - 0;
        a[index++] = t;
    }
}
BigNum::BigNum(const BigNum & b) : len(b.len) 
{
    memset(a,0,sizeof(a));
    for(int i = 0 ; i < len ; i++)
        a[i] = b.a[i];
}
BigNum & BigNum::operator = (const BigNum& n) 
{
    len = n.len;
    memset(a,0,sizeof(a));
    for(int i = 0 ; i < len ; i++)
        a[i] = n.a[i];
    return *this;
}
BigNum & BigNum::operator = (const int& num)
{
    BigNum t(num);
    *this = t;
    return *this;
}
BigNum & BigNum::operator = (const long long int& num)
{
    BigNum t(num);
    *this = t;
    return *this;
}
istream& operator >> (istream & in, BigNum & b) 
{
    char ch[MAXSIZE*4];
    int i = -1;
    in>>ch;
    int l = strlen(ch);
    int cnt = 0, sum = 0;
    for(i = l-1; i >= 0; ){
        sum = 0;
        int t = 1;
        for(int j = 0; j < 4 && i >= 0; j++,i--,t *= 10)
            sum += (ch[i]-0)*t;
        b.a[cnt] = sum;
        cnt++;
    }
    b.len = cnt++;
    return in;

}
ostream& operator << (ostream& out, BigNum& b)
{
    int i;
    cout << b.a[b.len - 1];
    for(i = b.len - 2 ; i >= 0 ; i--){
        cout.width(DLEN);
        cout.fill(0);
        cout << b.a[i];
    }
    return out;
}

template<typename T> BigNum BigNum::operator << (const T& b) const
{
    T temp = 1;
    for(int i = 0; i < b; i++)
        temp *= 2;
    BigNum t = (*this) * temp;
    return t;
}
template<typename T> BigNum BigNum::operator >> (const T& b) const
{
    T temp = 1;
    for(int i = 0; i < b; i++)
        temp *= 2;
    BigNum t = (*this) / temp;
    return t;
}

BigNum BigNum::operator + (const BigNum& b) const
{
    BigNum t(*this);
    int i,big;
    big = b.len > len ? b.len : len;
    for(i = 0 ; i < big ; i++){
        t.a[i] += b.a[i];
        if(t.a[i] > MAXN){
            t.a[i + 1]++;
            t.a[i] -=MAXN+1;
        }
    }
    if(t.a[big] != 0)
        t.len = big + 1;
    else
        t.len = big;
    return t;
}
BigNum BigNum::operator - (const BigNum& b) const 
{
    int i,j,big;
    bool flag;
    BigNum t1,t2;
    if(*this>b){
        t1 = *this;
        t2 = b;
        flag = 0;
    }
    else{
        t1 = b;
        t2 = *this;
        flag = 1;
    }
    big = t1.len;
    for(i = 0 ; i < big ; i++){
        if(t1.a[i] < t2.a[i]){
            j = i + 1;
            while(t1.a[j] == 0)
                j++;
            t1.a[j--]--;
            while(j > i)
                t1.a[j--] += MAXN;
            t1.a[i] += MAXN + 1 - t2.a[i];
        }
        else
            t1.a[i] -= t2.a[i];
    }
    t1.len = big;
    while(t1.a[t1.len - 1] == 0 && t1.len > 1){
        t1.len--;
        big--;
    }
    if(flag)
        t1.a[big-1] = 0-t1.a[big-1];
    return t1;
}

BigNum BigNum::operator * (const BigNum& b) const  
{
    BigNum ret;
    int i,j,up;
    int temp,temp1;
    for(i = 0 ; i < len ; i++){
        up = 0;
        for(j = 0 ; j < b.len ; j++){
            temp = a[i] * b.a[j] + ret.a[i + j] + up;
            if(temp > MAXN){
                temp1 = temp - temp / (MAXN + 1) * (MAXN + 1);
                up = temp / (MAXN + 1);
                ret.a[i + j] = temp1;
            }
            else{
                up = 0;
                ret.a[i + j] = temp;
            }
        }
        if(up != 0) ret.a[i + j] = up;
    }
    ret.len = i + j;
    while(ret.a[ret.len - 1] == 0 && ret.len > 1)
        ret.len--;
    return ret;
}
template<typename T> BigNum BigNum::operator / (const T& b) const
{
    BigNum ret;
    T i,down = 0;
    for(i = len - 1 ; i >= 0 ; i--){
        ret.a[i] = (a[i] + down * (MAXN + 1)) / b;
        down = a[i] + down * (MAXN + 1) - ret.a[i] * b;
    }
    ret.len = len;
    while(ret.a[ret.len - 1] == 0 && ret.len > 1)
        ret.len--;
    return ret;
}
template<typename T> T BigNum::operator % (const T& b) const
{
    T i,d=0;
    for (i = len-1; i>=0; i--){
        d = ((d * (MAXN+1))% b + a[i])% b;
    }
    return d;
}


template<typename T> BigNum BigNum::operator^(const T& n) const   
{
    BigNum t,ret(1);
    int i;
    if(n < 0) return 0;
    if(n == 0)
        return 1;
    if(n == 1)
        return *this;
    int m = n;
    while(m > 1){
        t =* this;
        for(i = 1; (i<<1) <= m;i <<= 1)
            t = t*t;
        m-=i;
        ret=ret*t;
        if(m == 1) ret = ret * (*this);
    }
    return ret;
}

bool BigNum::operator > (const BigNum& b) const 
{
    int tot;
    if(len > b.len)
        return true;
    else if(len == b.len){
        tot = len - 1;
        while(a[tot] == b.a[tot] && tot >= 0)
            tot--;
        if(tot >= 0 && a[tot] > b.a[tot])
            return true;
        else
            return false;
    }
    else
        return false;
}

bool BigNum::operator < (const BigNum& b) const
{
    int tot;
    if(len > b.len)
        return false;
    else if(len == b.len){
        tot = len - 1;
        while(a[tot] == b.a[tot] && tot >= 0)
            tot--;
        if(tot >= 0 && a[tot] > b.a[tot])
            return false;
        else
            return true;//
    }
    else
        return true;
}

bool BigNum::operator == (const BigNum& b) const
{
    int tot = len-1;
    if(len != b.len)
        return false;
    while(a[tot] == b.a[tot] && tot >= 0)
        tot--;
    if(tot < 0)
        return true;
    return false;
}

void BigNum::print() 
{
    int i;
    cout << a[len - 1];
    for(i = len-2; i >= 0; i--){
        cout.width(DLEN);
        cout.fill(0);
        cout << a[i];
    }
    cout << endl;
}
int BigNum::Size()
{
    int t = a[len-1],cnt = 0;
    while(t){ t /= 10; cnt++; }
    cnt += (len-1)*4;
    return cnt;
}
int BigNum::the_first()
{
    int t = a[len-1];
    while(t > 10){ t /= 10;}
    return t;
}
int BigNum::the_last()
{
    int t = a[0];
    return t%10;
}
int BigNum::to_int()
{
    int i,num;
    num = a[len-1];
    for(i = len-2; i >= 0; i--)
        num = num*(MAXN+1) + a[i];
    return num;
}
long long int BigNum::to_long()
{
    int i;
    long long int num;
    num = a[len-1];
    for(i = len-2; i >= 0; i--)
        num = num*(MAXN+1) + a[i];
    return num;
}

int t;
BigNum in,out;

int main(){
    cin>>t;
    while(t--){
        cin>>in;
        out=1;
        while(out<=in)
            out*=2;
        out/=2;
        out.print();
    }
    return 0;
}

 L、签到题3.0,又上大数板子搞一搞,打了个表看的规律a[i]=6*a[i-1]-a[i-2]+2,大概打到300左右答案就超过数据范围了,之后直接二分查询就完事

#include <bits/stdc++.h>
#define MAXN 9999
#define MAXSIZE 1000
#define DLEN 4
using namespace std;

class BigNum
{
private:
    int a[210];
    int len;
public:
    BigNum(){ len = 1;memset(a,0,sizeof(a)); }
    void XD();
    BigNum(const int);
    BigNum(const long long int);
    BigNum(const char*);
    BigNum(const string &);
    BigNum(const BigNum &);
    BigNum &operator = (const BigNum &);
    BigNum &operator = (const int &);
    BigNum &operator = (const long long int &);

    friend istream& operator >> (istream&,  BigNum&);
    friend ostream& operator << (ostream&,  BigNum&);

    template<typename T> BigNum operator << (const T &) const;
    template<typename T> BigNum operator >> (const T &) const;

    BigNum operator + (const BigNum &) const;
    BigNum operator - (const BigNum &) const;
    BigNum operator * (const BigNum &) const;
    bool   operator > (const BigNum& b)const;
    bool   operator < (const BigNum& b) const;
    bool   operator == (const BigNum& b) const;
    template<typename T> BigNum operator / (const T  &) const;
    template<typename T> BigNum operator ^ (const T  &) const;
    template<typename T> T    operator % (const T  &) const;

    template<typename T> BigNum operator + (const T& b) const {BigNum t = b; t = *this + t; return t;}
    template<typename T> BigNum operator - (const T& b) const {BigNum t = b; t = *this - t; return t;}
    template<typename T> BigNum operator * (const T& b) const {BigNum t = b; t = (*this) * t; return t;}
    template<typename T> bool   operator < (const T& b) const {BigNum t = b; return ((*this) < t);}
    template<typename T> bool   operator > (const T& b) const {BigNum t = b; return ((*this) > t);}
    template<typename T> bool   operator == (const T& b) const {BigNum t = b; return ((*this) == t);}

    bool   operator <= (const BigNum& b) const {return (*this) < b || (*this) == b;}
    bool   operator >= (const BigNum& b) const {return (*this) > b || (*this) == b;}
    bool   operator != (const BigNum& b) const {return !((*this) == b);}

    template<typename T> bool   operator >= (const T& b) const {BigNum t = b; return !((*this) < t);}
    template<typename T> bool   operator <= (const T& b) const {BigNum t = b; return !((*this) > t);}
    template<typename T> bool   operator != (const T& b) const {BigNum t = b; return !((*this) == t);}

    BigNum& operator += (const BigNum& b) {*this = *this + b; return *this;}
    BigNum& operator -= (const BigNum& b) {*this = *this - b; return *this;}
    BigNum& operator *= (const BigNum& b) {*this = *this * b; return *this;}
    template<typename T> BigNum& operator /= (const T& b) {*this = *this/b; return *this;}
    template<typename T> BigNum& operator %= (const T& b) {*this = *this%b; return *this;}
    template<typename T> BigNum& operator += (const T& b) {*this = *this+b; return *this;}
    template<typename T> BigNum& operator -= (const T& b) {*this = *this-b; return *this;}
    template<typename T> BigNum& operator *= (const T& b) {*this = *this*b; return *this;}
    template<typename T> BigNum& operator ^= (const T& b) {*this = *this^b; return *this;}

    BigNum operator ++ (int) {BigNum t = *this; *this += 1; return t;}
    BigNum operator -- (int) {BigNum t = *this; *this -= 1; return t;}
    BigNum& operator -- () {*this -= 1; return *this;}
    BigNum& operator ++ () {*this += 1; return *this;}

    template<typename T> BigNum& operator <<= (const T& b) {*this = *this << b; return *this;}
    template<typename T> BigNum& operator >>= (const T& b) {*this = *this >> b; return *this;}

    template<typename T> BigNum friend operator + (const T& a, const BigNum& b) {BigNum t = a; t = t + a; return t;}
    template<typename T> BigNum friend operator - (const T& a, const BigNum& b) {BigNum t = a; t = t - b; return t;}
    template<typename T> BigNum friend operator * (const T& a, const BigNum& b) {BigNum t = a; t = t * b; return t;}
    template<typename T> friend bool operator < (const T& a, const BigNum& b) {return b > a;}
    template<typename T> friend bool operator > (const T& a, const BigNum& b) {return b < a;}
    template<typename T> friend bool operator <= (const T& a, const BigNum& b) {return b >= a;}
    template<typename T> friend bool operator >= (const T& a, const BigNum& b) {return b <= a;}
    template<typename T> friend bool operator == (const T& a, const BigNum& b) {return b == a;}
    template<typename T> friend bool operator != (const T& a, const BigNum& b) {return b != a;}

    void print();    
    int Size();        
    int the_first();  
    int the_last();      
    int to_int();   
    long long int to_long();
    string to_String();
};

BigNum::BigNum(const int b) 
{
    int c,d = b;
    len = 0;
    memset(a,0,sizeof(a));
    while(d > MAXN){
        c = d - (d / (MAXN+1)) * (MAXN+1);
        d = d / (MAXN+1);
        a[len++] = c;
    }
    a[len++] = d;
}
BigNum::BigNum(const long long int b)
{
    long long int c,d = b;
    len = 0;
    memset(a,0,sizeof(a));
    while(d > MAXN){
        c = d - (d / (MAXN+1)) * (MAXN+1);
        d = d / (MAXN+1);
        a[len++] = c;
    }
    a[len++] = d;
}
BigNum::BigNum(const string& s)
{
    int t,k,index,l,i;
    memset(a,0,sizeof(a));
    l = s.size();
    len = l/DLEN;
    if(l%DLEN)
        len++;
    index = 0;
    for(i = l-1; i >=0 ;i -= DLEN){
        t = 0;
        k = i-DLEN+1;
        if(k < 0) k = 0;
        for(int j = k; j <= i; j++)
            t = t*10 + s[j]-0;
        a[index++] = t;
    }
}
BigNum::BigNum(const char* s) 
{
    int t,k,index,l,i;
    memset(a,0,sizeof(a));
    l = strlen(s);
    len = l/DLEN;
    if(l%DLEN)
        len++;
    index = 0;
    for(i = l-1; i >= 0; i -= DLEN){
        t = 0;
        k = i - DLEN + 1;
        if(k < 0) k = 0;
        for(int j = k; j <= i; j++)
            t = t*10 + s[j] - 0;
        a[index++] = t;
    }
}
BigNum::BigNum(const BigNum & b) : len(b.len) 
{
    memset(a,0,sizeof(a));
    for(int i = 0 ; i < len ; i++)
        a[i] = b.a[i];
}
BigNum & BigNum::operator = (const BigNum& n) 
{
    len = n.len;
    memset(a,0,sizeof(a));
    for(int i = 0 ; i < len ; i++)
        a[i] = n.a[i];
    return *this;
}
BigNum & BigNum::operator = (const int& num)
{
    BigNum t(num);
    *this = t;
    return *this;
}
BigNum & BigNum::operator = (const long long int& num)
{
    BigNum t(num);
    *this = t;
    return *this;
}
istream& operator >> (istream & in, BigNum & b) 
{
    char ch[MAXSIZE*4];
    int i = -1;
    in>>ch;
    int l = strlen(ch);
    int cnt = 0, sum = 0;
    for(i = l-1; i >= 0; ){
        sum = 0;
        int t = 1;
        for(int j = 0; j < 4 && i >= 0; j++,i--,t *= 10)
            sum += (ch[i]-0)*t;
        b.a[cnt] = sum;
        cnt++;
    }
    b.len = cnt++;
    return in;

}
ostream& operator << (ostream& out, BigNum& b)
{
    int i;
    cout << b.a[b.len - 1];
    for(i = b.len - 2 ; i >= 0 ; i--){
        cout.width(DLEN);
        cout.fill(0);
        cout << b.a[i];
    }
    return out;
}

template<typename T> BigNum BigNum::operator << (const T& b) const
{
    T temp = 1;
    for(int i = 0; i < b; i++)
        temp *= 2;
    BigNum t = (*this) * temp;
    return t;
}
template<typename T> BigNum BigNum::operator >> (const T& b) const
{
    T temp = 1;
    for(int i = 0; i < b; i++)
        temp *= 2;
    BigNum t = (*this) / temp;
    return t;
}

BigNum BigNum::operator + (const BigNum& b) const
{
    BigNum t(*this);
    int i,big;
    big = b.len > len ? b.len : len;
    for(i = 0 ; i < big ; i++){
        t.a[i] += b.a[i];
        if(t.a[i] > MAXN){
            t.a[i + 1]++;
            t.a[i] -=MAXN+1;
        }
    }
    if(t.a[big] != 0)
        t.len = big + 1;
    else
        t.len = big;
    return t;
}
BigNum BigNum::operator - (const BigNum& b) const 
{
    int i,j,big;
    bool flag;
    BigNum t1,t2;
    if(*this>b){
        t1 = *this;
        t2 = b;
        flag = 0;
    }
    else{
        t1 = b;
        t2 = *this;
        flag = 1;
    }
    big = t1.len;
    for(i = 0 ; i < big ; i++){
        if(t1.a[i] < t2.a[i]){
            j = i + 1;
            while(t1.a[j] == 0)
                j++;
            t1.a[j--]--;
            while(j > i)
                t1.a[j--] += MAXN;
            t1.a[i] += MAXN + 1 - t2.a[i];
        }
        else
            t1.a[i] -= t2.a[i];
    }
    t1.len = big;
    while(t1.a[t1.len - 1] == 0 && t1.len > 1){
        t1.len--;
        big--;
    }
    if(flag)
        t1.a[big-1] = 0-t1.a[big-1];
    return t1;
}

BigNum BigNum::operator * (const BigNum& b) const  
{
    BigNum ret;
    int i,j,up;
    int temp,temp1;
    for(i = 0 ; i < len ; i++){
        up = 0;
        for(j = 0 ; j < b.len ; j++){
            temp = a[i] * b.a[j] + ret.a[i + j] + up;
            if(temp > MAXN){
                temp1 = temp - temp / (MAXN + 1) * (MAXN + 1);
                up = temp / (MAXN + 1);
                ret.a[i + j] = temp1;
            }
            else{
                up = 0;
                ret.a[i + j] = temp;
            }
        }
        if(up != 0) ret.a[i + j] = up;
    }
    ret.len = i + j;
    while(ret.a[ret.len - 1] == 0 && ret.len > 1)
        ret.len--;
    return ret;
}
template<typename T> BigNum BigNum::operator / (const T& b) const
{
    BigNum ret;
    T i,down = 0;
    for(i = len - 1 ; i >= 0 ; i--){
        ret.a[i] = (a[i] + down * (MAXN + 1)) / b;
        down = a[i] + down * (MAXN + 1) - ret.a[i] * b;
    }
    ret.len = len;
    while(ret.a[ret.len - 1] == 0 && ret.len > 1)
        ret.len--;
    return ret;
}
template<typename T> T BigNum::operator % (const T& b) const
{
    T i,d=0;
    for (i = len-1; i>=0; i--){
        d = ((d * (MAXN+1))% b + a[i])% b;
    }
    return d;
}


template<typename T> BigNum BigNum::operator^(const T& n) const   
{
    BigNum t,ret(1);
    int i;
    if(n < 0) return 0;
    if(n == 0)
        return 1;
    if(n == 1)
        return *this;
    int m = n;
    while(m > 1){
        t =* this;
        for(i = 1; (i<<1) <= m;i <<= 1)
            t = t*t;
        m-=i;
        ret=ret*t;
        if(m == 1) ret = ret * (*this);
    }
    return ret;
}

bool BigNum::operator > (const BigNum& b) const 
{
    int tot;
    if(len > b.len)
        return true;
    else if(len == b.len){
        tot = len - 1;
        while(a[tot] == b.a[tot] && tot >= 0)
            tot--;
        if(tot >= 0 && a[tot] > b.a[tot])
            return true;
        else
            return false;
    }
    else
        return false;
}

bool BigNum::operator < (const BigNum& b) const
{
    int tot;
    if(len > b.len)
        return false;
    else if(len == b.len){
        tot = len - 1;
        while(a[tot] == b.a[tot] && tot >= 0)
            tot--;
        if(tot >= 0 && a[tot] > b.a[tot])
            return false;
        else
            return true;//
    }
    else
        return true;
}

bool BigNum::operator == (const BigNum& b) const
{
    int tot = len-1;
    if(len != b.len)
        return false;
    while(a[tot] == b.a[tot] && tot >= 0)
        tot--;
    if(tot < 0)
        return true;
    return false;
}

void BigNum::print() 
{
    int i;
    cout << a[len - 1];
    for(i = len-2; i >= 0; i--){
        cout.width(DLEN);
        cout.fill(0);
        cout << a[i];
    }
    cout << endl;
}
int BigNum::Size()
{
    int t = a[len-1],cnt = 0;
    while(t){ t /= 10; cnt++; }
    cnt += (len-1)*4;
    return cnt;
}
int BigNum::the_first()
{
    int t = a[len-1];
    while(t > 10){ t /= 10;}
    return t;
}
int BigNum::the_last()
{
    int t = a[0];
    return t%10;
}
int BigNum::to_int()
{
    int i,num;
    num = a[len-1];
    for(i = len-2; i >= 0; i--)
        num = num*(MAXN+1) + a[i];
    return num;
}
long long int BigNum::to_long()
{
    int i;
    long long int num;
    num = a[len-1];
    for(i = len-2; i >= 0; i--)
        num = num*(MAXN+1) + a[i];
    return num;
}

int t;
BigNum a,ans[305];

int main(){
    ans[0]=0;
    ans[1]=3;
    for(int i=2;i<=300;++i)
        ans[i]=6*ans[i-1]-ans[i-2]+2;
    cin>>t;
    while(t--){
        cin>>a;
        int p=lower_bound(ans+1,ans+1+300,a)-ans;
        ans[p].print();
    }
    return 0;
}

J、SB思维题,细节巨多,想半天没整明白,问了ly才搞过

大意是给你一个2*n的矩阵,问你能不能重新安排数字的顺序,使得任意两个相邻的数字和都不是3的倍数。

先按数字对3取余的余数把数字分成0,1,2三类,显然0和0、1和2不能摆在一起,那么不妨就这样反着考虑,什么情况下会输出no

感性地说,如果0太多,必定会有两个0相邻,而0太少则会导致1和2相邻

明确一点,摆成下面这两种形式是绝对没问题的:

1   1   1   1

1   1   1   1

2   2   2   2

2   2   2   2

那么剩下的问题就成了对0的处理。

如果0超过n个,不管你如何交错着放,一定会有0和0相邻,输出no

如果0只有一个,并且1和2的个数都不为0,不管你怎么分割,1和2必然相邻,因为把1和2分割开来至少需要两个0

如果0有两个,要考虑一种特别的情况如下:

1   0   2

0   1   2

这种情况下不论你如何安排都不能满足条件。

为什么会导致这种情况呢?上面说了把1和2分割开来至少需要两个0,这是有条件的:

如下图(星号代表未知位置):

1   *   *

1   1   *

这时候用两个0把1和2隔开是完全没有问题的,因为这两个0不会相邻

但是下面这种情况就不一样了:

1   1   *

1   1   *

这时候用两个0就不能成功分割,因为这两个0必然相邻。

0大于等于3个的情况更好理解了,摆成下面这样就一定能成:

*   0   *   0

0   *   0   *

#include <bits/stdc++.h>
using namespace std;

int t,n,a,b;
int cnt[3];

int main(){
    scanf("%d",&t);
    while(t--){
        scanf("%d",&n);
        memset(cnt,0,sizeof(cnt));
        for(int i=1;i<=n;++i) scanf("%d",&a),cnt[a%3]++;
        for(int i=1;i<=n;++i) scanf("%d",&b),cnt[b%3]++;
        if(cnt[1]==2*n||cnt[2]==2*n){printf("YES\n");continue;}
        if(cnt[0]>n){printf("NO\n");continue;}
        if((cnt[0]<=1&&cnt[1]&&cnt[2])||(cnt[0]==2&&cnt[1]%2==0)) printf("NO\n");
        else printf("YES\n");
    }
    return 0;
}

M、题意是求一个最大的点集合,使得点集合中的任意两个点都相互不可达。

感觉挺板子的,先floyd求传递闭包,再跑一遍二分图匹配把最小点覆盖算出来完事

#include <bits/stdc++.h>
using namespace std;

int t,n,m,u,v;
int g[105][105];
bool vis[105];
int lk[105];

void floyd(){
    for(int k=1;k<=n;++k)
        for(int i=1;i<=n;++i)
            for(int j=1;j<=n;++j)
                g[i][j]=g[i][j]||(g[i][k]&&g[k][j]);
}

bool dfs(int x){
    for(int i=1;i<=n;++i){
        if(g[x][i]==1&&!vis[i]){
            vis[i]=1;
            if(lk[i]==0||dfs(lk[i])){
                lk[i]=x;
                return 1;
            }
        }
    }
    return 0;
}

int main(){
    scanf("%d",&t);
    while(t--){
        scanf("%d%d",&n,&m);
        memset(g,0,sizeof(g));
        memset(lk,0,sizeof(lk));
        for(int i=1;i<=m;++i){
            scanf("%d%d",&u,&v);
            g[u][v]=1;
        }
        floyd();
//        for(int i=1;i<=n;++i) for(int j=1;j<=n;++j) cout<<g[i][j]<<" \n"[j==n];
        int ans=0;
        for(int i=1;i<=n;++i){
            memset(vis,0,sizeof(vis));
            if(dfs(i)) ++ans;    
        }
        printf("%d\n",n-ans);
    }
    return 0;
}

 

ICPC Asia Nanning 2017

标签:http   eof   abi   col   最小点覆盖   导致   字符串   def   for   

原文地址:https://www.cnblogs.com/oneman233/p/11456683.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!