头像

小轩喵灬




离线:5小时前


最近来访(59)
用户头像
86_4
用户头像
武僧
用户头像
爱吃西兰花
用户头像
昨天你TLE了吗
用户头像
途_8
用户头像
一吻封情
用户头像
pppppppx
用户头像
gyhje
用户头像
こんにちは
用户头像
ShawnShawn
用户头像
ParTin
用户头像
YOLO_0
用户头像
TTYYAA
用户头像
带有细胞壁的未知生物
用户头像
sakkkk
用户头像
摆烂大大王
用户头像
整个AcWing凑不出一个ikun
用户头像
早点睡觉_1
用户头像
GreatestOliveira
用户头像


dp 暴力 O(N2)

#include<iostream>
#include<string>
#include<ctype.h>

using namespace std;

const int N = 10010;
short dp[N][N];

string a,b;

int main() {
    cin >> a >> b;

    a = ' '+ a;
    b = ' '+ b;

    int la = a.length(), lb = b.length();
    short cnt = 0;
    for(int i = 1; i <= la; i++) {
        for(int j = 1; j <= lb; j++) {
            if (a[i] == b[j] && isalpha(a[i]) && isalpha(b[j])) {
                dp[i][j] = max(dp[i][j], short(dp[i-1][j-1] + 1));
            }
            cnt = max(cnt, dp[i][j]);
        }
    }
    cout<<cnt;
    return 0;
}



小轩喵灬
1个月前
#include<iostream>
#include<cstring>
#include<algorithm>
#include<vector>

using namespace std;

int n;
string str;

void update(char& c) {
    if (c == 'W') c = 'B';
    else c = 'W';
}

bool check(char c) {
    vector<int> res;
    string s = str;
    for (int i = 0; i + 1 < n; i++) {
        if (s[i] != c) {
            update(s[i]);
            update(s[i + 1]);
            res.push_back(i);
        }

    }

    if (s.back() != c) return false;

    cout<<res.size()<<endl;

    for(int x : res) {
        cout<<x + 1<<' ';
    }

    if (res.size()) {
        cout << endl;
    }
    return true;
}

int main() {
    int t;
    cin >> t;

    while(t--) {
        cin >> n >> str;
        if (!check('B') && !check('W')) puts("-1");
    }
    return 0;
}



小轩喵灬
1个月前
#include<iostream>

using namespace std;

const int N = 1e5+10;

int n, m;
int a[N], b[N];

int main() {
    cin >> n >>m;

    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }

    for(int j = 0; j <m ;j++) {
        cin >> b[j];
    }

    int i = 0, j = 0;
    while( i < n &&j < m) {
        if (a[i] == b[j]) {
            i++;
        }
        j++;
    }

    if (i == n) cout<<"Yes";
    else {
        cout<<"No";
    }
    return 0;
}



小轩喵灬
1个月前
#include<iostream>

using namespace std;

const int N = 1e5+10;

int a[N], b[N];

int n, m,x;

int main() {
    cin >>n >> m >>x;

    for(int i = 0; i < n ;i++) {
        cin >> a[i];
    }

    for(int j = 0; j < m; j++) {
        cin >> b[j];
    }

    for(int i = 0, j = m - 1; i < n; i++) {
        while(j >= 0 && a[i] + b[j] > x) j--;

        if (j >= 0 && a[i] + b[j] == x) cout<< i << ' '<< j<<endl;
    }
    return 0;
}



小轩喵灬
1个月前
#include<iostream>

using namespace std;

const int N = 1e5+10;

int n;
int a[N], b[N];

int main(){
    cin >> n;

    for(int i = 0 ; i < n; i++) {
        cin >> a[i];
    }
    int res = 0;
    for(int i = 0, j = 0; i <n; i++) {
        b[a[i]]++;
        while(i > j && b[a[i]] > 1) {
            b[a[j]]--;
            j++;
        }
        res = max(res, i - j + 1);
    }
    cout<<res;
    return 0;
}



小轩喵灬
1个月前
#include<iostream>
#include<cstring>

using namespace std;

const int N = 110;

int n;
string str;

