头像

zlspractice




在线 


最近来访(1)
用户头像
520coder

活动打卡代码 AcWing 609. 工资

zlspractice
2分钟前
import java.util.Scanner;
public class Main
{
    public static  void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt(),b = sc.nextInt();
        double c = sc.nextDouble() ;
        System.out.printf("NUMBER = %d\n",a);
        System.out.printf("SALARY = U$ %.2f",b * c);
    }
}


活动打卡代码 AcWing 606. 平均数1

zlspractice
3分钟前
import java.util.Scanner;
public class Main
{
    public static void main(String[] args) 
    {
        Scanner sc = new Scanner(System.in);
        double a = sc.nextDouble(),b = sc.nextDouble();
        System.out.printf("MEDIA = %.5f\n",a * 3.5 / 11 + b * 7.5 / 11);
    }
}


活动打卡代码 AcWing 604. 圆的面积

zlspractice
4分钟前
import java.util.Scanner;
public class Main
{
    public static final double pi = 3.14159;
    public static void main(String [] args)
    {
        Scanner sc = new Scanner(System.in);
        double r = sc.nextDouble();
        System.out.printf("A=%.4f\n",pi * r * r);
    }
}


活动打卡代码 AcWing 608. 差

zlspractice
10分钟前
import java.util.Scanner;
public class Main
{
    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt(),b = sc.nextInt(),c = sc.nextInt(),d = sc.nextInt();
        System.out.printf("DIFERENCA = %d\n",a * b - c * d);
    }
}


活动打卡代码 AcWing 1. A + B

zlspractice
12分钟前
import java.util.Scanner;
public class Main
{
    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt(),b = sc.nextInt();
        System.out.println(a + b);
    }
};



活动打卡代码 AcWing 1128. 信使

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

const int N = 105;

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

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    memset(g,0x3f,sizeof g);
    cin >> n >> m;
    for ( int i = 0;i < m;i++ )
    {
        cin >> a >> b >> c;
        g[a][b] = g[b][a] = min(g[a][b],c);
    }

    for ( int i = 1;i <= n;i++ ) g[i][i] = 0;//          对角线上初始化为0,否则会错

    for ( int k = 1;k <= n;k++ )
        for ( int i = 1;i <= n;i++ )
            for ( int j = 1;j <= n;j++ )
                g[i][j] = min(g[i][j],g[i][k] + g[k][j]);

    // for ( int i = 1;i <= n;i++ )
    // {
    //     for ( int j = 1;j <= n;j++ )
    //     cout << g[i][j] << ' ';
    //     cout << '\n';
    // }
    int ret = -1;
    for ( int i = 1;i <= n;i++ ) ret = max(ret,g[1][i]);
    if ( ret == 0x3f3f3f3f ) ret = -1;
    cout << ret;
    return 0;
}



活动打卡代码 AcWing 165. 小猫爬山

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

const int N = 20;
int n,c;
int ans = N;
int w[N],capacity[N];
bool st[N];


bool cmp(int &a,int &b)
{
    return a > b;
}

void dfs(int u,int k)//下标为u的猫 和 k个缆车
{
    if ( k >= ans ) return;//最优性剪枝
    if ( u == n )
    {
        ans = k;
        return;
    }
    for ( int i = 0;i < k;i++ )
    {
        if ( capacity[i] + w[u] <= c )//可行性剪枝
        {
            capacity[i] += w[u];
            dfs(u + 1,k);
            capacity[i] -= w[u];
        }
    }
    capacity[k] = w[u];
    dfs(u + 1,k + 1);
    capacity[k] = 0;

}

int main()
{
    cin >> n >> c;
    for ( int i = 0;i < n;i++ ) cin >> w[i];
    sort(w,w + n,cmp);

    dfs(0,0);

    cout << ans << endl;
    return 0;
}


活动打卡代码 AcWing 1117. 单词接龙

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

const int N = 23;
string word[N];
int used[N],g[N][N];
int n,ret;
char ch;
string start;


void dfs(string dragon,int last)
{
    ret = max(ret,(int)dragon.size());//相同类型的参数才可以比较   size_t先转换成int  再和int一起传入

    used[last]++;

    for ( int i = 0;i < n;i++ )
    {
        if ( g[last][i] != 0 && used[i] < 2 )
        dfs(dragon + word[i].substr(g[last][i]),i);
    }

    used[last]--;
}

int main()
{
    cin >> n;
    for ( int i = 0;i < n;i++ ) cin >> word[i];
    cin >> ch;

    for ( int i = 0;i < n;i++ )
    {
        for ( int j = 0;j < n;j++ )
        {
            string a = word[i],b = word[j];
            int len = min((int)a.size(),(int)b.size());
            for ( int k = 1;k < len;k++ )
            {
                if ( a.substr(a.size() - k,k) == b.substr(0,k) )
                {
                    g[i][j] = k;
                    break;
                }
            }
        }
    }

    for ( int i = 0;i < n;i++ )
    {
        if ( word[i][0] == ch )
            dfs(word[i],i);
    }

    cout << ret << endl;
    return 0;
}


活动打卡代码 AcWing 1116. 马走日

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

const int N = 12;
bool st[N][N];
int T,m,n,x,y;
int dx[] = {-2,-1,1,2,2,1,-1,-2};
int dy[] = {1,2,2,1,-1,-2,-2,-1};

int ans = 0;

void dfs(int x,int y,int cnt)
{
    if ( cnt == n * m )//只有在全部覆盖满的时候答案才加一,即这个搜索树的叶子结点
    {
        ans++;
        return;
    }
    st[x][y] = 1;
    for ( int i = 0;i < 8;i++ )
    {
        int a = x + dx[i],b = y + dy[i];
        if ( a < 0 || a >= m || b < 0 || b >= n ) continue;
        if ( st[a][b] ) continue;
        dfs(a,b,cnt + 1);
    }
    st[x][y] = 0;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    cin >> T;
    while(T--)
    {
        memset(st,0,sizeof st);
        ans = 0;

        cin >> m >> n >> x >> y;
        dfs(x,y,1);
        cout << ans << '\n';
    }
    return 0;
}


活动打卡代码 AcWing 1113. 红与黑

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

const int N = 105;
bool st[N][N];
char g[N][N];
int m,n;
int ans = 1;

int dx[] = {-1,0,1,0};
int dy[] = {0,1,0,-1};

void dfs(int sx,int sy)
{
    st[sx][sy] = 1;
    for ( int i = 0;i < 4;i++ )
    {
        int a = sx + dx[i],b = sy + dy[i];
        if (a < 0 || a >= m || b < 0 || b >= n ) continue;
        if ( st[a][b] || g[a][b] == '#' ) continue;
        ans++;
        dfs(a,b);
    }
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    while(cin >> n >> m)
    {
        if ( m == 0 && n == 0 ) break;
        memset(st,0,sizeof st);
        ans = 1;  

        for (int i = 0;i < m;i++ ) cin >> g[i];

        int x,y;
        for ( int i = 0;i < m;i++ )
        for ( int j = 0;j < n;j++ )
        {
            if ( g[i][j] == '@' )
            {
                x = i;
                y = j;
            }
        } 
        dfs(x,y);
        cout << ans << '\n';
    }
    return 0;
}