头像

今天编程了吗




离线:5小时前


最近来访(8)
用户头像
nacho_shizuku
用户头像
x6x
用户头像
21KINGDMG
用户头像
索隆
用户头像
A我的pig皮皮
用户头像
叮叮当
用户头像
李淞


#include<iostream>
#include<cstring>
#include<queue>
using namespace std;

typedef pair<int, int>  PII;

const int N = 110;
int g[N][N], d[N][N];//g[][]存图, d[][]层数也就是搜索到的点的距离
int n, m;

int bfs(){
    int dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1};
    queue <PII> q;

    memset(d, -1, sizeof d);

    d[0][0] = 0;//第一个元素开始搜索
    q.push({0, 0});//将第一个点入队

    while(!q.empty()){//当队列不为空的时候
        auto t = q.front();
        q.pop();//获取队头元素,将其出队

        for(int i = 0; i < 4; i ++ ){
            int x = t.first + dx[i], y = t.second + dy[i];

            if(x >= 0 && x < n && y >= 0 && y < m && g[x][y] == 0 && d[x][y] == -1){//点未出界,该点可走且没走过
                d[x][y] = d[t.first][t.second] + 1;//距离+1
                q.push({x, y});//新的点入队
            }
        }
    }

    return d[n - 1][m - 1];
}

int main(){
    cin >> n >> m;
    for(int i = 0; i < n; i ++){
        for(int j = 0; j < m; j ++ ){
            cin >> g[i][j];
        }
    }

    cout << bfs() << endl;

    return 0;
}



#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
int s[1000];
int main()
{
    string a,b;
    getline(cin,a);
    getline(cin,b);
    for(int i = 0;i < a.size();i++)
    {
        if(a[i] >= 'A' && a[i] <= 'Z')
        a[i] += 32;
    }
    for(int i = 0;i < b.size();i++)
    {
        if(b[i] >= 'A' && b[i] <= 'Z')
        b[i] += 32;
    }
    int c ;
    c = strcmp(a.c_str(),b.c_str());
    if(c < 0) cout << "<";
    else if(c == 0)cout <<"=";
    else if(c > 0)cout << ">";
    return 0;
}


活动打卡代码 AcWing 762. 字符串匹配

#include<cstdio>
#include<iostream>
using namespace std;
// char s[10000];
int main()
{
    double k;
    double cnt = 0;
    string a,b;
    cin >> k >> a >> b;
    double len = a.size();
    for(int i = 0;i < len;i++) 
    {
        if(a[i] == b[i]) cnt++;
    }
    cnt /= len;
    if(k <= cnt)
    {
        cout << "yes";
        return 0;
    }
    else  cout << "no";
    return 0;
}




#include<iostream>
#include<cstring>
using namespace std;
int s[100];
char str[100000];
int main()
{
    cin>>str;
    for(int i=0;str[i];i++) s[str[i]-'a']++;
    for(int i=0;str[i];i++)
    {
        if(s[str[i]-'a']==1)
        {
            cout<<str[i]<<endl;
            return 0;
        }
    }
    puts("no");
    return 0;
}


活动打卡代码 AcWing 773. 字符串插入

#include<cstdio>
#include<iostream>
using namespace std;
int main()
{
    string s;
    getline(cin,s);
    for(int i = 0;i < s.size();i++)
    cout << s[i] << ' ';
    return 0;
}



class Solution {
public:
    int strToInt(string str) {
        int k = 0;
        while(k < str.size() && str[k] == ' ') k++;
        long long number = 0;
        bool is_minus = false;
        if(str[k] == '+') k++;
        else if(str[k] == '-') k++,is_minus = true;
        while(k < str.size() && str[k] >= '0' && str[k] <= '9')
        {
            number = number*10 + str[k] - '0';
            k ++;
        }
        if(is_minus) number *=-1;
        if(number > INT_MAX) number = INT_MAX;
        if(number < INT_MIN) number = INT_MIN;
        return (int)number;
    }
};



#include<iostream>

using namespace std;

const int N = 50010;

int p[N], n, m, d[N];

int find(int x){
    if(x != p[x]){
        int t = find(p[x]);
        d[x] += d[p[x]];
        p[x] = t;
    }

    return p[x];
}

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

    for(int i = 1; i <= n; i ++ ) p[i] = i;

    int res = 0;
    while(m --){
        int k, x, y;
        scanf("%d%d%d", &k, &x, &y);
        if(x > n || y > n) res ++;
        else{
            int px = find(x), py = find(y);
            if(k == 1){
                if(px == py && (d[x] - d[y]) % 3) res ++; 
                //根节点相同且到根节点的距离模3不同时是假(不是同类,而k=1表示是同类为假)
                // 根节点相同只能证明已经添加过关系了!
                else if(px != py){
                    p[px] = py;
                    d[px] = d[y] - d[x];//(d[px] + d[x] - d[y]) % 3 = 0 ----> d[px] = d[y] - d[x];【见附图】
                }
            }
            else{ // k == 2, x 吃 y
                if(px == py && (d[x] - d[y] - 1) % 3) res ++;
                else if(px != py){
                    p[px] = p[y];
                    d[px] = d[y] + 1 - d[x]; // (d[px] + d[x] - d[y] - 1) % 3=0 【见附图】
                }
            }
        }
    }
    printf("%d", res);

    return 0;
}

屏幕截图 2021-11-18 204527.jpg



活动打卡代码 AcWing 669. 加薪

#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
    double salary;
    cin >> salary;
    if(salary >=0 && salary <= 400) 
    {
        printf("Novo salario: %.2lf\n",salary*(1+0.15));
        printf("Reajuste ganho: %.2lf\n",salary*0.15);
        printf("Em percentual: 15 %\n");
    }

    if(salary >400 && salary <= 800) 
    {
        printf("Novo salario: %.2lf\n",salary*(1+0.12));
        printf("Reajuste ganho: %.2lf\n",salary*0.12);
        printf("Em percentual: 12 %\n");
    }

    if(salary >800 && salary <= 1200) 
    {
        printf("Novo salario: %.2lf\n",salary*(1+0.1));
        printf("Reajuste ganho: %.2lf\n",salary*0.1);
        printf("Em percentual: 10 %\n");
    }

    if(salary >1200 && salary <= 2000) 
    {
        printf("Novo salario: %.2lf\n",salary*(1+0.07));
        printf("Reajuste ganho: %.2lf\n",salary*0.07);
        printf("Em percentual: 7 %\n");
    }

    if(salary >2000) 
    {
        printf("Novo salario: %.2lf\n",salary*(1+0.04));
        printf("Reajuste ganho: %.2lf\n",salary*0.04);
        printf("Em percentual: 4 %\n");
    }

}


活动打卡代码 AcWing 667. 游戏时间

#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
    int A,B,t;
    cin >> A >> B;
    if(A==B) t=24;
    else if(B>A) t=B-A;
    else if(B<A) t=B-A+24;
    printf("O JOGO DUROU %d HORA(S)",t);
    return 0;
}


活动打卡代码 AcWing 664. 三角形

#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
    double A,B,C;
    cin >> A >> B >> C;
    if((A+B) > C && (B+C) > A && (A+C) > B) printf("Perimetro = %.1lf",A+B+C);
    else printf("Area = %.1lf",(A+B)*C/2);
}