1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | #include <cstdio> using namespace std; int n; int a[100]; int main() { scanf("%d", &n); for (int i = 1; i <= n; ++i) scanf("%d", &a[i]); int ans = 1; for (int i = 1; i <= n; ++i) { if (i > 1 && a[i] < a[i - 1]) ans = i; while (ans < n && a[i] >= a[ans + 1]) ++ans; printf("%d\n", ans); } return 0; } |
0 of 6 Questions completed
Questions:
You have already completed the quiz before. Hence you can not start it again.
Quiz is loading…
You must sign in or sign up to start the quiz.
You must first complete the following:
0 of 6 Questions answered correctly
Your time:
Time has elapsed
You have reached 0 of 0 point(s), (0)
Earned Point(s): 0 of 0, (0)
0 Essay(s) Pending (Possible Point(s): 0)
1、第 16 行输出 ans,ans的值一定大于 i
2、程序输出的 ans小于等于 n。
3、若将第 12 行的 <
改为 !=
,程序输出的结果不会改变。
4、当程序执行到第 16 行时,若 ans−i>2,则 a[i+1]≤a[i]。
5、若输入的 a 数组是一个严格单调递增的数列, 此程序的时间复杂度?
6、最坏情况下,此程序的时间复杂度是?