uva12100解题报告
2017-05-22 11:01
387 查看
水题留念
一个队列模拟进出操作,一个优先队列保存优先级,模拟过程输出结果
Time 0ms
一个队列模拟进出操作,一个优先队列保存优先级,模拟过程输出结果
Time 0ms
#include<cstdio> #include<queue> #include<cstring> #include<sstream> using namespace std; const int maxn=100+10; typedef pair<int,int> P; struct cmp { bool operator () (const P &p1,const P &p2)const{ return p1.first<p2.first; } }; int main() { int T; scanf("%d",&T); while(T--) { int n,m; queue<P> q1; priority_queue<P,vector<P>,cmp > q2; int ver[15]; memset(ver,0,sizeof(ver)); scanf("%d %d",&n,&m); for(int i=0;i<n;i++) { int x; scanf("%d",&x); ver[x]++; P p=make_pair(x,i); q1.push(p); } for(int i=1;i<=9;i++) if(ver[i]>0) { P p=make_pair(i,ver[i]); q2.push(p); } int ans=0; while(1) { P p=q1.front(); q1.pop(); if(p.first!=q2.top().first) q1.push(p); else{ if(p.second==m) { ans++; break; } else { ans++; P p1=q2.top(); q2.pop(); if(p1.second>1){ p1.second--; q2.push(p1); } } } } printf("%d\n",ans); } return 0; }
相关文章推荐
- UVa 12100 printer queue 解题报告
- UVALive 5791 Candy's Candy 解题报告
- 一中OJ #1457 越大越聪明[Uva 10131 -> Is Bigger Smarter?] | 动态规划 字典序LIS | 解题报告
- UVA 196 Spreadsheet 解题报告
- UVA 10494 If We Were a Child Again 解题报告
- UVA 10098 Generating Fast 解题报告
- acm-uva11352解题报告
- UVA 10010 解题报告
- UVa 11134 Fabled Rooks 解题报告(贪心)
- Uva 11609 - Teams 解题报告(组合数学)
- Uva 1315 - Crazy tea party 解题报告(找规律)
- UVA10456 解题报告
- Uva 1073 - Glenbow Museum 解题报告(组合)
- UVA 11090 SPFA+二分答案 解题报告
- 一中OJ #1434 序列的LCS [UVa 10635 -> Prince and Princess] | 动态规划 LCS映射转换LIS | 解题报告
- UVAlive 6160 Countdown 解题报告
- UVALive 5790 Ball Stacking 解题报告
- 【解题报告】uva116_Unidirectional TSP(单向TSP, dp)
- UVA11090 Going in Cycle!! 解题报告【判负环】【SPFA】【二分答案】
- UVa 10878 - Decode the tape 解题报告