您的位置:首页 > 其它

NOIP 2016提高组 Day2 蚯蚓

2018-01-04 21:47 218 查看
直觉 用大根堆堆 用STL的priority_que 实现的; 过了七组数据,还有13组数据未过

#include <bits/stdc++.h>
using namespace std;
const int MM=100000;
int n,m,q,u,v,t;
//那只蚯蚓  m:时间 q:增加的长度   p=u/v
int qiuyin[MM];
vector<int> qiuyin2;

priority_queue<int> que;

int main(){

cin >> n >> m >> q >>u >> v>>t;

for(int i=0;i<n;i++){
cin >> qiuyin[i];
}

for(int i=0;i<n;i++){
que.push( qiuyin[i] );
}

for(int i=1;i<=m;i++){
int large = 0;
if(!que.empty()) {
large = que.top();
que.pop();
if( i>=t && i%t==0) cout << large << " ";

}

qiuyin2.clear();
while(!que.empty()){
qiuyin2.push_back(que.top());
//cout<< "debug :"<<que.top() << " "<<endl;
que.pop();
}

for(int j=0;j<qiuyin2.size();j++){
qiuyin2[j] += q;
que.push(  qiuyin2[j] );
}

//double p= 1.0*u/v;
//cout <<"debug p" << p<<endl;
int new1= int( 1.0*large*u/v);
int new2= large- new1;
//cout<<"debug: new1 new2"<< new1 <<"  "<< new2<<"  "<<endl;
que.push(new1);
que.push(new2);

}

cout << endl;
int ge=0;
while(!que.empty()){
int temp=que.top(); que.pop();
ge++;
if( ge>=t && ge%t==0) cout << temp << " ";
}

return 0;
}

收到网上“”记录时间戳“的思路的启发”,将所有的蚯蚓长度都折算到0时刻的长度(可能有负值)

通过了了16组数据,还有4组数据未通过。

#include <bits/stdc++.h>
using namespace std;
const int MM=100000;
int n,m,q,u,v,t;
//那只蚯蚓 m:时间 q:增加的长度 p=u/v
int qiuyin[MM];

priority_queue<int> que; //记录0时刻的蚯蚓的长度

int main(){

cin >> n >> m >> q >>u >> v>>t;

for(int i=0;i<n;i++){
cin >> qiuyin[i];
}

for(int i=0;i<n;i++){
que.push( qiuyin[i] );
}

for(int i=1;i<=m;i++){

int large = que.top() + (i-1)*q;
que.pop();
if( i>=t && i%t==0) cout << large << " ";

int new1= int( 1.0*large*u/v);
int new2= large- new1;
// cout<<"debug: new1 new2"<< new1 <<" "<< new2<<" "<<endl;
que.push(new1 - i*q);
que.push(new2 - i*q);

}

cout << endl;
int ge=0;
while(!que.empty()){
int ans=que.top() + m * q;
que.pop();
ge++;
if( ge>=t && ge%t==0 && ans>=0 ) cout << ans<< " ";
}

return 0;
}

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: