• 个人简介

    此人不懒,但什么都没有写。

    代码暂存区
    #include <bits/stdc++.h>
    #define int long long
    using namespace std;
    int a[300100];
    char c[300100];
    int sf[300100];
    int bf[300100];
    int sb[300100];
    int bb[300100];
    signed main(){
    int n, m;
    cin >> n >> m;
    for (int i = 1; i <= 300000; i++){
    sf[i] = 1e18;
    sb[i] = 1e18;
    bf[i] = -1e18;
    bb[i] = -1e18;
    }
    int x = 0;
    for (int i = 1; i <= n; i++){
    cin >> c[i];
    if (c[i] == '-'){
    x--;
    }
    else{
    x++;
    }
    a[i] = x;
    sf[i] = min(sf[i - 1], x);
    bf[i] = max(bf[i - 1], x);
    }
    sb[n + 1] = 1e18;
    bb[n + 1] = -1e18;
    for (int i = n; i >= 1; i--){
    sb[i] = min(sb[i + 1], a[i]);
    bb[i] = max(bb[i + 1], a[i]);
    }
    while (m--){
    int l, r;
    cin >> l >> r;
    cout << max(bf[l - 1], bb[r + 1] - (a[r] - a[l - 1])) - min(sf[l - 1], sb[r + 1] - (a[r] - a[l - 1])) + 1 << endl;
    }
    return 0;
    }
    

    还是写了

    #include <bits/stdc++.h>
    #pragma GCC optimize(3, "Ofast", "inline")
    #pragma GCC optimize(2, "Ofast", "inline")
    #pragma GCC optimize(1, "Ofast", "inline")
    using namespace std;
    int main()
    {
        return 0;
    }
    

    图论编辑器

    不同的时间复杂度对比

    2023tyoi0647给的实用模版

    实用图形工具

    我只不过积分了一条直线而已

    一个圆

    这是什么神奇的网址呢


    我写的计算器

    #include <iostream>
    #include <iomanip>
    #include <math.h>
    #include <cmath>
    #include <time.h>
    #include <stdlib.h>
    #include <cstdio>
    #include <cmath>
    #include <string.h>
    #include <string>
    #include <cstring>
    #include <vector>
    #include <stack>
    #include <map>
    using namespace std;
    #define back return
    int d[8][2] = {{0, -1}, {-1, 0}, {0, 1}, {1, 0}, {-1, -1}, {1, -1}, {1, 1}, {-1, 1}};
    namespace std
    {
        std::ostream &endl(std::ostream &os)
        {
            os.put(os.widen('\n'));
            return os;
        }
    }
    namespace str
    {
        char *itoa(int a, char *c, int n = 10)
        {
            int a1[100];
            int m = 0;
            if (n == 10)
            {
                while (a != 0)
                {
                    a1[m] = a % 10;
                    c[m] = a1[m] + '0';
                    a /= 10;
                    m++;
                }
            }
            else
            {
                while (a != 0)
                {
                    c[m] = a % n + '0';
                    if (c[m] > '9')
                    {
                        c[m] += 7;
                    }
                    a /= n;
                    m++;
                }
            }
            for (int i = 0, j = m - 1; i < j; i++, j--)
            {
                char k = c[i];
                c[i] = c[j];
                c[j] = k;
            }
            c[m] = '\0';
            return c;
        }
        long long atoi(char *c, int m = 10)
        {
            long long n = 0;
            long long a = 1;
            long long l = strlen(c);
            if (c[0] == '-')
            {
                for (int i = l - 1; i >= 0; i--)
                {
                    n += ((c[i] - (c[i] >= 'A' ? 'A' - 10 : '0')) * a);
                    a *= m;
                }
                n *= -1;
            }
            else
            {
                for (int i = l - 1; i >= 0; i--)
                {
                    n += ((c[i] - (c[i] >= 'A' ? 'A' - 10 : '0')) * a);
                    a *= m;
                }
            }
            return n;
        }
        void clean(char *c)
        {
            int l = strlen(c);
            for (int i = 0; i < l; i++)
            {
                c[i] = '\0';
            }
            return;
        }
        int strlen(const char *c)
        {
            int n = 0;
            while (c[n] != '\0')
            {
                n++;
            }
            return n;
        }
        int strfind(char *str1, const char *str2)
        {
            int l1 = str::strlen(str1);
            int l2 = str::strlen(str2);
            for (int i = 0, j = 0; i < l1; i++)
            {
                if (i != j)
                {
                    return j;
                }
                bool z = false;
                for (int k = 0; k < l2; k++)
                {
                    if (str1[i + k] != str2[k])
                    {
                        z = true;
                        break;
                    }
                }
                if (z == true)
                {
                    j++;
                }
            }
            return -1;
        }
        int strcpy(const char *c1, char *c2)
        {
            int n = str::strlen(c1);
            for (int i = 0; i < n; i++)
            {
                c2[i] = c1[i];
            }
            c2[n] = '\0';
            return n;
        }
        int strdel(char *a, const char *b)
        {
            int l1 = str::strlen(a);
            int l2 = str::strlen(b);
            for (int i = 0, j = 0; i < l1; i++)
            {
                if (i != j)
                {
                    for (int k = j + l2; k < l1; k++)
                    {
                        a[k - l2] = a[k];
                    }
                    a[l1 - l2] = '\0';
                    bool z = true;
                    for (int k = l2 - 1; k >= 0; k--)
                    {
                        if (a[j + k] != b[k])
                        {
                            z = false;
                            break;
                        }
                    }
                    if (z == false)
                    {
                        j = i;
                    }
                }
                bool z = true;
                for (int k = l2 - 1; k >= 0; k--)
                {
                    if (a[j + k] != b[k])
                    {
                        z = false;
                        break;
                    }
                }
                if (z == false)
                {
                    j++;
                }
            }
            int n = str::strlen(a);
            return n;
        }
        int strcat(char *c1, const char *c2)
        {
            int l1 = str::strlen(c1);
            int l2 = str::strlen(c2);
            for (int i = 0; i < l2; i++)
            {
                c1[i + l1] = c2[i];
            }
            c1[l1 + l2] = '\0';
            return str::strlen(c1);
        }
        void strsplit(const std::string &c, const std::string &f, std::vector<std::string> &a)
        {
            int cl = c.size();
            int fl = f.size();
            int n = 0;
            std::string s;
            for (int i = 0; i < cl; i++)
            {
                bool b = false;
                for (int j = 0; j < fl; j++)
                {
                    if (c[i] == f[j])
                    {
                        b = true;
                        break;
                    }
                }
                if (b == true)
                {
                    a.push_back(s);
                    s = "";
                }
                else
                {
                    s += c[i];
                }
            }
            a.push_back(s);
        }
        const int len = 1000000;
        class string
        {
        public:
            char c[len];
    
        public:
            int size();
            void clean();
            char *begin();
            char *end();
            string(const char ch[]);
            string();
            void getline();
            bool empty();
            char *tochar()
            {
                return c;
            }
            char &operator[](int n)
            {
                return *(c + n);
            }
            void operator=(const char ch[])
            {
                int n = str::strlen(ch);
                clean();
                for (int i = 0; i < n; i++)
                {
                    c[i] = ch[i];
                }
            }
            bool operator<(string s)
            {
                for (int i = 0; i < s.size(); i++)
                {
                    if (c[i] >= s[i])
                    {
                        return false;
                    }
                }
                return true;
            }
            bool operator>(string s)
            {
                for (int i = 0; i < s.size(); i++)
                {
                    if (c[i] <= s[i])
                    {
                        return false;
                    }
                }
                return true;
            }
            bool operator>=(string s)
            {
                for (int i = 0; i < s.size(); i++)
                {
                    if (c[i] < s[i])
                    {
                        return false;
                    }
                }
                return true;
            }
            bool operator<=(string s)
            {
                for (int i = 0; i < s.size(); i++)
                {
                    if (c[i] > s[i])
                    {
                        return false;
                    }
                }
                return true;
            }
            bool operator==(string s)
            {
                for (int i = 0; i < s.size(); i++)
                {
                    if (c[i] != s[i])
                    {
                        return false;
                    }
                }
                return true;
            }
            bool operator!=(string s)
            {
                for (int i = 0; i < s.size(); i++)
                {
                    if (c[i] != s[i])
                    {
                        return true;
                    }
                }
                return false;
            }
            bool operator<(const char s[])
            {
                int l = str::strlen(s);
                for (int i = 0; i < l; i++)
                {
                    if (c[i] >= s[i])
                    {
                        return false;
                    }
                }
                return true;
            }
            bool operator>(const char s[])
            {
                int l = str::strlen(s);
                for (int i = 0; i < l; i++)
                {
                    if (c[i] <= s[i])
                    {
                        return false;
                    }
                }
                return true;
            }
            bool operator<=(const char s[])
            {
                int l = str::strlen(s);
                for (int i = 0; i < l; i++)
                {
                    if (c[i] > s[i])
                    {
                        return false;
                    }
                }
                return true;
            }
            bool operator>=(const char s[])
            {
                int l = str::strlen(s);
                for (int i = 0; i < l; i++)
                {
                    if (c[i] < s[i])
                    {
                        return false;
                    }
                }
                return true;
            }
            bool operator==(const char s[])
            {
                int l = str::strlen(s);
                for (int i = 0; i < l; i++)
                {
                    if (c[i] != s[i])
                    {
                        return false;
                    }
                }
                return true;
            }
            bool operator!=(const char s[])
            {
                int l = str::strlen(s);
                for (int i = 0; i < l; i++)
                {
                    if (c[i] != s[i])
                    {
                        return true;
                    }
                }
                return false;
            }
        };
        int string::size()
        {
            return strlen(c);
        }
        void string::clean()
        {
            for (int i = 0; i < len; i++)
            {
                c[i] = '\0';
            }
        }
        char *string::begin()
        {
            return c;
        }
        char *string::end()
        {
            return c + strlen(c);
        }
        string::string(const char ch[])
        {
            int n = str::strlen(ch);
            clean();
            for (int i = 0; i < n; i++)
            {
                c[i] = ch[i];
            }
        }
        string::string()
        {
            clean();
        }
        void string::getline()
        {
            cin.getline(c, len);
        }
        bool string::empty()
        {
            if (strlen(c) == 0)
            {
                return true;
            }
            return false;
        }
        istream &operator>>(istream &is, string &s)
        {
            is >> s.c;
            return is;
        }
        ostream &operator<<(ostream &os, string &s)
        {
            os << s.c;
            return os;
        }
        bool operator<(const char c[], string s)
        {
            return s >= c;
        }
        bool operator>(const char c[], string s)
        {
            return s <= c;
        }
        bool operator>=(const char c[], string s)
        {
            return s < c;
        }
        bool operator<=(const char c[], string s)
        {
            return s > c;
        }
        bool operator==(const char c[], string s)
        {
            return s == c;
        }
        bool operator!=(const char c[], string s)
        {
            return s != c;
        }
    }
    namespace math
    {
        bool prime(long long a)
        {
            if (a == 2 || a <= 1)
            {
                return a == 2;
            }
            if (a % 2 == 0)
            {
                return false;
            }
            long long b = sqrt(a);
            for (int i = 3; i <= b; i += 2)
            {
                if (a % i == 0)
                {
                    return false;
                }
            }
            return true;
        }
        template<typename tp> int gcd(tp a, tp b)
        {
            if (a % b == 0)
            {
                return b;
            }
            else
            {
                return gcd(b, a % b);
            }
        }
        template<typename tp> int lcm(tp a, tp b)
        {
            long long n = gcd(a, b);
            return a / n * b;
        }
        template<typename tp> int decomposition(tp n, tp a[])
        {
            int cnt = 0;
            for (int i = 2; i * i < n; i++)
            {
                while (n % i == 0)
                {
                    n /= i;
                    a[cnt] = i;
                    cnt++;
                }
            }
            if (n != 1 || cnt == 0)
            {
                a[cnt] = n;
                n /= a[cnt];
                cnt++;
            }
            return cnt;
        }
        template<typename tp> double abs(tp n)
        {
            if (n < 0)
            {
                n *= -1;
            }
            return n;
        }
        template<typename tp> double max(tp n1, tp n2)
        {
            return n1 > n2 ? n1 : n2;
        }
        template<typename tp> double min(tp n1, tp n2)
        {
            return n1 < n2 ? n1 : n2;
        }
    }
    void fix(int n)
    {
        cout << fixed << setprecision(n);
    }
    void init()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
    }
    namespace structure
    {
        template<class tp> class list{
            public:
            struct node{
                tp data;
                node *nxt;
                node *lst;
            } *head = NULL, *q = NULL;
            public:
            list(){
                node *p;
                p = new node;
                p->lst = NULL;
                p->nxt = NULL;
                q = p;
                p = new node;
                p->nxt = q;
                p->lst = NULL;
                q->lst = p;
                head = p;
            }
            int size(){
                node *p = head->nxt;
                int t = 0;
                while (p != q){
                    t++;
                    p = p->nxt;
                }
                return t;
            }
            void push_front(tp data){
                node *a = new node;
                a->data = data;
                a->lst = head;
                a->nxt = head->nxt;
                head->nxt->lst = a;
                head->nxt = a;
            }
            void push_back(tp data){
                node *a = new node;
                a->data = data;
                a->lst = q->lst;
                a->nxt = q;
                q->lst->nxt = a;
                q->lst = a;
            }
            void pop_front(){
                node *p = head->nxt;
                head->nxt = p->nxt;
                p->nxt->lst = head;
                p->nxt = p->lst = NULL;
                delete p;
            }
            void pop_back(){
                node *p = q->lst;
                q->lst = p->lst;
                p->lst->nxt = q;
                p->nxt = p->lst = NULL;
                delete p;
            }
            void insert(node *p, tp data){
                node *a = new node;
                a->data = data;
                a->lst = p->lst;
                a->nxt = p;
                p->lst->nxt = a;
                p->lst = a;
            }
            void erase(node *p){
                node *tmp = p->lst;
                p->lst->nxt = p->nxt;
                p->nxt->lst = tmp;
                p->lst = p->nxt = NULL;
                delete p;
            }
            node *begin(){
                return head->nxt;
            }
            node *end(){
                return q;
            }
            void clear(){
                node *p = head->nxt;
                while (p != q){
                    p = p->nxt;
                    erase(p->lst);
                }
            }
            int empty(){
                return size() != 0;
            }
            node *operator [](int p){
                node *P = head->nxt;
                while (p--){
                    P = P->nxt;
                }
                return P;
            }
        };
    }
    
    bool z = false;
    map<string, int> order;
    int l = 0, p = 0;
    //***********************************************************************************************
    long double calculate(char s[])
    {
        long double x, y;
        string f;
        x = 0;
        y = 0;
        p = 0;
        f = "";
        int i = 0;
        long double m = 10;
        stack<long double> num;
        stack<string> op;
        z = false;
        x = 0;
        m = 10;
    //***********************************************************************************************
        if (s[0] >= '0' && s[0] <= '9'){
            for (int i = l - 1; i >= 0; i--){
                s[i + 1] = s[i];
            }
            s[0] = '0';
            l++;
        }
    //***********************************************************************************************
        bool bo = false;
        for (; i < l; i++)
        {
            y = 0;
            m = 10;
    //***********************************************************************************************
            if ((bo == false && s[i] == '-') || (s[i] >= '0' && s[i] <= '9') || s[i] == 'p' || s[i] == 'e')
            {
                bo = true;
                if (s[i] == 'e'){
                    num.push(2.7182818284590452353602874713526624977572470936999595749669676277240766303535475945713821785251664274);
                    continue;
                }
                if (s[i] == 'p'){
                    num.push(3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679);
                    continue;
                }
    //***********************************************************************************************
                bool b = false;
                if (s[i] == '-'){
                    b = true;
                    i++;
                }
                for (; (s[i] <= '9' && s[i] >= '0') || s[i] == '.'; i++)
                {
                    if (s[i] == '.' || m <= 1)
                    {
                        if (m == 10)
                        {
                            m /= 10;
                            continue;
                        }
                        m /= 10;
                        y += (s[i] - '0') * m;
                    }
                    else
                    {
                        y *= 10;
                        y += (s[i] - '0');
                    }
                }
                if (b == true){
                    y *= -1;
                }
                i--;
                num.push(y);
    //***********************************************************************************************
            }
            else
            {
                bo = false;
                f = "";
                if (s[i] == '(')
                {
                    f = "(";
                    num.push(calculate(s + i + 1));
                    if (z == true){
                        return 0;
                    }
                    p = 1;
                    while (p > 0)
                    {
                        i++;
                        if (i > l){
                            cout << "unknown error" << endl;
                        }
                        if (s[i] == '('){
                            p++;
                        }
                        else if (s[i] == ')'){
                            p--;
                        }
                    }
                    continue;
                }
                if (s[i] == ')'){
                    f = ")";
                }
                if (f == ")" && num.size() == 1 && op.size() == 0){
                    return num.top();
                }
    //***********************************************************************************************
                if (s[i] == '!'){
                    f = '!';
                    bo = true;
                }
                else
                {
                    for (; s[i] != ')' && s[i] != '(' && !(s[i] >= '0' && s[i] <= '9') && i < l; i++){
                        f.push_back(s[i]);
                        if (order.count(f) == true){
                            break;
                        }
                    }
                }
                if (order.count(f) == 0)
                {
                    cout << "Please input a correct operator!" << endl;
                    z = true;
                    return 0;
                }
    //***********************************************************************************************
                bool c = false;
                while (op.size() > 0 && order[f] <= order[op.top()])
                {
                    c = true;
                    if ((num.size() < 2 && op.top() != "!") || num.size() < 1){
                        cout << "Please input more number" << endl;
                        z = true;
                        return 0;
                    }
                    y = num.top();
                    num.pop();
                    if (op.top() != "!")
                    {
                        x = num.top();
                        num.pop();
                    }
                    string k = op.top();
                    op.pop();
    //***********************************************************************************************
                    if (k == "+")
                    {
                        x += y;
                    }
                    else if (k == "-")
                    {
                        x -= y;
                    }
                    else if (k == "*")
                    {
                        x *= y;
                    }
                    else if (k == "/")
                    {
                        if (y != 0)
                        {
                            x /= y;
                        }
                        else
                        {
                            cout << "Don't use a 0 as divisor!" << endl;
                            z = true;
                            return 0;
                        }
                    }
                    else if (k == "%")
                    {
                        if (y != int(y)){
                            if (y == 0){
                                cout << "Don't use a 0 as divisor!" << endl;
                                z = true;
                                return 0;
                            }
                            int tmp = 0;
                            if (y <= -1 || y >= 1){
                                tmp = x - 1.0 * (int)x / (int)y * (int)y;
                            }
                            while (tmp * y <= x)
                            {
                                tmp++;
                            }
                            while (tmp * y > x)
                            {
                                tmp--;
                            }
                            x -= tmp * y;
                            num.push(x);
                            continue;
                        }
                        int x1 = int(x), y1 = int(y);
                        if (y1 == 0)
                        {
                            cout << "Don't use a 0 as divisor!" << endl;
                            z = true;
                            return 0;
                        }
                        x = x1 % y1;
                    }
                    else if (k == "^")
                    {
                        if (x < 0 && (int)y != y)
                        {
                            cout << "This calculator does not support imaginary numbers!" << endl;
                            z = true;
                            return 0;
                        }
                        x = pow(x, y);
                    }
                    else if (k == "!"){
                        if (y < 0 || y != int(y)){
                            cout << "unknown error" << endl;
                            z = true;
                            return 0;
                        }
                        long double tmp = 1;
                        for (int i = y; i > 1; i--){
                            tmp *= i;
                        }
                        x = tmp;
                    }
                    num.push(x);
                }
                op.push(f);
                if (f == ")") break;
            }
        }
    //***********************************************************************************************
        if (num.size() < 1){
            cout << "Please input more number" << endl;
            z = true;
            return 0;
        }
        else if (num.size() > 1)
        {
            cout << "Please input less number" << endl;
            z = true;
            return 0;
        }
        return num.top();
    }
    //***********************************************************************************************
    //***********************************************************************************************
    //***********************************************************************************************
    int main()
    {
        // init();
        order["+"] = order["-"] = 1;
        order["*"] = order["/"] = order["%"] = 2;
        order["^"] = 3;
        order["!"] = 4;
        order[")"] = -1;
    //***********************************************************************************************
        bool b = false;
        while (true)
        {
            z = false;
            char s[100005];
            for (int i = 0; i <= 100004; i++){
                s[i] = '\0';
            }
            cin.getline(s, 100000);
            str::strdel(s, " ");
            l = str::strlen(s);
    //***********************************************************************************************
            int i = 0;
            string _ = "";
            if (s[0] == 'P' || (s[0] == 'p' && (order[_ + s[1]] == false)))
            {
                int x = 0;
                i = 1;
                for (; s[i] <= '9' && s[i] >= '0'; i++)
                {
                    x *= 10;
                    x += (s[i] - '0');
                }
                if (i != l){
                    cout << "unknown error" << endl;
                }
                if (x > 10){
                    cout << "too big" << endl;
                    continue;
                }
                cout.unsetf(cout.fixed);
                cout.precision((int)x);
                continue;
            }
    //***********************************************************************************************
            if (l == 3 && s[0] == 'i' && s[1] == 'n' && s[2] == 't'){
                cout.unsetf(cout.fixed);
                cout.precision(0);
                continue;
            }
            else if (l == 6 && s[0] == 'd' && s[1] == 'o' && s[2] == 'u' && s[3] == 'b' && s[4] == 'l' && s[5] == 'e'){
                cout.unsetf(cout.fixed);
                cout.precision(18);
                continue;
            }
    //***********************************************************************************************
            int n = 0;
            for (int i = 0; i < l - 1; i++){
                if (s[i] == '(' && s[i + 1] == ')'){
                    s[i] = s[i + 1] = ' ';
                }
            }
            str::strdel(s, " ");
            for (int i = 0; i < l; i++){
                if (s[i] == '('){
                    n++;
                }
                if (s[i] == ')'){
                    n--;
                }
                if (n < 0){
                    z = true;
                    break;
                }
            }
            l = str::strlen(s);
            if (z == true || n != 0){
                z = false;
                cout << "unknown error" << endl;
                continue;
            }
    //***********************************************************************************************
            s[l] = ')';
            l++;
            p = 0;
            long double y = calculate(s);
            if (z == false)
            {
                cout << y << endl;
            }
        }
        return 0;
    }
    

    有bug请从站内消息跟我说

    我的头文件

    #include <iostream>
    #include <iomanip>
    #include <math.h>
    #include <cmath>
    #include <time.h>
    #include <stdlib.h>
    #include <cstdio>
    #include <cmath>
    #include <string.h>
    #include <string>
    #include <cstring>
    #include <vector>
    #include <stack>
    #include <queue>
    #include <deque>
    #include <list>
    #include <map>
    #include <set>
    #include <sstream>
    using namespace std;
    int d[8][2] = {{0, -1}, {-1, 0}, {0, 1}, {1, 0}, {-1, -1}, {1, -1}, {1, 1}, {-1, 1}};
    namespace std
    {
        std::ostream &endl(std::ostream &os)
        {
            os.put(os.widen('\n'));
            return os;
        }
    }
    namespace str
    {
        char *itoa(int a, char *c, int n = 10)
        {
            int a1[100];
            int m = 0;
            if (n == 10)
            {
                while (a != 0)
                {
                    a1[m] = a % 10;
                    c[m] = a1[m] + '0';
                    a /= 10;
                    m++;
                }
            }
            else
            {
                while (a != 0)
                {
                    c[m] = a % n + '0';
                    if (c[m] > '9')
                    {
                        c[m] += 7;
                    }
                    a /= n;
                    m++;
                }
            }
            for (int i = 0, j = m - 1; i < j; i++, j--)
            {
                char k = c[i];
                c[i] = c[j];
                c[j] = k;
            }
            c[m] = '\0';
            return c;
        }
        long long atoi(char *c, int m = 10)
        {
            long long n = 0;
            long long a = 1;
            long long l = strlen(c);
            if (c[0] == '-')
            {
                for (int i = l - 1; i >= 0; i--)
                {
                    n += ((c[i] - (c[i] >= 'A' ? 'A' - 10 : '0')) * a);
                    a *= m;
                }
                n *= -1;
            }
            else
            {
                for (int i = l - 1; i >= 0; i--)
                {
                    n += ((c[i] - (c[i] >= 'A' ? 'A' - 10 : '0')) * a);
                    a *= m;
                }
            }
            return n;
        }
        void clean(char *c)
        {
            int l = strlen(c);
            for (int i = 0; i < l; i++)
            {
                c[i] = '\0';
            }
            return;
        }
        int strlen(const char *c)
        {
            int n = 0;
            while (c[n] != '\0')
            {
                n++;
            }
            return n;
        }
        int strfind(char *str1, const char *str2)
        {
            int l1 = str::strlen(str1);
            int l2 = str::strlen(str2);
            for (int i = 0, j = 0; i < l1; i++)
            {
                if (i != j)
                {
                    return j;
                }
                bool z = false;
                for (int k = 0; k < l2; k++)
                {
                    if (str1[i + k] != str2[k])
                    {
                        z = true;
                        break;
                    }
                }
                if (z == true)
                {
                    j++;
                }
            }
            return -1;
        }
        int strcpy(const char *c1, char *c2)
        {
            int n = str::strlen(c1);
            for (int i = 0; i < n; i++)
            {
                c2[i] = c1[i];
            }
            c2[n] = '\0';
            return n;
        }
        int strdel(char *a, const char *b)
        {
            int l1 = str::strlen(a);
            int l2 = str::strlen(b);
            for (int i = 0, j = 0; i < l1; i++)
            {
                if (i != j)
                {
                    for (int k = j + l2; k < l1; k++)
                    {
                        a[k - l2] = a[k];
                    }
                    a[l1 - l2] = '\0';
                    bool z = true;
                    for (int k = l2 - 1; k >= 0; k--)
                    {
                        if (a[j + k] != b[k])
                        {
                            z = false;
                            break;
                        }
                    }
                    if (z == false)
                    {
                        j = i;
                    }
                }
                bool z = true;
                for (int k = l2 - 1; k >= 0; k--)
                {
                    if (a[j + k] != b[k])
                    {
                        z = false;
                        break;
                    }
                }
                if (z == false)
                {
                    j++;
                }
            }
            int n = str::strlen(a);
            return n;
        }
        int strcat(char *c1, const char *c2)
        {
            int l1 = str::strlen(c1);
            int l2 = str::strlen(c2);
            for (int i = 0; i < l2; i++)
            {
                c1[i + l1] = c2[i];
            }
            c1[l1 + l2] = '\0';
            return str::strlen(c1);
        }
        void strsplit(const std::string &c, const std::string &f, std::vector<std::string> &a)
        {
            int cl = c.size();
            int fl = f.size();
            int n = 0;
            std::string s;
            for (int i = 0; i < cl; i++)
            {
                bool b = false;
                for (int j = 0; j < fl; j++)
                {
                    if (c[i] == f[j])
                    {
                        b = true;
                        break;
                    }
                }
                if (b == true)
                {
                    a.push_back(s);
                    s = "";
                }
                else
                {
                    s += c[i];
                }
            }
            a.push_back(s);
        }
        const int len = 1000000;
        class string
        {
        public:
            char c[len];
    
        public:
            int size();
            void clean();
            char *begin();
            char *end();
            string(const char ch[]);
            string();
            void getline();
            bool empty();
            char *tochar()
            {
                return c;
            }
            char &operator[](int n)
            {
                return *(c + n);
            }
            void operator=(const char ch[])
            {
                int n = str::strlen(ch);
                clean();
                for (int i = 0; i < n; i++)
                {
                    c[i] = ch[i];
                }
            }
            bool operator<(string s)
            {
                for (int i = 0; i < s.size(); i++)
                {
                    if (c[i] >= s[i])
                    {
                        return false;
                    }
                }
                return true;
            }
            bool operator>(string s)
            {
                for (int i = 0; i < s.size(); i++)
                {
                    if (c[i] <= s[i])
                    {
                        return false;
                    }
                }
                return true;
            }
            bool operator>=(string s)
            {
                for (int i = 0; i < s.size(); i++)
                {
                    if (c[i] < s[i])
                    {
                        return false;
                    }
                }
                return true;
            }
            bool operator<=(string s)
            {
                for (int i = 0; i < s.size(); i++)
                {
                    if (c[i] > s[i])
                    {
                        return false;
                    }
                }
                return true;
            }
            bool operator==(string s)
            {
                for (int i = 0; i < s.size(); i++)
                {
                    if (c[i] != s[i])
                    {
                        return false;
                    }
                }
                return true;
            }
            bool operator!=(string s)
            {
                for (int i = 0; i < s.size(); i++)
                {
                    if (c[i] != s[i])
                    {
                        return true;
                    }
                }
                return false;
            }
            bool operator<(const char s[])
            {
                int l = str::strlen(s);
                for (int i = 0; i < l; i++)
                {
                    if (c[i] >= s[i])
                    {
                        return false;
                    }
                }
                return true;
            }
            bool operator>(const char s[])
            {
                int l = str::strlen(s);
                for (int i = 0; i < l; i++)
                {
                    if (c[i] <= s[i])
                    {
                        return false;
                    }
                }
                return true;
            }
            bool operator<=(const char s[])
            {
                int l = str::strlen(s);
                for (int i = 0; i < l; i++)
                {
                    if (c[i] > s[i])
                    {
                        return false;
                    }
                }
                return true;
            }
            bool operator>=(const char s[])
            {
                int l = str::strlen(s);
                for (int i = 0; i < l; i++)
                {
                    if (c[i] < s[i])
                    {
                        return false;
                    }
                }
                return true;
            }
            bool operator==(const char s[])
            {
                int l = str::strlen(s);
                for (int i = 0; i < l; i++)
                {
                    if (c[i] != s[i])
                    {
                        return false;
                    }
                }
                return true;
            }
            bool operator!=(const char s[])
            {
                int l = str::strlen(s);
                for (int i = 0; i < l; i++)
                {
                    if (c[i] != s[i])
                    {
                        return true;
                    }
                }
                return false;
            }
        };
        int string::size()
        {
            return strlen(c);
        }
        void string::clean()
        {
            for (int i = 0; i < len; i++)
            {
                c[i] = '\0';
            }
        }
        char *string::begin()
        {
            return c;
        }
        char *string::end()
        {
            return c + strlen(c);
        }
        string::string(const char ch[])
        {
            int n = str::strlen(ch);
            clean();
            for (int i = 0; i < n; i++)
            {
                c[i] = ch[i];
            }
        }
        string::string()
        {
            clean();
        }
        void string::getline()
        {
            cin.getline(c, len);
        }
        bool string::empty()
        {
            if (strlen(c) == 0)
            {
                return true;
            }
            return false;
        }
        istream &operator>>(istream &is, string &s)
        {
            is >> s.c;
            return is;
        }
        ostream &operator<<(ostream &os, string &s)
        {
            os << s.c;
            return os;
        }
        bool operator<(const char c[], string s)
        {
            return s >= c;
        }
        bool operator>(const char c[], string s)
        {
            return s <= c;
        }
        bool operator>=(const char c[], string s)
        {
            return s < c;
        }
        bool operator<=(const char c[], string s)
        {
            return s > c;
        }
        bool operator==(const char c[], string s)
        {
            return s == c;
        }
        bool operator!=(const char c[], string s)
        {
            return s != c;
        }
    }
    namespace math
    {
        bool prime(long long a)
        {
            if (a == 2 || a <= 1)
            {
                return a == 2;
            }
            if (a % 2 == 0)
            {
                return false;
            }
            long long b = sqrt(a);
            for (int i = 3; i <= b; i += 2)
            {
                if (a % i == 0)
                {
                    return false;
                }
            }
            return true;
        }
        template<typename tp> int gcd(tp a, tp b)
        {
            if (a % b == 0)
            {
                return b;
            }
            else
            {
                return gcd(b, a % b);
            }
        }
        template<typename tp> int lcm(tp a, tp b)
        {
            long long n = gcd(a, b);
            return a / n * b;
        }
        template<typename tp> int decomposition(tp n, tp a[])
        {
            int cnt = 0;
            for (int i = 2; i * i < n; i++)
            {
                while (n % i == 0)
                {
                    n /= i;
                    a[cnt] = i;
                    cnt++;
                }
            }
            if (n != 1 || cnt == 0)
            {
                a[cnt] = n;
                n /= a[cnt];
                cnt++;
            }
            return cnt;
        }
        template<typename tp> double abs(tp n)
        {
            if (n < 0)
            {
                n *= -1;
            }
            return n;
        }
        template<typename tp> double max(tp n1, tp n2)
        {
            return n1 > n2 ? n1 : n2;
        }
        template<typename tp> double min(tp n1, tp n2)
        {
            return n1 < n2 ? n1 : n2;
        }
    }
    void fix(int n)
    {
        cout << fixed << setprecision(n);
    }
    void init()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
    }
    namespace structure
    {
        template<class tp> class list{
            public:
            struct node{
                tp data;
                node *nxt;
                node *lst;
            } *head = NULL, *q = NULL;
            long long l;
            public:
            list(){
                l = 0;
                node *p;
                p = new node;
                p->lst = NULL;
                p->nxt = NULL;
                q = p;
                p = new node;
                p->nxt = q;
                p->lst = NULL;
                q->lst = p;
                head = p;
            }
            int size(){
                return l;
            }
            void push_front(tp data){
                l++;
                node *a = new node;
                a->data = data;
                a->lst = head;
                a->nxt = head->nxt;
                head->nxt->lst = a;
                head->nxt = a;
            }
            void push_back(tp data){
                l++;
                node *a = new node;
                a->data = data;
                a->lst = q->lst;
                a->nxt = q;
                q->lst->nxt = a;
                q->lst = a;
            }
            void pop_front(){
                l--;
                node *p = head->nxt;
                head->nxt = p->nxt;
                p->nxt->lst = head;
                p->nxt = p->lst = NULL;
                delete p;
            }
            void pop_back(){
                l--;
                node *p = q->lst;
                q->lst = p->lst;
                p->lst->nxt = q;
                p->nxt = p->lst = NULL;
                delete p;
            }
            void insert(node *p, tp data){
                l++;
                node *a = new node;
                a->data = data;
                a->lst = p->lst;
                a->nxt = p;
                p->lst->nxt = a;
                p->lst = a;
            }
            void erase(node *p){
                l--;
                node *tmp = p->lst;
                p->lst->nxt = p->nxt;
                p->nxt->lst = tmp;
                p->lst = p->nxt = NULL;
                delete p;
            }
            node *begin(){
                return head->nxt;
            }
            node *end(){
                return q;
            }
            void clear(){
                node *p = head->nxt;
                while (p != q){
                    p = p->nxt;
                    erase(p->lst);
                }
                l = 0;
            }
            int empty(){
                return size() != 0;
            }
            node *operator [](int p){
                if (p > l){
                    return NULL;
                }
                node *P = head->nxt;
                while (p--){
                    P = P->nxt;
                }
                return P;
            }
        };  
    }
    

    AI五子棋

    #include <iostream>
    #include <iomanip>
    #include <vector>
    #include <time.h>
    using namespace std;
    const long long n = 10;
    const char ccc = '_';
    vector<vector<char>> a;
    int dd[4][2] = {{0, 1}, {1, 1}, {1, 0}, {1, -1}};
    //long long eg[12] = {0, 2, 2, 30, 40, 90000000, 10000, 10000, 10000, 10000, 10000, 10000};
    //long long pg[12] = {0, 2, 2, 2000, 9999, 10000, 10000, 10000, 10000, 10000, 10000, 10000};
    long long eg[6] = {10, 1000, 100000, 10000000, 1000000000, 1000000000000000};
    long long pg[6] = {1, 100, 10000, 1000000, 100000000, 10000000000};
    long long win(){
        for (long long i = 1; i <= n - 4; i++){
            for (long long j = 1; j <= n - 4; j++){
                if (a[i][j] == 'x' && a[i + 1][j + 1] == 'x' && a[i + 2][j + 2] == 'x' && a[i + 3][j + 3] == 'x' && a[i + 4][j + 4] == 'x'){
                    return 1;
                }
                if (a[i][j] == 'o' && a[i + 1][j + 1] == 'o' && a[i + 2][j + 2] == 'o' && a[i + 3][j + 3] == 'o' && a[i + 4][j + 4] == 'o'){
                    return -1;
                }
            }
        }
        for (long long i = 5; i <= n; i++){
            for (long long j = 1; j <= n - 4; j++){
                if (a[i][j] == 'x' && a[i - 1][j + 1] == 'x' && a[i - 2][j + 2] == 'x' && a[i - 3][j + 3] == 'x' && a[i - 4][j + 4] == 'x'){
                    return 1;
                }
                if (a[i][j] == 'o' && a[i - 1][j + 1] == 'o' && a[i - 2][j + 2] == 'o' && a[i - 3][j + 3] == 'o' && a[i - 4][j + 4] == 'o'){
                    return -1;
                }
            }
        }
        for (long long i = 1; i <= n - 4; i++){
            for (long long j = 1; j <= n; j++){
                if (a[i][j] == 'x' && a[i + 1][j] == 'x' && a[i + 2][j] == 'x' && a[i + 3][j] == 'x' && a[i + 4][j] == 'x'){
                    return 1;
                }
                if (a[i][j] == 'o' && a[i + 1][j] == 'o' && a[i + 2][j] == 'o' && a[i + 3][j] == 'o' && a[i + 4][j] == 'o'){
                    return -1;
                }
            }
        }
        for (long long i = 1; i <= n; i++){
            for (long long j = 1; j <= n - 4; j++){
                if (a[i][j] == 'x' && a[i][j + 1] == 'x' && a[i][j + 2] == 'x' && a[i][j + 3] == 'x' && a[i][j + 4] == 'x'){
                    return 1;
                }
                if (a[i][j] == 'o' && a[i][j + 1] == 'o' && a[i][j + 2] == 'o' && a[i][j + 3] == 'o' && a[i][j + 4] == 'o'){
                    return -1;
                }
            }
        }
        long long r = 2;
        for (long long i = 1; i <= n; i++){
            for (long long j = 1; j <= n; j++){
                if (a[i][j] != 'x' && a[i][j] != 'o'){
                    r = 0;
                }
            }
        }
        return r;
    }
    void print(){
        cout << "    ";
        for (long long i = 1; i <= n; i++){
            cout << i << " ";
        }
        cout << endl;
        for (long long i = 1; i <= n; i++){
            cout << setw(2) << i << "  ";
            for (long long j = 1; j <= n; j++){
                cout << a[i][j] << " ";
            }
            cout << endl;
        }
    }
    long long linegrade(long long x, long long y, long long d, char c, char f){
        if (a[x][y] != ccc){
            return 0;
        }
        long long ans = 0;
        vector<char> v;
        v.push_back(0);
        long long i = x, j = y;
        long long p = 1;
        bool b = false;
        for (; i > 0 && j > 0 && i <= n && j <= n; i -= dd[d][0], j -= dd[d][1]){}
        i += dd[d][0];
        j += dd[d][1];
        for (; i > 0 && j > 0 && i <= n && j <= n; i += dd[d][0], j += dd[d][1]){
            v.push_back(a[i][j]);
            if (i == x && j == y){
                b = true;
            }
            if (b == false){
                p++;
            }
        }
        char e;
        if (c == 'X'){
            e = 'O';
        }
        else{
            e = 'X';
        }
        long long cnt = 0;
        long long ls = 0;
        long long rs = 0;
        long long len = 0;
        int l, r;
        int ll, rr;
        for (long long i = p - 4, j = p; i <= p; i++, j++){
            cnt = 0;
            ls = 0;
            rs = 0;
            len = 0;
            ll = 0;
            rr = 0;
            l = -1e9;
            r = -1e9;
            if (i < 1 || j < 1 || i > n || j > n){
                continue;
            }
            if (i == 1 || v[i - 1] == e){
                l = i - 1;
            }
            if (j == v.size() - 1 || v[j + 1] == e){
                r = j + 1;
            }
            for (long long k = p - 1; k >= i; k--){
                if (v[k] == c){
                    cnt++;
                    if (ls == 0){
                        len++;
                    }
                    ll = 0;
                }
                else if (v[k] == ccc){
                    ls++;
                    ll++;
                    continue;
                }
                else{
                    l = i;
                    ll = 0;
                    break;
                }
            }
            for (long long k = p + 1; k <= j; k++){
                if (v[k] == c){
                    cnt++;
                    if (rs == 0){
                        len++;
                    }
                    rr = 0;
                }
                else if (v[k] == ccc){
                    rs++;
                    rr++;
                    continue;
                }
                else{
                    r = j;
                    rr = 0;
                    break;
                }
            }
            ls -= ll;
            rs -= rr;
            if (l != -1e9 && r != -1e9){
                continue;
            }
            if (cnt == 4){
                ans += 1e9;
            }
            else if (l != -1e9 || r != -1e9){
                if (ls != 0 || rs != 0){
                    if (c == f){
                        ans += eg[max(0ll, cnt - 2)];
                    }
                    else{
                        ans += pg[max(0ll, cnt - 2)];
                    }
                }
                else{
                    if (c == f){
                        ans += eg[max(0ll, cnt - 1)];
                    }
                    else{
                        ans += pg[max(0ll, cnt - 1)];
                    }
                }
            }
            else{
                if (ls != 0 || rs != 0){
                    if (c == f){
                        ans += eg[max(0ll, cnt - 1)];
                    }
                    else{
                        ans += pg[max(0ll, cnt - 1)];
                    }
                }
                else{
                    if (c == f){
                        ans += eg[max(0ll, cnt)];
                    }
                    else{
                        ans += pg[max(0ll, cnt)];
                    }
                }
            }
        }
        return ans;
    }
    long long grade(long long x, long long y, char c){
        if (x < 1 || y < 1 || x > n || y > n){
            return 0;
        }
        if (a[x][y] != ccc){
            return 0;
        }
        long long ans = 0;
        for (long long i = 0; i < 4; i++){
            char e;
            if (c == 'X'){
                e = 'O';
            }
            else{
                e = 'X';
            }
            ans += linegrade(x, y, i, c, c);
            ans += linegrade(x, y, i, e, c);
        }
        return ans;
    }
    long long px, py;
    void change(char c){
        long long x = 0, y = 0, v = -1e9;
        for (long long i = 1; i <= n; i++){
            for (long long j = 1; j <= n; j++){
                if (a[i][j] == ccc){
                    // cout << i << " " << j << " " << grade(i, j, c) << " " << linegrade(i, j, 0, c) << " " << linegrade(i, j, 1, c) << " " << linegrade(i, j, 2, c) << " " << linegrade(i, j, 3, c) << endl;
                    if (v < grade(i, j, c)){
                        x = i;
                        y = j;
                        v = grade(i, j, c);
                    }
                    else if (v == grade(i, j, c)){
                        if ((rand() & 1) == 1){
                            x = i;
                            y = j;
                            v = grade(i, j, c);
                        }
                    }
                }
            }
        }
        px = x;
        py = y;
    }
    int main(){
        srand(time(NULL));
        a.resize(n + 1);
        for (long long i = 1; i <= n; i++){
            a[i].resize(n + 1, ccc);
        }
        bool d = false;
        bool c;
        string s;
        while (true){
            cout << "请问你要先手还是后手(如先手请输入\"1\", 否则输入\"2\")" << endl;
            cin >> s;
            if (s == "1"){
                c = true;
                break;
            }
            else if (s == "2"){
                c = false;
                break;
            }
            else{
                cout << "输入有误, 请重新输入" << endl;
                continue;
            }
        }
        while (c == true){
            long long flag = win();
            if (flag != 0){
                print();
                if (flag == -1){
                    cout << "AI胜" << endl;
                    break;
                }
                else{
                    cout << "你赢了" << endl;
                    break;
                }
            }
            print();
            cout << "请输入你要下的行和列" << endl;
            long long x, y;
            cin >> x >> y;
            if (x < 1 || y < 1 || x > n || y > n || a[x][y] != ccc){
                cout << "输入有误 请重新输入" << endl;
                continue;
            }
            a[x][y] = 'x';
            flag = win();
            if (flag != 0){
                print();
                if (flag == 2){
                    cout << "平局" << endl;
                }
                if (flag == -1){
                    cout << "AI胜" << endl;
                    break;
                }
                else{
                    cout << "你赢了" << endl;
                    break;
                }
            }
            change('o');
            a[px][py] = 'o';
            cout << "AI下" << px << " " << py << endl;
        }
        bool b = false;
        while (c == false){
            long long flag = win();
            if (flag != 0){
                print();
                if (flag == -1){
                    cout << "AI胜" << endl;
                    break;
                }
                else{
                    cout << "你赢了" << endl;
                    break;
                }
            }
            if (d == false){
                if (b == false){
                    px = n / 2 + 1;
                    py = n / 2 + 1;
                    b = true;
                }
                else{
                    change('o');
                }
                a[px][py] = 'o';
                print();
                cout << "AI下" << px << " " << py << endl;
                cout << "请输入你要下的行和列" << endl;
            }
            flag = win();
            if (flag != 0){
                print();
                if (flag == 2){
                    cout << "平局" << endl;
                    break;
                }
                else if (flag == -1){
                    cout << "AI胜" << endl;
                    break;
                }
                else{
                    cout << "你赢了" << endl;
                    break;
                }
            }
            long long x, y;
            cin >> x >> y;
            d = false;
            if (x < 1 || y < 1 || x > n || y > n || a[x][y] != ccc){
                cout << "输入有误 请重新输入" << endl;
                d = true;
                continue;
            }
            a[x][y] = 'x';
        }
        return 0;
    }
    
  • 最近活动

  • Stat

  • Rating