也是暴力
2024-07-08 09:19:29
发布于:广东
19阅读
0回复
0点赞
#include <iostream>
#include <vector>
#include <string>
#include <climits>
using namespace std;
int main() {
    int n;
    string s;
    cin >> n >> s;
    vector<int> positions;
    for (int i = 0; i < n; ++i) {
        if (s[i] == '*') {
            positions.push_back(i);
        }
    }
    int m = positions.size();
    if (m == 0) {
        cout << 0 << endl;
        return 0;
    }
    int median_index = m / 2;
    int median_position = positions[median_index];
    long long min_moves = 0;
    for (int j = 0; j < m; ++j) {
        min_moves += abs(positions[j] - (median_position - median_index + j));
    }
    cout << min_moves << endl;
    return 0;
}
全部评论 1
好了,这下我知道是谁写的了(
2024-07-08 来自 广东
0阿弥诺斯
2024-07-08 来自 广东
0








有帮助,赞一个