有没有更优化的方法?(我是卡边之王!)
  • 板块灌水区
  • 楼主一咕咕一
  • 当前回复3
  • 已保存回复3
  • 发布时间2024/9/6 20:38
  • 上次更新2024/10/7 22:04:24
查看原帖
有没有更优化的方法?(我是卡边之王!)
772815
一咕咕一楼主2024/9/6 20:38

卡边测试(#20)

代码:

#include <bits/stdc++.h>
using namespace std;
int a[100007], n, s, w;
inline int read()
{
    int s = 0, f = 1;
    char ch = getchar();
    while (ch < '0' || ch > '9')
    {
        if (ch == '-')
            f = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9')
    {
        s = s * 10 + ch - '0';
        ch = getchar();
    }
    return s * f;
}
inline void write(int x)
{
    if (x < 0)
    {
        putchar('-');
        x = -x;
    }
    if (x > 9)
        write(x / 10);
    putchar(x % 10 + '0');
}
int main()
{
    // freopen(".in", "r", stdin);
    // freopen(".out", "w", stdout);
    s = read();
    w = read();
    for (register int i = 1; i <= s; i++)
    {
        int x;
        x = read();
        register int j = n;
        while (j >= 1 && a[j] < x)
            a[j + 1] = a[j], j--;
        a[j + 1] = x;
        n++;
        write(a[max(1, int(n * w / 100.0))]);
        putchar(' ');
    }
    // system("pause");
    return 0;
}

使用我能力范围内的所有优化了,还是比较卡边(我是卡边之王(伦敦大雾))

2024/9/6 20:38
加载中...