由于我喜欢做一道发一道,所以是“部分”题解
传送门
【CSP-J模拟赛七】--B光荣的梦想
每次交换可消除一个“逆序对”(后面的数小于前面的数称为“逆序对”),直接暴力求解逆序对数量即可
#include<bits/stdc++.h>
using namespace std;
int main() {
int n;
cin>>n;
vector<int>a(n);
for (auto &x:a)cin>>x;
int s=0;
for (int i=0;i<n-1;i++) {
for (int j=i+1;j<n;j++) {
if (a[j]<a[i])s++;
}
}
cout<<s;
return 0;
}
【CSP-J模拟赛七】--D化简运算
栈
#include <iostream>
#include <stack>
using namespace std;
int main() {
string s; cin >> s;
stack<pair<int, int>> st;
int m = 0, c = 0;
for (char x : s) {
if (x == 'a') c++;
else if (x == '(') {
st.push({m, c});
m = c = 0;
} else if (x == ')') {
int t = max(m, c);
auto [pm, pc] = st.top(); st.pop();
m = pm;
c = pc + t;
} else if (x == '|') {
m = max(m, c);
c = 0;
}
}
cout << max(m, c);
}
【CSP-J模拟赛七】--E牛的阵容
【CSP-J模拟赛七】--F验算
【CSP-J模拟赛七】--C逻辑运算
懒得做了,骗80也挺不错
#include <bits/stdc++.h>
using namespace std;
int main() {
string str;
cin>>str;
int len=str.size();
if(len%200==4)cout<<"false";
else cout<<"true";
return len%200;
}
【CSP-J模拟赛七】--A整数幂
这道题应该不用说什么了。。。我用的while循环每次a/=2
#include<bits/stdc++.h>
using namespace std;
int main() {
double a;
cin>>a;
while (a>2) {
a/=2;
}
if (a==2)cout<<"yes";
else cout<<"no";
return 0;
}