int main() {
    cin >> n >> str;

    int res = 0;
    for(int i = 0; i < n; i++) {
        if (str[i] == 'x') {
            int j = i + 1;
            while(j < n && str[j] == 'x' ) j++;
            res += max(j - i - 2, 0);
            i = j - 1;
        }
    }

    cout<<res;
    return 0;
}



小轩喵灬
1个月前
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <unordered_map>

using namespace std ;
const int N = 32 ;
int n ;
int a[N] , b[N] ;
unordered_map<int,int> l , r , pos ;

int bulid(int bl , int br , int al , int ar) //递归处理,l记录左儿子,r记录右儿子
{
    int root = a[ar] ;
    int k = pos[root] ;
    if(bl < k) l[root] = bulid(bl , k - 1 , al , al + k - 1 - bl ) ;
    if(br > k) r[root] = bulid(k + 1 , br , ar - br + k  , ar - 1) ;
    return root ;
}
void dfs(int u)
{
    queue<int> q ;
    q.push(u) ;

    while(q.size())
    {
        int t = q.front() ;
        q.pop() ;
        cout << t << " " ;
        if(l.count(t)) q.push(l[t]) ;
        if(r.count(t)) q.push(r[t]) ;
    }
}

int main()
{
    cin >> n ;
    for(int i = 0 ; i < n ; i ++) cin >> a[i] ;
    for(int i = 0 ; i < n ; i ++)
    {
        cin >> b[i] ;
        pos[b[i]] = i ; // 记录中序遍历的位置
    }

    int root = bulid(0 , n - 1 , 0 , n - 1) ; //建树,前面两位表示中序的起始位置,后面两位表示后序的位置
    dfs(root) ;//遍历根节点
    return 0 ; 
}



小轩喵灬
1个月前
#include<iostream>

using namespace std;

const int N = 100010;

int n,q[N],m;

int main() {
    scanf("%d%d", &n, &m);

    for(int i = 0; i < n; i++) {
        scanf("%d",&q[i]);
    }

    while(m--) {
        int x;
        scanf("%d", &x);

        int l = 0, r = n -1;


        while(l < r) {
            int mid = l + r>>1;

            // 取左边界
            if (q[mid] >= x) r = mid;
            else l = mid + 1;
        }

        if (q[l] != x) printf("-1 -1\n");
        else {
            printf("%d ", l);

            l = 0, r = n-1;

            while( l < r) {
                int mid = l+r+1>>1;
                // 取有边界  右边包含mid
                if (q[mid] <= x) l = mid;
                else r = mid -1;
            }            
            printf("%d\n", r);
        }
    }
    return 0;
}



小轩喵灬
1个月前
#include<iostream>
#include<cstring>
#include<unordered_set>

using namespace std;

const int N = 110;

int n;
string str;

bool check(int mid) {
    unordered_set<string> hash;

    for(int i = 0; i + mid - 1 < n; i++) {
        string s = str.substr(i, mid);
        if (hash.count(s)) return false;
        hash.insert(s);
    }
    return true;
}

int main() {
    cin >> n >> str;

    int l = 1, r = n;

    while(l < r) {
        int mid = l + r >> 1;
        if (check(mid)) {
            r = mid;
        } else {
            l = mid + 1;
        }
    }
    cout<<r;
    return 0;
}



小轩喵灬
1个月前
#include<iostream>

using namespace std;

const int N = 1010;

int n, m, q;

int b[N][N];

void insert(int x1, int y1, int x2, int y2, int c) {
   b[x1][y1] += c;
   b[x1][y2 + 1] -= c;
   b[x2 + 1][y1] -= c;
   b[x2+1][y2 + 1] += c;
}

int main() {
    cin >> n >> m >> q;

    for(int i = 1; i <=n ;i++) {
        for(int j = 1; j <= m; j++) {
            int x;
            cin >> x;
              insert(i,j, i , j, x);
        }
    }

    while(q--) {
        int x1, y1, x2, y2, c;
        cin >> x1 >> y1 >> x2 >> y2 >> c;
        insert(x1, y1, x2, y2, c);
    }

    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= m; j++) {
            b[i][j] = b[i][j] + b[i-1][j] + b[i][j-1] - b[i-1][j-1];
            cout<<b[i][j] << ' ';
        }
        puts("");
    }


    return 0;
}