Title Description
Beef has n friend, numbered 0 to n-1, each with up to a friend who does not like, referred to as A [i], like if each individual person i, a [i] = i now need beef We invite everyone to a party, but he found a different order would invite lead to different results, because once someone discovered that he does not like people who have been invited he would not come to the party, I ask how many people you can invite up to to the party
Enter a description:
A first line of input integer n (1≤n≤50)
a second line of the input n integers 0≤ai≤n-1
Example 1
Input
2
0. 1
Output
2
Example 2
Input
2
1 0
Output
1
Example 3
Input
. 4
. 1. 3 0 2
Output
2
Example 4
Input
. 6
5 2 2 5. 4 0
Output
5
(Greedy - a star)
Python
n=int(input())
l=[int(x) for x in input().split()]
count=len(l)
for i in range(n):
if l[i]<i:
count-=1
print(count)
C
#include<stdio.h>
int main()
{
int a[1000];
int n,count;
scanf("%d", &n);
count = n;
for(int i=0;i<n;i++)
{
scanf("%d", &a[i]);
}
for (int j = 0; j < n; j++)
{
if (a[j] < j) count -= 1;
}
printf("%d\n", count);
return 0;
}