abc371
A.#
模拟。
#include<bits/stdc++.h>
using namespace std;
const int N = 1e6 + 7;
int main() {
string a, b, c;
cin >> a >> b >> c;
if(a == "<") {
if(c == "<") cout << "B" << endl;
else {
if(b == "<") cout << "C" << endl;
else cout << "A" << endl;
}
}
else {
if(b == "<") cout << "A" << endl;
else {
if(c == "<") cout << "C" << endl;
else cout << "B" << endl;
}
}
return 0;
}
B.#
模拟。
#include<bits/stdc++.h>
using namespace std;
const int N = 1e6 + 7;
int vis[N];
int main() {
int n, m;
cin >> n >> m;
for(int i = 1; i <= m; i ++) {
int a;
string b;
cin >> a >> b;
if(b == "F") {
cout << "No" << endl;
}
else {
if(!vis[a]) {
cout << "Yes" << endl;
vis[a] = 1;
}
else cout << "No" << endl;
}
}
return 0;
}
C.#
题意为,给两个无向图
注意到
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N = 200;
vector<int> g1[N], g2[N];
int a[N][N];
int p1[N][N], p2[N][N];
int pp[N];
signed main() {
int n, m1, m2;
cin >> n >> m1;
for(int i = 1; i <= m1; i ++) {
int x, y;
cin >> x >> y;
p1[x][y] = 1;
p1[y][x] = 1;
}
cin >> m2;
for(int i = 1; i <= m2; i ++) {
int x, y;
cin >> x >> y;
p2[x][y] = 1;
p2[y][x] = 1;
}
for(int i = 1; i <= n; i ++) {
for(int j = i + 1; j <= n; j ++) {
cin >> a[i][j];
}
}
int cnt = 0x3f3f3f3f;
for(int i = 1; i <= n; i ++) pp[i] = i;
do{
int ans = 0;
for(int i = 1; i <= n; i ++) {
for(int j = i + 1; j <= n; j ++) {
if((p1[pp[i]][pp[j]] && p2[i][j]) || (!p1[pp[i]][pp[j]] && !p2[i][j])) continue;
ans += a[i][j];
}
}
cnt = min(cnt, ans);
}while(next_permutation(pp + 1, pp + n + 1));
cout << cnt << endl;
return 0;
}
D.#
有
#include<bits/stdc++.h>
#define int long long
using namespace std;
struct Village {
int x;
int p;
};
bool compare(const Village &a, const Village &b) {
return a.x < b.x;
}
signed main() {
int n;
cin >> n;
vector<Village> villages(n);
for (int i = 0; i < n; ++i) {
cin >> villages[i].x;
}
for (int i = 0; i < n; ++i) {
cin >> villages[i].p;
}
sort(villages.begin(), villages.end(), compare);
vector<long long> prefix(n + 1, 0);
for (int i = 1; i <= n; ++i) {
prefix[i] = prefix[i - 1] + villages[i - 1].p;
}
int q;
cin >> q;
for (int i = 0; i < q; ++i) {
int L, R;
cin >> L >> R;
int ll = lower_bound(villages.begin(), villages.end(), Village{L, 0}, compare) - villages.begin();
int rr = upper_bound(villages.begin(), villages.end(), Village{R, 0}, compare) - villages.begin() - 1;
if (left <= right) {
cout << prefix[rr + 1] - prefix[ll] << endl;
} else {
cout << 0 << endl;
}
}
return 0;
}
E.#
求
发现加入一个
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1e6 + 7;
int lst[N], ans, a[N], now;
signed main() {
int n;
cin >> n;
for(int i = 1; i <= n; i ++) cin >> a[i];
for(int i = 1; i <= n; i ++) {
now += (i - lst[a[i]]);
ans += now;
lst[a[i]] = i;
}
cout << ans << endl;
}
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· 清华大学推出第四讲使用 DeepSeek + DeepResearch 让科研像聊天一样简单!
· 实操Deepseek接入个人知识库
· CSnakes vs Python.NET:高效嵌入与灵活互通的跨语言方案对比
· Plotly.NET 一个为 .NET 打造的强大开源交互式图表库