本文共 832 字,大约阅读时间需要 2 分钟。
简单模拟。
#include #include #include #include #include #include #include #include #include #include using namespace std;struct X{ string name; int h;} s[100000+10];int n,k;vector g[200];int tmp[10000+10];bool cmp(const X&a,const X&b){ if(a.h==b.h) return a.name b.h;}int main(){ scanf("%d%d",&n,&k); for(int i=1; i<=n; i++) cin>>s[i].name>>s[i].h; sort(s+1,s+n+1,cmp); int t=n+1; for(int i=k; i>=1; i--) { int m; if(i>1) m=n/k; else m=n-n/k*(k-1); t=t-m; int y=t,p=m/2+1,sz=0; int L,R; tmp[p]=y++,sz++,L=p-1,R=p+1; while(1) { if(sz==m) break; if(sz%2==0) tmp[R++]=y++; else tmp[L--]=y++; sz++; } for(int j=1;j<=m;j++) g[i].push_back(tmp[j]); } for(int i=1; i<=k; i++) { for(int j=0; j
转载于:https://www.cnblogs.com/zufezzt/p/5644689.html