头像

AndyLZA




离线:2天前


最近来访(31)
用户头像
kkklll
用户头像
笑脸人
用户头像
no_one
用户头像
xihb183
用户头像
incra
用户头像
VALUE_5
用户头像
二研为定

活动打卡代码 AcWing 4416. 缺少的数

AndyLZA
26天前
#pragma GCC optimize(1)
#pragma GCC optimize(2)
#pragma GCC optimize(3)

#include <bits/stdc++.h>

using namespace std;

const int max_N = 100010;
bool a[max_N];

int main()
{
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    for (int i = 0; i < n; ++ i)
    {
        int t;
        cin >> t;
        a[t] = true;
    }
    for (int i = 1; i <= n; ++ i)
    {
        if (a[i] == false)
            cout << i;
    }
    return 0;
}


活动打卡代码 AcWing 898. 数字三角形

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

using namespace std;

const int max_N = 510;
const int MIN_INF = -0x3f3f3f3f;

int a[max_N][max_N];
int n = 0;
int dp[max_N][max_N];


int main()
{

    cin >> n;
    for (int i = 0; i < n; ++i)
    {
        for (int j = 0; j <= i; ++j)
        {
            cin >> a[i][j];
        }
    }
    dp[0][0]= a[0][0];
    for(int i = 1;i<=n-1;i++){
        for(int j=0; j<= i; j++){
            if (j == 0){
                dp[i][j] = dp[i-1][j] + a[i][j];
            }else if(i==j){
                dp[i][j] = dp[i-1][j-1] + a[i][j];
            }else{
                dp[i][j] = max(dp[i-1][j-1],dp[i-1][j]) + a[i][j];
            }
        }
    }
    int mx = MIN_INF;
    for (int j = 0; j < n; j++){
        mx = max(mx, dp[n-1][j]);
    }
    cout << mx;
    return 0;
}



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

using namespace std;

const int MAX_N = 1e5 + 10;
vector<int> G[MAX_N];
int degree[MAX_N];

void bfs(int n){
    vector<int> tuopu;
    queue<int> q;
    for (int i = 1; i <= n; i++){
        if (degree[i] == 0){
            q.push(i);
        }    
    }
    while(!q.empty()){
        int top = q.front();
        q.pop();
        tuopu.push_back(top);
        for(int v : G[top]){
            degree[v]--;
            if (degree[v] == 0)
                q.push(v);
        }
    }
    if (tuopu.size() == n){
        for(int v : tuopu){
            cout << v << " ";
        }
    }else{
        cout << "-1";
    }
}

int main(){
    int n , m;
    cin >> n >> m;
    for(int i = 0; i < m; ++i){
        int a, b;
        cin >> a >> b;
        degree[b]++;
        G[a].push_back(b);
    }
    bfs(n);
    return 0;
}


活动打卡代码 AcWing 474. 龙虎斗

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

using namespace std;

typedef long long LL;

const int max_N = 100010;
int n, m, p1, s1;

int op(float x)
{
    if(x - (int)x == 0)
        return x;
    if (x > 0 && x < 1)
        return 1;
    if (x < 0 && x > -1)
        return -1;
    else
    {
        if (x > 0)
        {
            if (x - floor(x) <= 0.5)
                return x;
            else return x + 1;
        }
        else{
            if (floor(x) - x + 1 < 0.5)
                return x;
            else return x - 1;  
        } 
    }
}

int main()
{

    // cout << op(-0.1) << endl; // -1
    // cout << op(-0.5) << endl; // -1
    // cout << op(-0.7) << endl; // -1
    // cout << op(0.1) << endl; // 1
    // cout << op(0.5) << endl; // 1
    // cout << op(0.7) << endl; // 1
    // cout << op(3) << endl; // 3
    // cout << op(3.1) << endl; // 3
    // cout << op(3.5) << endl; // 3
    // cout << op(3.7) << endl; // 4
    // cout << op(-3) << endl; // -3
    // cout << op(-3.1) << endl; // -3
    // cout << op(-3.5) << endl; // -4
    // cout << op(-3.7) << endl; // -4
    // return 0;
    int n, m, p1, s1;
    float s2;
    int s[max_N];
    cin >> n;
    for (int i = 1; i <= n; ++i)
        cin >> s[i];
    cin >> m >> p1 >> s1 >> s2;
    s[p1] += s1;
    LL qi_l, qi_h;
    for (int i = 1; i < m; ++i)
        qi_l += (m - i) * s[i];
    for (int i = m + 1; i <= n; ++i)
        qi_h += (i - m) * s[i];
    int d = qi_l - qi_h;
    if (d == 0)
    {
        cout << m;
        return 0;
    }
    // cout << d / s2<< endl;
    int d1 = m + op(d / s2);
    if (d1 > d)
        cout << m;
    else
        cout << d1;
    return 0;
}


