题解:AT_arc220_a [ARC220A] Sum of Reciprocals of Squares
只会写 A,还是太菜了。
首先,我们注意力惊人的发现
注意到我们这样构造会使序列长度增加
显然
随后我们再次注意力惊人的发现
因为
至于构造方式,我们用优先队列存一下所有数,每次取出最小的数,将他删掉并往优先队列里加入四个这个数乘二的值。
似乎没有什么值得特别注意的地方。
:::success[AC code]
#include<bits/stdc++.h>
using namespace std;
int t,n;
priority_queue<int,vector<int>,greater<int> >q;
inline void work()noexcept
{
cin>>n;
if(n%3==0)
{
if(n<6)
{
puts("No");
return;
}
q.push(2),q.push(2),q.push(2),q.push(3),q.push(3),q.push(6);
puts("Yes");
while(q.size()<n)
{
int x=q.top();
q.pop();
for(int i=1;i<=4;i++)q.push(x<<1);
}
while(!q.empty())
{
cout<<q.top()<<' ';
q.pop();
}
cout<<endl;
return;
}
if(n%3==1)
{
puts("Yes"),q.push(1);
while(q.size()<n)
{
int x=q.top();
q.pop();
for(int i=1;i<=4;i++)q.push(x<<1);
}
while(!q.empty())
{
cout<<q.top()<<' ';
q.pop();
}
cout<<endl;
return;
}
if(n%3==2)
{
if(n<8)
{
puts("No");
return;
}
puts("Yes");
q.push(2),q.push(2),q.push(3),q.push(3),
q.push(3),q.push(3),q.push(6),q.push(6);
while(q.size()<n)
{
int x=q.top();
q.pop();
for(int i=1;i<=4;i++)q.push(x<<1);
}
while(!q.empty())
{
cout<<q.top()<<' ';
q.pop();
}
cout<<endl;
return;
}
}
signed main()
{
cin>>t;
while(t--)work();
return 0;
}
:::