1109. Group Photo (25)

简介: #include #include #include #include #include #include using namespace std;struct node{ string name;...
#include <iostream>
#include <vector>
#include <map>
#include <cmath>
#include <string>
#include <algorithm>
using namespace std;

struct node{
    string name;
    int h;
};
bool cmp(node &a, node &b){
    if(a.h == b.h) return a.name < b.name;
    else return a.h > b.h;
}

int main()
{
    int n, m, k, cnt = 0;
    cin >> n >> k;
    vector<node> v(n);
    for(int i = 0; i < n; i++){
        cin >> v[i].name >> v[i].h;
    }
    sort(v.begin(), v.end(), cmp);
    for(int i = 0; i < k; i++){
        if(i == 0) m = n / k + n % k;
        else m = n / k;
        int t = m, flag = 0;
        if(m % 2 != 0) t = m-1;
        for(int j = cnt + t - 1; j > cnt; j = j - 2){
            if(j != cnt + t - 1) cout << ' '; 
            cout << v[j].name;
            flag = 1;
        }
        for(int j = cnt; j < cnt + m; j = j + 2 ){
            if(flag){ cout << ' ';}
            else flag = 1;
            cout << v[j].name;
        }
        cnt += m; 
        cout << endl;
    }

    return 0;
}
}
目录
相关文章
|
JavaScript
09HUI - 图片列表(hui-img-list-content)
09HUI - 图片列表(hui-img-list-content)
34 0
|
SQL 关系型数据库 MySQL
only_full_group_by问题而引发的对group by的深入思考
only_full_group_by问题而引发的对group by的深入思考
156 0
group by+group_concat解决的小问题
group by+group_concat解决的小问题
111 0
Media change: please insert the disc labeled
Media change: please insert the disc labeled
112 0
when click one item in table Select at least one column to perform the search
when click one item in table Select at least one column to perform the search
116 0
when click one item in table Select at least one column to perform the search
|
SQL Oracle 关系型数据库
[20171211]HASH GROUP BY ?354?.txt
[20171211]HASH GROUP BY not used when using more that 354 aggregate functions.txt --//http://msutic.
1243 0
|
关系型数据库 Oracle Linux
[20171206]SQLTUNE_CATEGORY参数.txt
[20171206]SQLTUNE_CATEGORY参数.txt --//今天提示别人使用sql profile优化语句,使用DBMS_SQLTUNE.import_sql_profile的引入替换功能.
1310 0