MC0201
a + b a+b a+b
code:
cpp
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
void solve(){
int a,b; cin >> a >> b;
cout << a + b << endl;
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr),cout.tie(nullptr);
int _ = 1;
while(_ --){
solve();
}
return 0;
}
MC0202
暴力枚举
code:
cpp
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
void solve(){
int l,r; char x; cin >> l >> x >> r;
int sum = 0;
for(int i = l;i <= r;i ++){
if(i % 2 || i % 3) continue;
sum += i;
}
cout << sum << endl;
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr),cout.tie(nullptr);
int _ = 1;
while(_ --){
solve();
}
return 0;
}
MC0203
map更新分数和最后一次操作的位置即可
然后找最小分数 如果最小分数相同就看更新的位置
code:
cpp
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
int n;
void solve(){
cin >> n;
map<string,pair<int,int>> mp;
for(int i = 0;i < n;i ++){
string s; cin >> s;
int x; cin >> x;
mp[s] = {x + mp[s].first,i};
}
int mn = 1e18,pos = 1e18;
string ans;
for(auto x : mp){
if(x.second.first < mn) mn = x.second.first,ans = x.first,pos = x.second.second;
else if(x.second.first == mn && x.second.second < pos) mn = x.second.first,ans = x.first,pos = x.second.second;
}
cout << ans << endl;
cout << mn + 1000 << endl;
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr),cout.tie(nullptr);
int _ = 1;
while(_ --){
solve();
}
return 0;
}
MC0204
求最长连续不重复子序列长度
双指针即可
code:
cpp
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
const int N = 1e6 + 7;
int n;
int c[N];
void solve(){
cin >> n;
for(int i = 0;i < n;i ++) cin >> c[i];
map<int,int> mp;
int mx = 1;
for(int i = 0,j = 0;i < n;i ++){
mp[c[i]] ++;
while(j < i && mp[c[i]] > 1) mp[c[j ++]] --;
mx = max(i - j + 1,mx);
}
cout << mx << endl;
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr),cout.tie(nullptr);
int _ = 1;
while(_ --){
solve();
}
return 0;
}
MC0205
找最大字符
code:
cpp
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
void solve(){
string s; cin >> s;
char ans = *max_element(s.begin(),s.end());
cout << ans << endl;
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr),cout.tie(nullptr);
int _ = 1;
while(_ --){
solve();
}
return 0;
}
MC0206
只会有两种情况:
ABABAB...
BABABA...
看两种情况最低处理操作即可
code:
cpp
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
void solve(){
string s; cin >> s;
int n = s.size();
int ans1 = 0,ans2 = 0;
for(int i = 0;i < n;i ++){
if(i % 2){
if(s[i] == 'A') ans1 ++;
else ans2 ++;
} else{
if(s[i] == 'B') ans1 ++;
else ans2 ++;
}
}
cout << min(ans1,ans2) << endl;
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr),cout.tie(nullptr);
int _ = 1; cin >> _;
while(_ --){
solve();
}
return 0;
}
MC0207
单向建图 dfs从1开始跑一遍看是否能到n即可
code:
cpp
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
const int N = 2e5 + 7;
vector<int> g[N];
int n,m;
int flag;
int st[N];
void dfs(int u){
if(flag || u == n){
flag = 1;
return;
}
st[u] = 1;
for(auto t : g[u]){
if(st[t]) continue;
dfs(t);
}
}
void solve(){
cin >> n >> m;
for(int i = 0;i < m;i ++){
int u,v; cin >> u >> v;
g[u].push_back(v);
}
dfs(1);
if(flag) cout << "Yes" << endl;
else cout << "No" << endl;
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr),cout.tie(nullptr);
int _ = 1;
while(_ --){
solve();
}
return 0;
}
MC0208
看是否是10的倍数 不是就*2
code:
cpp
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
int n;
void solve(){
cin >> n;
if(n % 10) cout << 2 * n << endl;
else cout << 0 << endl;
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr),cout.tie(nullptr);
int _ = 1;
while(_ --){
solve();
}
return 0;
}
MC0209
分长度奇偶即可
code:
cpp
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
int n;
void solve(){
string s; cin >> s;
n = s.size();
if(n & 1) cout << "123456" << endl;
else{
reverse(s.begin() + n / 2,s.end());
cout << s << endl;
}
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr),cout.tie(nullptr);
int _ = 1;
while(_ --){
solve();
}
return 0;
}
MC0210
暴力判断即可
code:
cpp
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
int n;
void solve(){
string s; cin >> s;
n = s.size();
for(int i = n / 3;i >= 1;i --){
string s1 = s.substr(0,i);
string s2 = s.substr(n - i,i);
if(s1 == s2){
string s3 = s.substr(i,n - 2 * i);
if(s3.find(s1) != s3.npos){
cout << s1 << endl;
return;
}
}
}
cout << "No" << endl;
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr),cout.tie(nullptr);
int _ = 1;
while(_ --){
solve();
}
return 0;
}
MC0211
模拟
code:
cpp
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
void solve(){
string s; cin >> s;
int pos = s.size() - 1;
for(int i = pos;i >= 0;i --){
if(s[i] != '0'){
pos = i;
break;
}
}
if(s.size() == 1) cout << s << endl;
else{
cout << s[0];
if(pos != 0) cout << ".";
for(int i = 1;i <= pos;i ++) cout << s[i];
cout << "E" << s.size() - 1 << endl;
}
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr),cout.tie(nullptr);
int _ = 1;
while(_ --){
solve();
}
return 0;
}
MC0212
code:
cpp
MC0213
按相同边长分类讨论
code:
cpp
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
void solve(){
map<int,int> mp;
for(int i = 0;i < 5;i ++){
int x; cin >> x;
mp[x] ++;
}
if(mp.size() == 1) cout << "Square" << endl;
else if(mp.size() == 2){
if(mp.begin()->second == 4 || mp.begin()->second == 1) cout << "Square" << endl;
else cout << "Rectangle" << endl;
} else if(mp.size() == 3){
int cnt = 0;
for(auto x : mp) if(x.second == 2) cnt ++;
if(cnt == 2) cout << "Rectangle" << endl;
else cout << "No" << endl;
}
else cout << "No" << endl;
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr),cout.tie(nullptr);
int _ = 1;
while(_ --){
solve();
}
return 0;
}