当前位置:网站首页>PAT甲级 1056 Mice and Rice
PAT甲级 1056 Mice and Rice
2022-08-08 00:53:00 【九是否非随机的称呼】
#include<iostream>
#include<vector>
#include<queue>
#include<string>
#include<bits/stdc++.h>
using namespace std;
typedef struct{
int weight, index, index0, rank;
}record;
bool compare(record &rd, record &ld){
if(rd.index0 < ld.index0) return true;
else return false;
}
int main(void){
int i, j, g, m, n, t, counts, x, y, cnt=0;
cin>>m>>g;
vector<int> v, v0;
vector<record> vrt;
for(i = 0; i < m; i++){
cin>>t;
v.push_back(t);
}
record rcr, tmp;
for(i = 0; i < m; i++){
cin>>rcr.index0;
rcr.weight = v[rcr.index0];
rcr.index = i;
rcr.rank = 0;
vrt.push_back(rcr);
}
queue<record> q;
for(i = 0; i < m; i++){
q.push(vrt[i]);
}
int group, max=-9;
while(q.size()!=0){
x = q.size();
group = x/g;
if(x%g!=0) group += 1;
cnt = 0;
if(x==1){
rcr = q.front();
vrt[rcr.index].rank = 1;
break;
}
for(i = 0; i < x; i++){
rcr = q.front();
vrt[rcr.index].rank = group + 1;
q.pop();
cnt++;
if(max < rcr.weight){
max = rcr.weight;
tmp = rcr;
}
if(cnt%g==0 || i == (x - 1) ){
max = -9;
q.push(tmp);
}
}
}
sort(vrt.begin(), vrt.end(), compare);
for(i=0; i<m; i++){
printf("%d", vrt[i].rank);
if(i!=m-1) printf(" ");
}
return 0;
}边栏推荐
- 有关原码,反码,补码那些事
- 陈强教授《机器学习及R应用》课程第十一章作业
- DataNode Disk Detection Service
- SwiftUI使用MatchedGeometryEffect快速同步不同继承层级中视图的位置和尺寸
- ip and userId in awk statistics log--analyze the behavior of users maliciously brushing the interface
- 倒水问题(暑假每日一题 17)
- In-depth Synchronized various usage methods
- 继承关系下构造方法的访问特点
- SVG基本图形
- Is it safe to snowball account!
猜你喜欢

SwiftUI使用MatchedGeometryEffect快速同步不同继承层级中视图的位置和尺寸

【神器】MarkDown-沉浸写作的利器

kaggle小白必看:小白常见的2个错误解决方案

Good news | Hongshi data has obtained CMMI level 3 certification!Welcome to the self-developed unified operation and maintenance monitoring platform!

2021 RoboCom 世界机器人开发者大赛-本科组(决赛)7-1绿色围栏(模拟)

BOSS直聘再爆情色招聘丑闻,面试官行为不堪入目

leetcode 30. 串联所有单词的子串

提升领导力的有效方法

继承关系下构造方法的访问特点注意:把this()访问本类其他成员方法也加进去

使用开源库libyuv中替换开源汇编接口,解决汇编接口中的崩溃问题
随机推荐
使用大智慧炒股,资金能保证安全吗?
Let’s talk about the anti-reverse circuit in combination with the actual situation (summary of the anti-reverse circuit)
pycharm连接远程服务器
redis分布式锁实现
kaggle小白必看:小白常见的2个错误解决方案
一套极简的MQTT使用接口EasyMqttClient
Win10 rdkit download and use
Is it safe and reliable to open a securities account?
adb命令logcat抓取日志
【愚公系列】2022年08月 Go教学课程 032-结构体方法继承
分布式一致性协议 之 Lease机制
SVG基本图形
快速将rmd文件转化为R纯代码文件
[QNX Hypervisor 2.2 User Manual] 10.11 vdev progress
Flexible and easy-to-use sql monitoring script part6
没有操作的思考
STM32F103C8T6模拟SPI控制6针/7针0.96寸OLED显示屏
倒水问题(暑假每日一题 17)
Octopus Application Chain|Content Curation Collaboration Organization DISCOVOL DAO Mainnet Launched in August
OpenFeign简介和使用详解
https://github.com/ZouJiu1/PAT