活动打卡代码 AcWing 461. 金币

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

using namespace std;
int main(){
    int n, a, b;
    cin >> n;
    while (n>0)
    {
        a += n;
        ++b;
        n -= b;
    }
    cout << a;
    return 0;
}


活动打卡代码 AcWing 462. 扫雷游戏

AndyLZA
1个月前
//
// Created by 86135 on 2021/7/30.
//
#include <bits/stdc++.h>
using namespace std;
int main(){
    int booms[102][102] = {0}; //存放是否有地雷 边上的行列是墙,没有地雷,方便对一个单元格周边地雷数计数使用。
    int n,m; //n行 m列
    char c;  //c=='*'代表地雷
    cin >> n >> m;
    for (int i = 1;i <= n;++i) {
        for (int j = 1;j <= m;++j) {
            cin >> c;
            if (c == '*')
                booms[i][j] = 1;
        }
    }

    for (int i = 1;i <= n;++i) {
        for (int j = 1;j <= m;++j) {
            if (booms[i][j] == 1){
                cout << '*';
            }else {
                int temp = 0;
                if(booms[i][j + 1] == 1)temp ++;
                if(booms[i][j - 1] == 1)temp ++;
                if(booms[i + 1][j + 1] == 1)temp ++;
                if(booms[i + 1][j - 1] == 1)temp ++;
                if(booms[i + 1][j] == 1)temp ++;
                if(booms[i - 1][j + 1] == 1)temp ++;
                if(booms[i - 1][j - 1] == 1)temp ++;
                if(booms[i - 1][j] == 1)temp ++;
                cout << temp;
            }
        }
        cout << endl;
    }

    return 0;
}


活动打卡代码 AcWing 465. 买铅笔

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

using namespace std;

int main()
{
    int n;
    cin >> n;
    int res = 1e9;
    for (int i = 0; i < 3; ++ i )
    {
        int a, b;
        cin >> a >> b;
        res = min(res, (n + a - 1) / a * b);
    }
    cout << res;
    return 0;
}


活动打卡代码 AcWing 466. 回文日期

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

using namespace std;

int month[2][13] = {0,31,28,31,30,31,30,31,31,30,31,30,31,0,31,29,31,30,31,30,31,31,30,31,30,31};

bool judge(int a){
    return 1;
}
bool judgey(int y){
    if((y % 4 == 0) && (y % 400 != 0))return 1;
    return 0;
}

int main(){
    int d1 , d2 , count;
    count = 0;
    cin >> d1 >> d2;
    if (judge(d1)) count++;
    for(; d1 != d2;){
        int y , m;

        y = (d1 - d1 % 10000)/10000;
        m = (d1 % 10000 - d1 % 100)/1000;
        d1++;
        if(month[judgey(y)][m] < d1 % 100){
            d1 = d1 + 100 - (d1 % 100) + 1;
            m++;
        }
        if(m > 12){
            d1 = d1 - 1200 + 10000;
        }
        if (judge(d1)) {
            cout << d1 << endl;
           count++; 

        }
    }
    cout << count;
    return 0;
}


活动打卡代码 AcWing 446. 统计单词数

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

using namespace std;

char c(char a){
    if('A' <= a <= 'Z'){
        a = a + 32;
    }
    return a;
}

int main()
{
    string a,b;

    getline(cin,a);
    getline(cin,b);

    for(long unsigned int i = 0; i < a.length(); ++i){
        c(a[i]);
    }
    for(long unsigned int i = 0; i < a.length(); ++i){
        c(b[i]);
    }

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

    int f=b.find(a);
    int f1 = f;
    int res=0;
    if(f != -1){
        f1=f;
        while(f1 != -1){
            res ++ ;
            f1=b.find(b[0] , b[0] + f1 , a);
        }
    }else{
        cout<<-1<<endl;
        return 0;
    }

    cout<<res<<" "<<f <<endl;


    return 0;
}


活动打卡代码 AcWing 470. 图书管理员

AndyLZA
1个月前
//
// Created by 86135 on 2021/8/24.
//

#include<bits/stdc++.h>

using namespace std;

const int max_N = 1000 + 10;
struct inf{
    int l;
    int n;
}need[max_N];

int book[max_N];

int search(int l , int num , int n){
    int p;
    for(int i = 0; i < n; ++i){
        p = pow(10 , l);
        if((book[i] % p) == num)return book[i];
    }
    return -1;
}

int main(){
    char f = '*';
    int n , q;
    cin >> n >> q;
    for(int i = 0; i < n; ++i){
        cin >> book[i];
    }
    for(int i = 0; i < q; ++i){
        cin >> need[i].l >> need[i].n;
    }
    sort(book , book + n);
    for(int i = 0; i < q; ++i){
        cout << search(need[i].l , need[i].n , n) << endl;
    }
    return 0;
}