比赛链接

A

思路:排序后前缀和维护,注意总和为X的情况输出NO即可,若前缀和为X,交换当前位置的金子和后续位置金子即可。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76

//team lots of balloons
//author: CN.TTDragon
#include<bits/stdc++.h>
typedef long long ll;
const ll mod=1e9+7;
const ll maxn=1e5+7;
const double pi=acos(-1);
using namespace std;
int _,n,m;
int a[maxn];
int no;
int sum;
int main()
{
ios::sync_with_stdio(false);
//freopen("in.in","r",stdin);
//freopen("mine.out","w",stdout);
for(cin>>_;_;_--)
{
no=sum=0;
cin>>n>>m;
for(int i=1;i<=n;i++)
{
cin>>a[i];
}
sort(a+1,a+n+1);
for(int i=1;i<=n;i++)
{
sum+=a[i];
if(sum!=m)
{
continue;
}
else
{
no=i;
}
}
if((no==1 && n==1)||sum==m)
{
cout<<"NO"<<endl;
}
else
{
cout<<"YES"<<endl;
if(no==0)
{
for(int i=1;i<=n;i++)
{
cout<<a[i]<<" ";

}
cout<<endl;
}
else if (no==n)
{
for(int i=1;i<=n-2;i++)
{
cout<<a[i]<<" ";
}
cout<<a[n]<<" "<<a[n-1]<<endl;
}
else
{
for(int i=1;i<=n;i++)
{
if(i!=no)
cout<<a[i]<<" ";
}
cout<<a[no]<<endl;
}
}
}
return 0;
}

B

思路:n必然为偶数,同时这个数需要时是平方数或者是平方数的两倍(这个是斜边的根号二带来的)。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44

//team lots of balloons
//author: CN.TTDragon
#include<bits/stdc++.h>
typedef long long ll;
const ll mod=1e9+7;
const ll maxn=1e5+7;
const double pi=acos(-1);
using namespace std;
int _,n,m;
map<ll,bool> MP;
int main()
{
ios::sync_with_stdio(false);
//freopen("in.in","r",stdin);
//freopen("mine.out","w",stdout);
MP[2]=1;
for(ll i=2;i*i<=mod;i++)
{
MP[i*i]=1;
}
for(cin>>_;_;_--)
{
cin>>n;
if(n%2==0)
{
if(MP[n]||MP[n/2])
{
cout<<"YES"<<endl;
}
else{
cout<<"NO"<<endl;
}
}
else
{
cout<<"NO"<<endl;
}

}
return 0;
}


C

思路:用小根堆来维护最小值,给最小值加上目前高度即可,最后看最大和最小Tower的高度差是否满足题意。这里写了个稀碎的重载

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92

//team lots of balloons
//author: CN.TTDragon
#include<bits/stdc++.h>
typedef long long ll;
const ll mod=1e9+7;
const ll maxn=1e5+7;
const double pi=acos(-1);
using namespace std;
int _,n,m,k;
struct node{
int num;//塔编号
int val;//值
bool operator < (node b) const
{
return b.val<val;
}
};
priority_queue<node > q;
node node1;
int a[maxn];
int ans[maxn];
int mx,mi;
queue<int >que[10005];
int main()
{
ios::sync_with_stdio(false);
//freopen("in.in","r",stdin);
//freopen("mine.out","w",stdout);
for(cin>>_;_;_--)
{
mx=0;
mi=mod;
for(int i=1;i<=10000;i++)
{
while(!que[i].empty())
{
que[i].pop();
}
}
while(!q.empty())
{
q.pop();
}
cin>>n>>m>>k;
for(int i=1;i<=n;i++)
{
cin>>a[i];
que[a[i]].push(i);
}
sort(a+1,a+n+1);
for(int i=1;i<=m;i++)
{
node1.num=i;
node1.val=a[i];
ans[que[a[i]].front()]=i;
que[a[i]].pop();
q.push(node1);
}
for(int i=m+1;i<=n;i++)
{
node1=q.top();
q.pop();
node1.val+=a[i];
ans[que[a[i]].front()]=node1.num;
que[a[i]].pop();
q.push(node1);
}
while(!q.empty())
{
node1=q.top();
mi=min(mi,node1.val);
mx=max(mx,node1.val);
q.pop();
}
if(mx-mi<=k)
{
cout<<"YES"<<endl;
for(int i=1;i<=n;i++)
{
cout<<ans[i]<<" ";
}
cout<<endl;
}
else
{
cout<<"NO"<<endl;
}
}
return 0;
}