main
黄海 1 year ago
parent bb3486a1c8
commit e9c16803c7

@ -0,0 +1,19 @@
5
1 2 3 3 2
5
2 3 2 3 1
5
2 3 4 5 2
5
3 2 4 2 5
7
3 2 4 2 5 3 1
5
3 2 3 2 5
0

@ -1,35 +1,32 @@
#include <bits/stdc++.h> #include <bits/stdc++.h>
using namespace std; using namespace std;
typedef pair<int, int> PII;
const int N = 110; const int N = 110;
int a[N]; int a[N];
int st[10]; int st[10];
struct Node { vector<PII> q;
int st, ed;
};
vector<Node> q;
int res; int res;
/* int n;
5
1 2 3 3 2
5
3 2 4 2 3
7
3 2 4 2 5 3 1
*/
int main() { int main() {
int n; #ifndef ONLINE_JUDGE
cin >> n; freopen("6.in", "r", stdin);
for (int i = 1; i <= n; i++) cin >> a[i]; // 密码数组 #endif
while (cin >> n && n) {
// 各种清空
memset(a, 0, sizeof a);
memset(st, 0, sizeof st);
q.clear();
res = 0;
for (int i = 1; i <= n; i++) { for (int i = 1; i <= n; i++) cin >> a[i]; // 密码数组
if (!st[a[i]]) { for (int i = 1; i <= n; i++) { // 遍历每个位置
st[a[i]] = 1; if (!st[a[i]]) { // 如果此数字没有被处理过
for (int j = n; j; j--) st[a[i]] = 1; // 标识已处理
for (int j = n; j; j--) // 从后向前找到它的终止位置
if (a[i] == a[j]) { if (a[i] == a[j]) {
q.push_back({i, j}); q.push_back({i, j}); // 记录有效区间
break; break;
} }
} }
@ -39,16 +36,12 @@ int main() {
// Q:求一组区间的相交区间个数?如果存在一个相交区间就多加1个1 // Q:求一组区间的相交区间个数?如果存在一个相交区间就多加1个1
res = q.size(); res = q.size();
for (int i = 0; i < q.size(); i++) cout << q[i].st << " " << q[i].ed << endl; // 如果存在区间相交则res++
for (int i = 0; i < q.size(); i++) for (int i = 0; i < q.size(); i++)
for (int j = i + 1; j < q.size(); j++) { for (int j = i + 1; j < q.size(); j++)
if (q[i].ed > q[j].st && q[j].ed > q[i].ed) { if (q[i].second > q[j].first && q[j].second > q[i].second) res++;
res++;
}
}
cout << res << endl; cout << res << endl;
}
return 0; return 0;
} }
Loading…
Cancel
Save