A
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include <bits/stdc++.h> #define PI acos(-1.0) #define mem(a,b) memset((a),b,sizeof(a)) #define TS printf("!!! ") #define pb push_back #define inf 0x3f3f3f3f //std::ios::sync_with_stdio(false); using namespace std; //priority_queue<int,vector<int>,greater<int>> que; get min const double eps = 1.0e-10; const double EPS = 1.0e-4; typedef pair<int, int> pairint; typedef long long ll; typedef unsigned long long ull; //const int maxn = 3e5 + 10; const int turn[4][2] = {{0, 1}, { 1, 0}, { 0, -1}, { -1, 0}}; //priority_queue<int, vector<int>, less<int>> que; //next_permutation int num[100005]; int main() { vector<int> ans; int minn=2e9; int n; cin >> n; for(int i=1;i<=n;i++) { scanf("%d",&num[i]); minn=min(minn,num[i]); } for(int i=1;i<=n;i++) { if(num[i]==minn) { ans.push_back(i); } } int anser=1e9; for(int i=0;i<ans.size()-1;i++) { anser=min(anser,ans[i+1]-ans[i]); } cout<<anser<<endl; }
B
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include <bits/stdc++.h> #define PI acos(-1.0) #define mem(a,b) memset((a),b,sizeof(a)) #define TS printf("!!! ") #define pb push_back #define inf 0x3f3f3f3f //std::ios::sync_with_stdio(false); using namespace std; //priority_queue<int,vector<int>,greater<int>> que; get min const double eps = 1.0e-10; const double EPS = 1.0e-4; typedef pair<int, int> pairint; typedef long long ll; typedef unsigned long long ull; //const int maxn = 3e5 + 10; const int turn[4][2] = {{0, 1}, { 1, 0}, { 0, -1}, { -1, 0}}; //priority_queue<int, vector<int>, less<int>> que; //next_permutation int num[100005]; int main() { int n,a,b; cin >> n >> a >> b; for(int i=min(a,b);;i--) { if(a/i+b/i>=n) { cout<<i<<endl; return 0; } } }
C
我们知道当三个里面的最小值都大于三的时候肯定不行 当有一个为1的时候肯定行 当2的个数不小于两个的时候肯定行 三个全为3也肯定行
剩下的就是 244这种情况
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include <bits/stdc++.h> #define PI acos(-1.0) #define mem(a,b) memset((a),b,sizeof(a)) #define TS printf("!!! ") #define pb push_back #define inf 0x3f3f3f3f //std::ios::sync_with_stdio(false); using namespace std; //priority_queue<int,vector<int>,greater<int>> que; get min const double eps = 1.0e-10; const double EPS = 1.0e-4; typedef pair<int, int> pairint; typedef long long ll; typedef unsigned long long ull; //const int maxn = 3e5 + 10; const int turn[4][2] = {{0, 1}, { 1, 0}, { 0, -1}, { -1, 0}}; //priority_queue<int, vector<int>, less<int>> que; //next_permutation int num[1505]; int main() { int a, b, c; cin >> a >> b >> c; num[a]++, num[b]++, num[c]++; if (min(min(a, b), c) == 1) { cout << "YES" << endl; return 0; } if (num[2] == 1 && num[4] == 2) { cout << "YES" << endl; return 0; } if (num[2] >= 2 || num[3] == 3) { cout << "YES" << endl; return 0; } cout << "NO" << endl; }
D
假设一个区间内的逆序对数为N 区间为L-R 则不为逆序对的数翻转之后会变成逆序对 本为逆序对的翻转之后变成正常 而1-L -1 R+1-N的逆序对并不会受到影响
所以最终的答案就是SUM-N+(R-L+1)*(R-L)/2-N=SUM+(R-L+1)*(R-L)/2-2*N 因为2*N肯定是偶数 减去不影响答案的奇偶性 所以只要判断(R-L+1)*(R-L)/2是奇数还是偶数就行
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include <bits/stdc++.h> #define PI acos(-1.0) #define mem(a,b) memset((a),b,sizeof(a)) #define TS printf("!!! ") #define pb push_back #define inf 0x3f3f3f3f //std::ios::sync_with_stdio(false); using namespace std; //priority_queue<int,vector<int>,greater<int>> que; get min const double eps = 1.0e-10; const double EPS = 1.0e-4; typedef pair<int, int> pairint; typedef long long ll; typedef unsigned long long ull; //const int maxn = 3e5 + 10; const int turn[4][2] = {{0, 1}, { 1, 0}, { 0, -1}, { -1, 0}}; //priority_queue<int, vector<int>, less<int>> que; //next_permutation int num[1505]; int c[1505][1505]; int dp[1505][1505]; ll sum = 0; int main() { int n; cin >> n; for (int i = 1; i <= n; i++) { scanf("%d", &num[i]); } for (int i = 1; i <= n; i++) { for (int j = num[i] - 1; j >= 1; j--) { c[i][j]++; } } for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { c[j][i] += c[j - 1][i]; } } for (int i = 1; i <= n; i++) { sum += c[i - 1][num[i]]; } int flag; if(sum%2) flag=1; else flag=0; int q; cin >> q; while (q--) { int l,r; cin >> l >> r; if(((r-l+1)*(r-l)/2)%2) flag^=1; if(flag) cout<<"odd"<<endl; else cout<<"even"<<endl; } }
E
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include <bits/stdc++.h> #define PI acos(-1.0) #define mem(a,b) memset((a),b,sizeof(a)) #define TS printf("!!! ") #define pb push_back #define inf 0x3f3f3f3f //std::ios::sync_with_stdio(false); using namespace std; //priority_queue<int,vector<int>,greater<int>> que; get min const double eps = 1.0e-10; const double EPS = 1.0e-4; typedef pair<int, int> pairint; typedef long long ll; typedef unsigned long long ull; //const int maxn = 3e5 + 10; const int turn[4][2] = {{0, 1}, { 1, 0}, { 0, -1}, { -1, 0}}; //priority_queue<int, vector<int>, less<int>> que; //next_permutation int anser[200005]; int num[200005]; int visit[200005]; stack<int> sta; vector<int> ans; int main() { int cur = 1; int n, m; cin >> n >> m; for (int i = 1; i <= m; i++) { cin >> num[i]; anser[i] = num[i]; visit[num[i]] = 1; sta.push(num[i]); while (sta.size() && cur == sta.top()) { sta.pop(); cur++; } } int now; while (cur <= n || (!sta.empty() && sta.top() > cur)) { if (sta.size()) { now = sta.top(); } else { now = n + 1; } for (int i = now - 1; i >= cur; i--) { if (visit[i]) { cout << -1 << endl; return 0; } else { anser[++m] = i; sta.push(i); visit[i] = 1; } } while (sta.size() && cur == sta.top()) { sta.pop(); cur++; } } if (sta.size()) { cout << -1 << endl; return 0; } for (int i = 1; i <= n; i++) { cout << anser[i] << " "; } cout << endl; }