首页 文章 错题001

错题001

2022-05-09 09:04  浏览数:455  来源:Coat    

#define cinios (ios::sync_with_stdio(false),cin.tie(0),cout.tie(0))
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include<string>
#include<algorithm>
using namespace std;
long long h[100010], s[100010];
int main()
{
int t;
cin >> t;
for (int e = 0; e < t; e++)
{
long long n, sum1, sum2 = 0;
scanf("%lld%lld", &n, &sum1);
for (int i = 0; i < n; i++)
{
scanf("%lld", &h[i]);
s[i] = 0;
sum2 += h[i];
}
int num = sum1 - sum2;
int awa = 0;
for (int i = 0; i < n / 2; i++)
{
if (num >= n - 2 * i - 1 && num!=0)
{
s[i] = 1;
num -= n - 2 * i - 1;
}
if (num < n - 2 * i - 1)
continue;
}
if (num == 1)
awa = 1;
for (int i = 0; i <= n / 2 + 1; i++)
{
num = 0;
if (s[i] == 1)
for (int j = 0; j < n; j++)
{
if (h[j] == i + 1)
for (int w = 0; w < n; w++)
if (h[w] == n - i)
{
swap(h[j], h[w]);
num = 1;
break;
}
if (num == 1)
break;
}
}
num = 0;
if (awa == 1)
{
int flag = n;
for (int j = 0; j < n; j++)
{
if (h[j] == flag / 2 && s[flag / 2 - 1] != 1)
{
for (int w = 0; w < n; w++)
if (h[w] == flag / 2 + 1)
{
swap(h[j], h[w]);
num = 1;
break;
}
}
if (s[flag / 2 - 1] == 1)
flag -= 2;
if (num == 1)
break;
}
}
for (int i = 0; i < n; i++)
printf("%lld ", h[i]);
cout << endl;
}
return 0;
}



声明:以上文章均为用户自行添加,仅供打字交流使用,不代表本站观点,本站不承担任何法律责任,特此声明!如果有侵犯到您的权利,请及时联系我们删除。

字符:    改为:
去打字就可以设置个性皮肤啦!(O ^ ~ ^ O)