forked from oeddyo/algorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.cpp
More file actions
31 lines (30 loc) · 700 Bytes
/
test.cpp
File metadata and controls
31 lines (30 loc) · 700 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
//g++ 4.7.2 提交
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int main()
{
int n;
scanf("%d", &n);
int a[n+1], count[n+1];
memset(count, 0, sizeof(count));
for (int i = 1; i <= n; ++i)
scanf("%d", &a[i]);
for (int i = 1; i <= n; ++i)
{
int t = (i-a[i]+n+1)%n; //for循环里可以直接++count[((i - a[i] + 1) % N + N) % N]
if (t == 0)
t = n;
++count[t];
}
int maxnum = 0, maxindex;
for (int i = 1; i <= n; ++i)
if (count[i] > maxnum)
{
maxnum = count[i];
maxindex = i;
}
printf("%d\n", maxindex);
return 0;
}