L - Doki Doki Literature Club 2018 浙江省赛 zoj

一个sort搞定的水题 我非要用priority queue去写 智障了

。。。。

真的智障了

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
#include<queue>
#include<string>
using namespace std;

struct node
{
	char str[25];
	long long value;
	/*friend bool operator < (node a,node b)
	{
		if(a.value!=b.value)
		return a.value<b.value;
		
		if(a.value==b.value)
		{
			if(strcmp(a.str,b.str)>0)
			return a.str>b.str;
			else
			return a.str<b.str;
		}
	}*/
}temp[110];

//priority_queue<node> q;
//priority_queue<node> st;

bool cmp(node a,node b)
{
	if(a.value!=b.value)
		return a.value>b.value;//值由大到小 
	else
	{
		if(strcmp(a.str,b.str)>0)//字典序由小到大 
		return a.str<b.str;
		else
		return a.str>b.str;
	}	
}

int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		//while(!q.empty()) q.pop();
		//while(!st.empty()) st.pop();
		int n,m;
		cin>>n>>m; 
		for(int i=1;i<=n;i++)
		{
			scanf("%s",&temp[i].str);
			scanf("%lld",&temp[i].value);		
		}
		sort(temp+1,temp+1+n,cmp);
		/*for(int i=1;i<=n;i++)
		{
		cout<<q.top().str<<' '<<q.top().value<<endl;
		q.pop();
		}*/
		long long h=0;
		for(int i=1;i<=m;i++)
		{
			//node in=q.top();
			h+=(m-i+1)*temp[i].value;
			//q.pop();
		}
		cout<<h<<' ';
		for(int i=1;i<=m-1;i++)
		{
			//node in=st.top();
			cout<<temp[i].str<<' ';
			//st.pop();
		}
		//node in=st.top();
		cout<<temp[m].str<<endl;
		//gtx1080
	}
}

猜你喜欢

转载自blog.csdn.net/weixin_41544329/article/details/83508325
今日推荐