CF 358C C. Dima and Containers 离线+模拟
2018-02-25 14:22
627 查看
题意: 有3种数据结果,Queue,Stack,Deck(两端插入) 和 Q次操作
操作1:把数字x压入3种数据结构中的其中一种.
操作2: 遇到输入x==0 将弹出3个数据结构中的非受限端 (Queue为队头,Stack为栈顶).并且清空该数据结构.(Deck 只能选其中一端) 并且要求每次操作2弹出的数之和要最大.
1<=Q,x<=1e6.
每遇到操作2后 所用数据都清空 所以将两个0之间的数 分开来考虑.
因为Deck只能弹出一个数 所以可以选择其一端放没用的数 .那么显然可以每次遇到操作2都弹出前3大的数.
最大放queue,次大放stack,第三大放Front 剩余的都放Back. 用vector模拟一下即可.
#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;
typedef pair<int,int> ii;
const int N=2e+5;
int mk[5];
vector<ii> v;
string s[4]={"Queue","Stack","Front","Back"};
bool cmp(ii a,ii b)
{
return a.se<b.se;
}
void calc()
{
int ans=0;
vector<int> res(v.size());
sort(v.begin(),v.end());
reverse(v.begin(),v.end());
for(int i=0;i<v.size();i++)
res[v[i].se]=3;
for(int i=0;i<min(3,(int)v.size());i++)
res[v[i].se]=i,ans++;
sort(v.begin(),v.end(),cmp);
for(int i=0;i<v.size();i++)
cout<<"push"<<s[res[i]]<<"\n";
cout<<ans;
for(int i=0;i<ans;i++)
cout<<" pop"<<s[i];
cout<<"\n";
res.clear();
}
int main()
{
ios::sync_with_stdio(false);
//cin.tie(0);
//cout.tie(0);
int Q,x,id=0;
cin>>Q;
for(int i=0;i<Q;i++)
{
cin>>x;
if(x)
v.push_back(ii(x,id++));
else
{
calc();
id=0;
v.clear();
}
}
if(v.size())
for(int i=0;i<v.size();i++)
cout<<"pushQueue"<<"\n";
return 0;
}
操作1:把数字x压入3种数据结构中的其中一种.
操作2: 遇到输入x==0 将弹出3个数据结构中的非受限端 (Queue为队头,Stack为栈顶).并且清空该数据结构.(Deck 只能选其中一端) 并且要求每次操作2弹出的数之和要最大.
1<=Q,x<=1e6.
每遇到操作2后 所用数据都清空 所以将两个0之间的数 分开来考虑.
因为Deck只能弹出一个数 所以可以选择其一端放没用的数 .那么显然可以每次遇到操作2都弹出前3大的数.
最大放queue,次大放stack,第三大放Front 剩余的都放Back. 用vector模拟一下即可.
#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;
typedef pair<int,int> ii;
const int N=2e+5;
int mk[5];
vector<ii> v;
string s[4]={"Queue","Stack","Front","Back"};
bool cmp(ii a,ii b)
{
return a.se<b.se;
}
void calc()
{
int ans=0;
vector<int> res(v.size());
sort(v.begin(),v.end());
reverse(v.begin(),v.end());
for(int i=0;i<v.size();i++)
res[v[i].se]=3;
for(int i=0;i<min(3,(int)v.size());i++)
res[v[i].se]=i,ans++;
sort(v.begin(),v.end(),cmp);
for(int i=0;i<v.size();i++)
cout<<"push"<<s[res[i]]<<"\n";
cout<<ans;
for(int i=0;i<ans;i++)
cout<<" pop"<<s[i];
cout<<"\n";
res.clear();
}
int main()
{
ios::sync_with_stdio(false);
//cin.tie(0);
//cout.tie(0);
int Q,x,id=0;
cin>>Q;
for(int i=0;i<Q;i++)
{
cin>>x;
if(x)
v.push_back(ii(x,id++));
else
{
calc();
id=0;
v.clear();
}
}
if(v.size())
for(int i=0;i<v.size();i++)
cout<<"pushQueue"<<"\n";
return 0;
}
相关文章推荐
- cf C. Dima and Containers
- CF10月25日比赛。(Dima and Text Messages)
- cf D. Dima and Trap Graph
- cf C. Dima and Salad
- CF 390B:Inna, Dima and Song
- CF10月25日比赛。(Dima and Text Messages)
- CF round167 Div1 C Dima and Horses
- cf 167.div2 D.Dima and Two Sequences
- cf-381A-Sereja and Dima
- Codeforces Round #208 (Div. 2) C. Dima and Containers
- CF 272B Dima and Sequence
- cf B. Dima and To-do List
- CF 366E - Dima and Magic Guitar 最远曼哈顿距离
- CF 366E Dima and Magic Guitar(最远哈密顿距离)
- CF 366E - Dima and Magic Guitar 最远曼哈顿距离
- CF10月25日比赛。(Dima and Continuous Line)
- cf D. Dima and Lisa (三素数定理_素数打表+判定)
- CF Dima and To-do List
- cf B. Dima and Text Messages
- CF 273C C. Dima and Horses