标签:code int cin long ++ num using
A
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
void solve() {
int n;
cin >> n;
vector<int> g[n];
vector<int> dep(n), cnt(n);
for (int i = 0; i < n - 1; i++) {
int x, y;
cin >> x >> y;
x--;
y--;
g[x].push_back(y);
g[y].push_back(x);
}
dep[0] = 1;
function<void(int, int)> dfs = [&](int cur, int pre) {
cnt[cur]++;
for (auto x : g[cur]) {
if (x != pre) {
dep[x] = dep[cur] + 1;
dfs(x, cur);
cnt[cur] += cnt[x];
}
}
};
dfs(0, -1);
for (int i = 0; i < n; i++) {
cout << dep[i] << ' ' << n + 1 - cnt[i] << '\n';
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int tt = 1;
cin >> tt;
for (int _ = 1; _ <= tt; _++) {
solve();
}
return 0;
}
E
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
void solve() {
int n, m;
cin >> n >> m;
auto get = [&](string s) {
int num = 0;
s.pop_back();
if (s == "A") {
num = 14;
} else if (s == "K") {
num = 13;
} else if (s == "Q") {
num = 12;
} else if (s == "J") {
num = 11;
} else if (s == "T") {
num = 10;
} else {
num = stoi(s);
}
return num;
};
vector<int> a(n);
for (int i = 0; i < n; i++) {
string s;
cin >> s;
a[i] = get(s);
}
vector<int> b(m);
for (int i = 0; i < m; i++) {
string s;
cin >> s;
b[i] = get(s);
}
string s;
cin >> s;
int pro = get(s);
sort(a.begin(), a.end());
sort(b.begin(), b.end());
// 必败
if (n == 1 || b[0] >= pro || a[0] >= pro) {
cout << "Shou" << '\n';
return;
}
int big = *prev(lower_bound(a.begin(), a.end(), pro));
if (m == 1 && b[0] > big) {
cout << "Shou" << '\n';
return;
}
// 必胜
// Bob手里只有一张牌
if (m == 1 && b[0] < pro) {
cout << "Pang" << '\n';
return;
}
// Bob手里有两张小牌
if (m >= 2 && b[0] < pro && b[1] < pro) {
cout << "Pang" << '\n';
return;
}
//特殊情况
if (n > 3 && b[0] <= big && b.back() < a.back() && a[0] < pro && a[1] < pro) {
cout << "Pang" << '\n';
return;
}
cout << "Shou" << '\n';
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int tt = 1;
cin >> tt;
for (int _ = 1; _ <= tt; _++) {
solve();
}
return 0;
}
I
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
void solve() {
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
a[i]--;
}
i64 cnt0 = 0, cnt1 = 0, cnt2 = 0, ans = 0;
for (int i = 0; i < n; i++) {
if (a[i] > 0) {
cnt1++;
}
if (a[i] < 0) {
cnt2++;
}
}
ans += cnt1 * cnt2;
for (int i = 0; i < n; i++) {
if (a[i] == 0) {
cnt0++;
ans += n - cnt0;
}
}
cout << ans << '\n';
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int tt = 1;
cin >> tt;
for (int _ = 1; _ <= tt; _++) {
solve();
}
return 0;
}
L
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
void solve() {
int n;
string s;
cin >> n >> s;
vector<int> cnt(n + 1);
for (int i = 1; i <= n; i++) {
if (s[i - 1] == '1') {
if (i + (i & -i) <= n) {
cnt[i + (i & -i)]++;
}
}
}
i64 ans = 0;
for (int i = 1; i <= n; i++) {
if (s[i - 1] == '0' && cnt[i] == 1) {
ans++;
} else if (s[i - 1] == '1' && cnt[i] == 0) {
ans++;
}
}
cout << ans << '\n';
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int tt = 1;
cin >> tt;
for (int _ = 1; _ <= tt; _++) {
solve();
}
return 0;
}
标签:code,int,cin,long,++,num,using 来源: https://www.cnblogs.com/kiddingma/p/16549321.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。