Home Article Practice 错题001

错题001

2022-05-09 09:04  views:520  source: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;
}



Disclaimer: The above articles are added by users themselves and are only for typing and communication purposes. They do not represent the views of this website, and this website does not assume any legal responsibility. This statement is hereby made! If there is any infringement of your rights, please contact us promptly to delete it.

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