解题代码
#include<cstdio>
#include<map>
#include<cmath>
#include<functional>
using namespace std;
map<int, int,greater<int> > m;
int n, temp;
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &temp);
m[abs(temp - i)]++;
}
for (auto it : m)
if (it.second > 1) printf("%d %d\n", it.first, it.second);
return 0;
}
测试结果
问题整理
1.基础题目。
2.map的排序函数greater()的头文件是functional。