1926(div4)

A. Vlad and the Best of Five

给定长度为 5 的字符串,输出 A 多还是 B 多

std::cout << count(s.begin(), s.end(), 'A') >= 3 ? 'A' : 'B' << "\n";

B. Vlad and Shapes

判断矩阵中 1 组成的是三角形还是正方形

00100
01110
11111
111
111
111
void solve() {
    int n;cin >> n;
    vector<string> a(n);
    for (int i = 0;i < n;i++) {
        for (int j = 0;j < n;j++) {
            cin >> a[i][j];
        }
    }
    for (int i = 0;i < n;i++) {
        for (int j = 0;j < n;j++) {
            if (a[i][j] == '1') {
                int cnt = 0;
                for (int k = i;k < n;k++) {
                    if (a[k][j] != '1')break;
                    cnt++;
                }
                if (cnt == 1) {
                    cout << "TRIANGLE\n";return;
                }
                for (int k = j;k < n;k++) {
                    if (a[i][k] != '1')break;
                    cnt--;
                }
                if (cnt == 0) { cout << "SQUARE\n";return; } else { cout << "TRIANGLE\n"; return; }
            }
        }
    }
}
for (int i = 0; i < n; i++) {
	if count(s[i].begin(), s[i].end(), '1') == 1 {
		std::cout << "TRIANGLE\n";
		return;
	}
}
std::cout << "SQUARE\n";

C. Vlad and a Sum of Sum of Digits

输出 1n 数位和 之和,

vector<int> a(2e5 + 1);
int main() {
    ios::sync_with_stdio(false), cin.tie(nullptr);
    a[1] = 1;
    for (int i = 2;i <= 2e5;i++) {
        string s = to_string(i);
        int cnt = 0;
        for (int i = 0;i < s.size();i++) {
            cnt += s[i] - '0';
        }
        a[i] = a[i - 1] + cnt;
    }
    int _ = 1;
    cin >> _;
    while (_--){
	    int n; cin >> n;
	    cout << a[n] << '\n';
    }
}

D. Vlad and Division

给定一个数组 a,如果两个数字二进制 131 位都不一样,则可以分到一组,求 a 至少分为多少组


(待更 )