记录详情

Wrong Answer

/in/foo.c: In function 'main':
/in/foo.c:46:13: warning: 'v' may be used uninitialized in this function [-Wmaybe-uninitialized]
     i = n; v--;
            ~^~
# 状态 耗时 内存占用
#1 Wrong Answer 2ms 204.0 KiB

代码

#include <stdio.h>
#include <stdlib.h>
#define N 10005
int a[N];

int cmp(const void* a, const void* b)
{
	return *(int*)a - *(int*)b;
}

void Swap(int* a, int* b)
{
	int t;
	t = *a;
	*a = *b;
	*b = t;
}

int Min(int a, int b)
{
	return a < b ? a : b;
}

int main(void)
{
	int n, m;
	scanf("%d", &n);
	scanf("%d", &m);
	int i, j, k;
	int v;
	for (i = 1; i <= n; i++)
		scanf("%d", &a[i]);
	for (i = n - 1; i >= 1; i--)
	{
		if (a[i] < a[i + 1])
		{
			v = i; break;
		}
	}
	for (k = 0; k < m; k++)
	{
		for (i = n; i >= 1; i--)
		{
			if (i == v)
			{
				i = n; v--;
			}
			for (j = i - 1; j >= v; j--)
				if (a[j] < a[i])
				{
					Swap(&a[i], &a[j]);
					qsort(a + j + 1, n - j, sizeof(int), cmp);
					v = Min(j - 1, v);
					i = j = 0;
					/*for (int q = 1; q <= n; q++)
						printf("%d ", a[q]);
					printf("\n");*/
				}
		}
	}
	for (i = 1; i <= n; i++)
		printf("%d ", a[i]);
}

信息

递交者
类型
自测
题目
P1005 hitwh 2019 新生赛 F Ramen and his faculty
语言
C
递交时间
2020-12-26 11:48:20
评测时间
2020-12-26 11:48:20
评测机
分数
0
总耗时
2ms
峰值内存
204.0 KiB