#include<iostream> #include<vector> #include<set> using namespace std; int maxlevel = 1; vector<vector<int>> v; set<int> s; void dfs(int node,int level){ if(level>maxlevel){ maxlevel = level; s.clear(); s.insert(node); }else if(level == maxlevel){ s.insert(node); } for(int i=0;i<v[node].size();i++){ dfs(v[node][i],level+1); } } int main() { int n,num,root = 0; scanf("%d",&n); v.resize(n+1); for(int i=1;i<=n;i++){ scanf("%d",&num); if(num==-1){ root = i; continue; } v[num].push_back(i); } dfs(root,1); printf("%d\n",maxlevel); for(set<int>::iterator it = s.begin();it!=s.end();it++){ if(it!=s.begin()){ printf(" "); } printf("%d",*it); } return 0; }
#include<iostream> #include<map> #include<vector> #include<bits/stdc++.h> using namespace std; map<string,int> Gp;//在线编程成绩 map<string,int> Gm;//期中考试成绩 map<string,int> Gf;//期末考试成绩 map<string,double> G;//总评 map<string,int>::iterator it; vector< pair<string,int> > vec; bool cmp(pair<string,int> a,pair<string,int>b){ if(a.second!=b.second) return a.second>b.second; return a.first<b.first; } int main() { int p,m,n; cin>>p>>m>>n; for(int i=1;i<=p;i++) { string s; int score; cin>>s>>score; Gp[s]=score; } for(int i=1;i<=m;i++) { string s; int score; cin>>s>>score; Gm[s]=score; } for(int i=1;i<=n;i++) { string s; int score; cin>>s>>score; Gf[s]=score; } it=Gp.begin(); while(it!=Gp.end()) { string s; s=it->first; if(Gm.count(s)>0) { if(Gm[s]>Gf[s]) { G[s]=0.4*Gm[s]+0.6*Gf[s]; G[s]=round(G[s]); } else G[s]=Gf[s]; } else { Gm[s]=-1; G[s]=Gf[s]; } //cout<<s<<" "<<Gp[s]<<" "<<Gm[s]<<" "<<" "<<Gf[s]<<" "<<G[s]<<endl; it++; } for(map<string,double>::iterator it = G.begin();it!=G.end();it++) { vec.push_back( pair<string,int>(it->first,it->second)); } sort(vec.begin(),vec.end(),cmp); for(vector< pair<string,int> >::iterator it=vec.begin();it!=vec.end();it++) { string s; s=it->first; if(Gp[s]>=200&&G[s]>=60) { cout<<s<<" "<<Gp[s]<<" "<<Gm[s]<<" "<<Gf[s]<<" "<<G[s]<<endl; } } }
标签:begin,int,Gf,score,vec,8.15,include From: https://www.cnblogs.com/xuxingkai/p/17632227.html