头像

cassie




离线:2天前


最近来访(13)
用户头像
five_
用户头像
RyanMoriarty
用户头像
樂_6
用户头像
undatinx
用户头像
lchlchlch123
用户头像
xxxxxxx


cassie
2天前
#include<bits/stdc++.h>
using namespace std;

int main(){


vector< vector<int> > array;
    for (int i = 0; i < 5; i++)
    {
        array.push_back(vector<int>());//不断往array里加行 
    }
    for (int i = 0; i < array.size(); i++)//行 
    {
        for (int j = 0; j < 5; j++)//添加5列 
        {
            array[i].push_back(i + j);
        }
    }
    for (int i = 0; i < array.size(); i++)
    {
        for (int j = 0; j < 5; j++)
        {
            cout << array[i][j] << " ";//使用下标访问 
        }
        cout << endl;
    }
    return 0;
}

初始化

第一种

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

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

    vector< vector<int> > a(n, vector<int>(2*n, 0));

    for(int i = 0; i < n ; i ++){
        for(int j = 0; j < 2 * n; j ++) cout << a[i][j] <<" ";
        cout << endl;
    }

       return 0;

}

第二种

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

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

    vector<vector<int> >vv;  
      for(int c = 1; c <= n; c++)  
      vv.push_back(vector<int>(n,0));

    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
        {
            cout << vv[i][j] << " ";
        }
        cout << endl;
    }
       return 0;

}



cassie
5天前
#include<bits/stdc++.h>
using namespace std ;

const int N = 1e6 + 10;
int a[N];

int main(){
    int t ;
    cin >> t;
    while(t --){
        int n;
        cin >> n;
        int maxn = 0;

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

        int  sum = 0;
        for(int i = 0;i < 2 *n; i ++) {
            if (a[i] == 1) sum ++;
            if (a[i] == 0){
                maxn = max( sum , maxn);
                sum = 0;
            } 
        }
        cout << maxn << endl;

    }
    return 0;
}


活动打卡代码 AcWing 787. 归并排序

cassie
17天前
#include<bits/stdc++.h>
using namespace std;

const int N = 1e6 + 10;
int a[N], tmp[N];
int n;

void merge_sort(int a[], int l, int r){
    if (l >= r) return;

    int mid = l + r >> 1, i = l, j = mid + 1;
    int k = 0;

    merge_sort(a, l, mid), merge_sort(a, mid + 1, r);

    while(i <= mid && j <= r) 
        if (a[i] < a[j]) tmp[k ++] = a[i ++];
        else tmp[k ++] = a[j ++];
    while(i <= mid) tmp[k ++] = a[i ++];
    while(j <= r) tmp[k ++] = a[j ++];

    for(i = l, j = 0; i <= r ; i ++, j ++ ) a[i] = tmp[j];
}

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

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

    merge_sort(a, 0, n - 1);

    for(int i = 0; i < n; i ++) printf("%d ", a[i]);
    return 0;
}


活动打卡代码 AcWing 786. 第k个数

cassie
19天前
#include<bits/stdc++.h>

using namespace std;

const int N = 1e6 + 10;
int n, a[N];

void quick_sort(int a[], int l , int r){
    if ( l >= r) return ;
    int x = a[(l + r) >> 1] , i = l - 1, j = r + 1;
    while (i < j){
        do i ++; while (a[i] < x);
        do j --; while (a[j] > x);
        if (i < j ) swap ( a[i], a[j]);
    }
    quick_sort(a, l, j);
    quick_sort(a, j + 1 ,r );
}

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

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

    quick_sort(a, 0 , n - 1);

    printf("%d", a[k-1]);
    return 0;
}


活动打卡代码 AcWing 3762. 二进制矩阵

cassie
24天前
#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;

const int N = 110;

int n, m;
char g[N][N];

