#include<queue>
#include<vector>
struct cmp // 最小优先队列
{
bool operator()(const long long i,const long long j)
{
return i>j;
}
};
priority_queue<int,vector<long long>,cmp> Q;
struct node // 最小优先队列
{
int id,len;
bool operator < (const node &b)const // 重载小于号
{
return len>b.len;
}
};
priority_queue<node> Q;
下面以 long long 型队列介绍:
Q.empty() // 判断队列是否为空返回ture表示空返回false表示空 bool
Q.top() // 返回顶端元素的值元素还在队列里 long long
Q.pop() // 删除顶端元素 void
Q.push(V) // 把long long型的数V加入到队列里它会制动条件V的位置void
Q.size() // 返回队列里元素个数 unsigned int
priority_queue<int,vector<int>,greater<int> > que; // 最小优先队列
priority_queue<int> que1; // 最大优先队列
priority_queue<int,vector<int>,less<int> > que1; // 最大优先队列
是其它类型的如long long 用优先队列需要从载cmp 类
struct cmp // 整形最小优先队列
{
bool operator()(const int i,const int j)
{
return i>j;
}
};
priority_queue<int,vector<int>,cmp>que;
struct cmp // long long 型最小优先队列
{
bool operator()(const long long i,const long long j)
{
return i>j;
}
};
priority_queue<int,vector<long long>,cmp> Q;
struct cmp // string表示整数最小最优队列的重载
{
bool operator()(const string &i,const string &j)
{
int len1=i.length(),len2=j.length();
if(len1==len2)return i.compare(j)>0;
return len1>len2;
}
};
priority_queue<int,vector<string>,cmp> Q;
bool cmpe(string i,string j) // 从大数到小数的排序重载
{
int len1=i.length(),len2=j.length();
if(len1==len2)return i.compare(j)>0;
return len1 > len2;
}
sort(a+1,a+10+1,cmpe);
// ustc1122 求最大的10 个数
#include<iostream>
#include<stdio.h>
#include<string>
#include<string.h>
#include<queue>
using namespace std;
struct cmp // string最小最优队列的重载
{
bool operator()(const string &i,const string &j)
{
int len1=i.length(),len2=j.length();
if(len1==len2)return i.compare(j)>0;
return len1>len2;
}
};
void change(char * s,int &len) // 处理前导零同时发回整数的长度
{
int j,k;
len=strlen(s);
for( j=0; j<len; j++)if(s[j]!='0')break;
if(j==len)
{
s[1]='\0';
len=1;
}
else if(j)
{
for(k=0; j<len; j++,k++)s[k]=s[j];
s[k]='\0';
len=k;
}
}
string a[11];
int main()
{
int i,j,k,n,len2,len;
string t,stringtop;
char cs[30];
while(cin>>n)
{
priority_queue<int,vector<string>,cmp> Q;
for(i=1; i<=10; i++)
{
scanf("%s",cs);
change(cs,len);
Q.push(t.assign(cs));
}
stringtop=Q.top();
len2=stringtop.length();
for(i=11; i<=n; i++)
{
scanf("%s",cs);
change(cs,len);
if(len<len2)continue;
t.assign(cs); // 转换成string 类
if(len>len2||len==len2&&t.compare(stringtop)>0)
{
Q.pop();
Q.push(t);
stringtop=Q.top();
len2=stringtop.length();
}
};
i=10;
while(!Q.empty())
{
a[i--]=Q.top();
Q.pop();
}
for(i=1; i<=10; i++) cout<<a[i]<<endl;
}
}
/*Sample Input
11
1 00 0 4 5 6 007 015 9 8 10
Sample Output
15 10 9 8 7 6 5 4 3 2
*/
/*
* File: nuaa1081 合并最小花费.cpp
* Author: GOUXIANG
*
* Created on 2009年9月21日, 下午9:36
*/
#include <stdlib.h>
#include<stdio.h>
#include<queue>
#include<vector>
#include<algorithm>
using namespace std;
/*
*
*/
struct cmp
{
bool operator()(const long long i,const long long j)
{
return i>j;
}
};
int main(int argc, char** argv)
{
int n,temp;
long long t,t2;
while(scanf("%d",&n)!=EOF)
{
int i;
priority_queue<int,vector<long long>,cmp> Q;
for(i=1; i<=n; i++)
{
scanf("%d",&temp);
Q.push((long long)temp);
}
long long sum=0;
while(Q.size()>1)
{
t=Q.top();
Q.pop();
t2=Q.top();
Q.pop();
t+=t2;
sum+=t;
Q.push(t);
}
printf("%I64d\n",sum);
}
return (EXIT_SUCCESS);
}
/*Sample Input
4
4 1 2 3
Sample Output
19
Hint
第一次拿1和2 堆成一堆,耗费体力3, 然后拿3+3=6,最后6+4=10;则消耗体力为3+6+10=19。
注:结果范围不超出longint.
*/
//zju3230 Solving the Problems
/*
Aaron的编程能力为p,他想用m天时间每天做一题来提高自己的编程能
力,对于每道题目,都又做这题的最小能力要求,达到这个能力ai后才能
做,做了这题后编程能力会提升bi(就像砍小怪,砍掉以后会获得经验值,
就能升级^_^)问m天后Aaron的编程能力最多能提升到多少。
*/
#include <stdlib.h>
#include<iostream>
#include<queue>
#include<algorithm>
using namespace std;
/*
*
*/
struct node
{
int a,b;
};
node v[100001];
bool cmp(node x,node y)
{
if(x.a==y.a)return x.b>y.b;
return x.a<y.a;
}
int main(int argc, char** argv)
{
int n,m,p,i,index;
while(scanf("%d%d%d",&n,&m,&p)!=EOF)
{
for(i=1; i<=n; i++)scanf("%d%d",&v[i].a,&v[i].b);
sort(v+1,v+n+1,cmp);
priority_queue<int> Q;
index=1;
while(m--)
{
while(v[index].a<=p&&index<=n)
{
Q.push(v[index].b);
index++;
}
if(!Q.empty())
{
p+=Q.top();
Q.pop();
}
else break;
}
printf("%d\n",p);
}
return (EXIT_SUCCESS);
}
/*Sample Input
2 2 1
1 2
7 3
3 1 2
1 2
2 3
3 4
Sample Output
3
5
*/