1056. Mice and Rice (25)
2016-03-07 22:25
309 查看
传送门 :https://www.patest.cn/contests/pat-a-practise/1056
英语不好,所以读起来很吃力,好久才弄明白第一行11个数是编号从0-10的重量 而不是对应下方随机编号的.
AC代码
#include <iostream>
#include <string>
#include <cstdio>
#include <vector>
#include <queue>
#include <algorithm>
#include <stack>
#include <map>
using namespace std;
struct player{
int id,rank,weight;
};
void solution(vector<player *> ans,int NG){
if(ans.size()==1){
ans[0]->rank = 1;
return ;
}
int len = (int)ans.size();
int x= ans.size()%NG==0?len/NG:len/NG+1;
vector<player *>nextMath;
int i = 0,j;
while (i<len) {
if(i+NG<len)
j = i+NG;
else
j = len;
sort(ans.begin()+i, ans.begin()+j, [](player *a ,player *b){
return a->weight>b->weight;
});
for (int k = i+1; k<j; k++)
ans[k]->rank = x+1;
nextMath.push_back(ans[i]);
i = j;
}
solution(nextMath, NG);
}
int main()
{
int NP,NG,a;
scanf("%d %d",&NP,&NG);
vector<player *>ans;
vector<int>weight(NP);
for (int i=0; i<NP; ++i) {
player * p = new player();
ans.push_back(p);
scanf("%d",&weight[i]);
}
for (int i=0; i<NP; ++i) {
scanf("%d",&a);
ans[i]->id = a;
ans[i]->weight = weight[a];
}
solution(ans, NG);
sort(ans.begin(), ans.end(), [](player *a ,player *b){
return a->id<b->id;
});
for (int i=0; i<NP; ++i) {
printf(i==NP-1?"%d\n":"%d ",ans[i]->rank);
}
return 0;
}
英语不好,所以读起来很吃力,好久才弄明白第一行11个数是编号从0-10的重量 而不是对应下方随机编号的.
AC代码
#include <iostream>
#include <string>
#include <cstdio>
#include <vector>
#include <queue>
#include <algorithm>
#include <stack>
#include <map>
using namespace std;
struct player{
int id,rank,weight;
};
void solution(vector<player *> ans,int NG){
if(ans.size()==1){
ans[0]->rank = 1;
return ;
}
int len = (int)ans.size();
int x= ans.size()%NG==0?len/NG:len/NG+1;
vector<player *>nextMath;
int i = 0,j;
while (i<len) {
if(i+NG<len)
j = i+NG;
else
j = len;
sort(ans.begin()+i, ans.begin()+j, [](player *a ,player *b){
return a->weight>b->weight;
});
for (int k = i+1; k<j; k++)
ans[k]->rank = x+1;
nextMath.push_back(ans[i]);
i = j;
}
solution(nextMath, NG);
}
int main()
{
int NP,NG,a;
scanf("%d %d",&NP,&NG);
vector<player *>ans;
vector<int>weight(NP);
for (int i=0; i<NP; ++i) {
player * p = new player();
ans.push_back(p);
scanf("%d",&weight[i]);
}
for (int i=0; i<NP; ++i) {
scanf("%d",&a);
ans[i]->id = a;
ans[i]->weight = weight[a];
}
solution(ans, NG);
sort(ans.begin(), ans.end(), [](player *a ,player *b){
return a->id<b->id;
});
for (int i=0; i<NP; ++i) {
printf(i==NP-1?"%d\n":"%d ",ans[i]->rank);
}
return 0;
}
相关文章推荐
- html基础学习第一天
- 单例设计模式(三)-------简单实现一个单例设计模式
- 浅谈Struts2拦截器的原理与实现
- CodeForces - 630R Game (规律)水
- CentOS 6和CentOS 7进入单用户模式区别
- 201. Bitwise AND of Numbers Range LeetCode
- Android多点触控技术实战,自由地对图片进行缩放和移动
- [leetcode 137] Single Number II
- Vagrant启动报错
- Codeforces Round #345 (Div. 2)(C)排列组合,思维
- ImageView 备忘录
- 定义一个一维指针指向二维数组并打印
- [转]GBDT(Gradient Boosting Decision Tree)迭代决策树
- 基于CentOS安装Redis
- 我与git“美妙”的一天
- 初学delphi
- 文件加密二进制版本
- NSMutableDictionary
- CodeForces - 630G Challenge Pennants (组合数学)
- 课堂作业3