/ Vijos / 讨论 / 花匠 /

为什么卡了两个点啊。。。

#include<cstdio>
#include<iostream>
using namespace std;
int n,ans;
int a[100005];

int main()
{
    scanf("%d",&n);
    for(int i = 1;i <= n;++i)
    {
        scanf("%d",&a[i]);
    }
    ans = 1;
    int k = 1;
    while(k < n)
    {
        if(a[k + 1] > a[k])
        {
            ans ++;
            while(a[k + 1] > a[k] && k < n)
            {
                ++k;
            }
        }
        else if(a[k + 1] < a[k])
        {
            ans ++;
            while(a[k + 1] < a[k] && k < n)
            {
                ++k;
            }
        }
        else
        {
            ++k;
        }
    }
    if(ans == 1 && a[n] == a[1])
    {
        printf("%d",ans);
        //system("pause");
        return 0;
    }
    else
    {
        printf("%d",ans);
        //system("pause");
        return 0;
    }
}

编译成功

测试数据 #0: Accepted, time = 0 ms, mem = 948 KiB, score = 10
测试数据 #1: Accepted, time = 0 ms, mem = 944 KiB, score = 10
测试数据 #2: Accepted, time = 0 ms, mem = 948 KiB, score = 10
测试数据 #3: Accepted, time = 0 ms, mem = 944 KiB, score = 10
测试数据 #4: Accepted, time = 0 ms, mem = 948 KiB, score = 10
测试数据 #5: Accepted, time = 0 ms, mem = 948 KiB, score = 10
测试数据 #6: WrongAnswer, time = 0 ms, mem = 952 KiB, score = 0
测试数据 #7: WrongAnswer, time = 0 ms, mem = 948 KiB, score = 0
测试数据 #8: Accepted, time = 15 ms, mem = 948 KiB, score = 10
测试数据 #9: Accepted, time = 46 ms, mem = 952 KiB, score = 10
WrongAnswer, time = 61 ms, mem = 952 KiB, score = 80

0 条评论

目前还没有评论...

信息

ID
1845
难度
6
分类
(无)
标签
递交数
4343
已通过
1237
通过率
28%
被复制
9
上传者