讨论 / STL优先队列秒杀法
frank6696 2014-02-19 22:39:54
点我顶贴 收藏 删除

测试点1 Accepted / 15ms / 3264kB

测试点2 Accepted / 12ms / 3264kB

测试点3 Accepted / 12ms / 3264kB

测试点4 Accepted / 13ms / 3264kB

测试点5 Accepted / 16ms / 3264kB

#include<iostream>

#include<algorithm>

#include<cmath>

#include<queue>

using namespace std;

priority_queue<int,vector<int>,greater<int> > q;

int prime(int m)

{

if(m==2||m==3) return 1;

else if(m<2||m%2==0) return 0;

int k=sqrt(m);

int ok=1;

for(int i=3;i<=k;i+=2)

{

if(m%i==0) {ok=0;return 0;}

}

if(ok) return 1;

}

int main()

{

int n,x,t;

cin>>n;

for(;n--;q.push(x))

{

cin>>x;

}

t=q.top();

for(x=0;!q.empty();q.push(n))

{

n=q.top();

q.pop();

if(q.empty()) break;

n+=q.top();

q.pop();

x+=n;

}

cout<<x+t<<endl;

if(prime(x+t)) cout<<"Yes";

else cout<<"No";

return 0;

}

查看更多回复
提交回复