A

#include<bits/stdc++.h>
#define ll long long

using namespace std;

int main()
{
    int n;
    cin >> n;
    while (n >= 2){
        cout << n-- << ",";
    }
    cout << 1;
        
    return 0;
}

B

#include<bits/stdc++.h>
#define ll long long

using namespace std;

int t[110][110];

int main()
{
    int n;
    cin >> n;
    for (int i = 1; i < n; i++){
        for (int j = i+1; j <= n; j++)
            cin >> t[i][j];
    }
    
    for (int a = 1; a <= n-2; a++)
        for (int b = a+1; b <= n-1; b++)
            for (int c = b+1; c <= n; c++)
                if (t[a][b]+t[b][c] < t[a][c]){
                    cout << "Yes";
                    return 0;
                }
    cout << "No";
    
    return 0;
}

C

#include<bits/stdc++.h>
#define ll long long

using namespace std;

char g[1010][1010];
int dx[] = {0,1,0,-1}, dy[] = {1,0,-1,0};
int n, m;

void dfs(int x, int y){
    if (g[x][y] == '.') g[x][y] = '#';
    for (int i = 0; i < 4; i++){
        int nx = x + dx[i];
        int ny = y + dy[i];
        if (nx >= 1&&nx <= n&&ny >=1 &&ny <= m&&g[nx][ny]=='.')
            dfs(nx, ny);
    }
}

int main()
{

    cin >> n >> m;
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++)
            cin >> g[i][j];
    
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++){
            if ((i == 1 || i == n || j == 1 || j == m) && g[i][j] == '.'){
                dfs(i, j);
            }
        }
    int cnt = 0;
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++){
            if (g[i][j] == '.'){
                dfs(i, j);
                cnt++;
            }
        }
    cout << cnt;
    return 0;
}

/*
思路:
1.从边界dfs将'.'标记
2.dfs统计内部'.'的数量
*/

D

#include<bits/stdc++.h>
#define ll long long

using namespace std;

vector<ll> s;
int main()
{
    ll n, k, maxn = 0;
    cin >> n >> k;
    for (int i = 1; i <= n; i++){
        ll x; cin >> x;
        maxn = max(maxn, x);
        s.push_back(x);
    }
    
    for (int i = 0; i < s.size(); i++){
        s[i] = (maxn-s[i])/k*k+s[i];
    }
    
    sort(s.begin(), s.end());
    s.erase(unique(s.begin(),s.end()), s.end());
    
    ll ans = maxn - s[0];
    for (int i = 0; i < s.size()-1; i++){
        ans = min(ans, s[i]+k-s[i+1]);
    }
    cout << ans;

    return 0;
}

/*
思路:
1.将所有数操作缩减到长度为k的区间(尽可能逼近最大值,也就是转换为比最大值小的最大的数)
2.排序去重
3.初始最小值为s[1]最大值为s[len-1]
遍历每个数,令其+k,当前最大值为s[i]+k,最小值为s[i+1]
*/