A1141 PAT Ranking of Institutions

1.用map做string道double的映射
2.遍历所有映射,放进结构体数组,然后按要求排序
3.有的题解说map会超时,我的程序没有出现这个问题,最大运行时间到400多ms,如果真的超时用unordered_map
4.计算TWS的时候不用吧BAT都算出来在加权求和,实时加权求和一样的
5.sort只到len长度,一开始写了到n,结果最后一个点一直错

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <map>
using namespace std;

struct node{
	string SCH;
	double TWS;
	int NS;
};
bool cmp(node a,node b)
{
	if((int)a.TWS != (int)b.TWS)return a.TWS > b.TWS;
	else if(a.NS != b.NS)return a.NS < b.NS;
	else return a.SCH < b.SCH;
	
}
int main()
{
	int n;
	scanf("%d",&n);
	string id,sch;
	int grade;
	map<string,node> mp;
	for(int i=0;i<n;i++){
		cin>>id>>grade>>sch;
		for(int j=0;j<sch.length();j++){	//转换为小写 
			if(sch[j]>='A' && sch[j]<='Z'){
				sch[j] += 'a'-'A';
			}
		}
		if(id[0]=='B')mp[sch].TWS += 1.0*grade/1.5;
		if(id[0]=='A')mp[sch].TWS += 1.0*grade;
		if(id[0]=='T')mp[sch].TWS += 1.0*grade*1.5;
		mp[sch].NS++;
	}
	node S[n];			//将map映射放入结构体数组,方便排序 
	int len = 0;
	for(map<string,node>::iterator it=mp.begin();it!=mp.end();it++){
		S[len] = it->second;
		S[len].SCH = it->first;
		len++;
	}
	sort(S,S+len,cmp);			//排序 
	printf("%d\n",len);			//sch个数 
	int rank = 1;				//排名 
	for(int i=0;i<len;i++){
		if(i>=1 && (int)S[i].TWS < (int)S[i-1].TWS)rank = i+1;
		printf("%d ",rank);
		cout<<S[i].SCH;
		printf(" %d %d\n",(int)S[i].TWS,S[i].NS);
	}
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Interconnected multilayer networks are complex systems that consist of multiple layers of interconnected networks. These networks can represent various social, technological, and biological systems, and their analysis is essential for understanding the dynamics of these systems. Ranking the nodes in interconnected multilayer networks can reveal the most important nodes, which play a crucial role in the functioning of the system. The ranking of nodes in interconnected multilayer networks is a challenging problem because the nodes' importance in one layer may not necessarily correspond to their importance in another layer. Therefore, a comprehensive ranking method should consider the nodes' importance across all layers of the network. Recent research has proposed several ranking methods for interconnected multilayer networks. One of the most promising approaches is the multilayer PageRank algorithm, which extends the classic PageRank algorithm to multilayer networks. This algorithm considers the importance of nodes in all layers of the network and assigns a score to each node based on its influence on the entire system. The ranking of nodes in interconnected multilayer networks has various applications, such as identifying critical nodes in transportation networks, predicting the spread of diseases in social networks, and detecting influential users in online social networks. Furthermore, the ranking of nodes can reveal versatile nodes that play a crucial role in multiple layers of the network, indicating their importance in maintaining the system's functionality. In conclusion, ranking nodes in interconnected multilayer networks is a crucial task that can reveal the most important and versatile nodes in the system. This information can be used to optimize the network's performance, identify critical nodes, and predict the system's behavior under different conditions.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值