void pL(int i, int j, int k)
{
    if (!k) printf("%d %d %d %d %d %d\n", i, j, i + 1, j, i, j + 1);
    else if (k == 1) printf("%d %d %d %d %d %d\n", i, j - 1, i, j, i + 1, j);
    else if (k == 2) printf("%d %d %d %d %d %d\n", i - 1, j, i, j, i, j - 1);
    else printf("%d %d %d %d %d %d\n", i - 1, j, i, j, i, j + 1);
}

int main()
{
    int T;
    cin >> T;
    while (T -- )
    {
        cin >> n >> m;
        int res = 0;
        for (int i = 1; i <= n; i ++ )
        {
            cin >> g[i] + 1;
            for (int j = 1; j <= m; j ++ )
                if (g[i][j] == '1')
                    res += 3;
        }
        cout << res << endl;
        for (int i = 1; i <= n; i ++ )
            for (int j = 1; j <= m; j ++ )
                if (g[i][j] == '1')
                {
                    if (i < n && j < m)
                        pL(i, j, 0), pL(i, j + 1, 1), pL(i + 1, j, 3);
                    else if (i == n && j == m)
                        pL(i, j, 2), pL(i - 1, j, 1), pL(i, j - 1, 3);
                    else if (i == n)
                        pL(i, j, 3), pL(i - 1, j, 0), pL(i, j + 1, 2);
                    else
                        pL(i, j, 1), pL(i, j - 1, 0), pL(i + 1, j, 2);
                }
    }
    return 0;
}



cassie
24天前
#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;

int main()
{
    string a;
    int t ;
    cin >> t;
    while (t --){
        cin >> a;
        string x;
        int  m = 0;
        for ( char c : a ){
            if ( m == 5 ){
                m = 0;continue;
            }  
            if ( c == '0') m = 0;
            if ( c == '1') m ++; 
            x += c;
        }
        cout << x << endl;
    }
    return 0;
}


活动打卡代码 AcWing 3814. 矩阵变换

cassie
1个月前
#include<bits/stdc++.h>
using namespace std;

string a[110];
int b[110]= {1};

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

    for(int i = 1 ; i < n ; i ++ ){
        for( int j = 0 ; j <= i ; j ++){
            if( a[i] == a[j]) {
                b[j] ++ ;
                if ( b[j] > max) max = b[j];
                break;
            }
        }
    }

    cout << max;
    return 0;

}


活动打卡代码 AcWing 3824. 在校时间

cassie
1个月前
#include<bits/stdc++.h>

using namespace std;
bool a[110]; 

int main(){
    int T;
    cin >> T;
    while(T --){
        int n, sum = 0;
        cin >> n;
        for (int i = 0; i < n; i++) {
            cin >> a[i];
            if ( i > 1 )
                if ( a[i] && !a[i-1] && a[i-2]) a[i-1] = 1; 
        }
        for (int i = 0; i < n ; i ++ ) if (a[i]) sum ++;
        cout << sum << endl;

    }
    return 0;

}


活动打卡代码 AcWing 2767. 优秀的拆分

cassie
2个月前
#include<iostream>
using namespace std;
int main(){
    int n;
    cin >> n;
    if ( n % 2 == 1) 
        cout << "-1"<<endl;
    else {
         for ( int i = 23; i >= 0;i--)
            if ( n >> i & 1) printf ( "%d ", 1 << i);


    }

    return 0;
}


活动打卡代码 AcWing 785. 快速排序

cassie
2个月前
#include<iostream>

using namespace std;

const int N = 1e6 + 10;

int n, q[N];

void quick_sort(int q[], int l, int r )
{
    if(l >= r)return ;
    int i = l - 1, j = r + 1, x = q[l + r >> 1];
    while(i < j)
    {
        do i ++; while (q[i] < x);
        do j --; while (q[j] > x);
        if ( i < j ) swap( q[i], q[j]);
    }
        quick_sort(q, l, j); 
        quick_sort(q, j + 1, r);

}

int main()
{
    scanf("%d", &n);
    for (int i = 0 ; i < n ; i++) scanf("%d", &q[i]);
    quick_sort(q, 0, n - 1);
    for (int i = 0; i < n; i ++) printf ("%d ", q[i]);
    return 0;
}