现在有n个香蕉,每个香蕉的质量为ai,m只猴子,每只猴子的体重为bi。
现在将香蕉分给这些猴子,将猴子按照从大到小的顺序依次拿香蕉。当一轮拿完时,还有多的香蕉就会继续一个个拿,直到被拿完。
猴子都是聪明的,每次都会选择一个质量最大的香蕉。
现在请求出每个猴子获得的香蕉质量。
第一行输入两个正整数n,m(1<=n,m<=10^5)
第二行n个整数ai表示每个香蕉的质量(1<=ai<=10^4)
第三行m个整数bi表示每个猴子的体重,保证体重互不相同。(1<=bi<=10^9)
一行,m个用空格分隔的整数,表示每个猴子获得的香蕉质量之和。按照输入顺序输出对应的猴子。
- 5 3
- 1 2 3 4 5
- 3 2 1
7 5 3
这里没想到什么很好的方法,就直接用结构体排序了
使用模运对数组赋值
- #include
-
- using namespace std;
-
- typedef long long int ll;
- #define endl "\n"
- const int maxLine = 1e5+10;
- // #define long long int ll;
-
- // bool cmp(const pair
& a,const pair& b){ - // return a.second
- // }
- // auto maxValue=max_element(mymap.begin(),mymap.end(),cmp);
- // 猴子的序号和体重过
- // prir
mypair[maxLine]; - struct monky {
- int index;
- int w;
- int value;
- };
- struct monky ttt[maxLine];
- // 体重排序
- bool cmp(struct monky a,struct monky b){
- return a.w>b.w;
- }
-
- bool cmp2(struct monky a,struct monky b){
- return a.index
- }
-
- int banana[maxLine];
-
- void print(struct monky arr[maxLine],int nums){
- for(int i=0;i
- cout<
" "<" "< - }
- cout<
- }
- void prints(int arr[maxLine],int nums){
- for(int i=0;i
- cout<
- }
- cout<
- }
- int main() {
- int m,n;
- cin>>m>>n;
- for(int i=0;i
- cin>>banana[i];
- }
- for(int i=0;i
- int w;
- cin>>w;
- ttt[i].index=i;
- ttt[i].w=w;
- }
- // 对香蕉降序
- sort(banana,banana+m,greater<int>());
- // 对猴子体重升序
- sort(ttt,ttt+n,cmp);
-
- for(int i=0;i
- ttt[i%n].value+=banana[i];
- }
- // 按照index升序
- sort(ttt,ttt+n,cmp2);
-
- for(int i=0;i
- cout<
" "; - }
- return 0;
- }
-
相关阅读:
macos知名的清理软件 cleanmymac和腾讯柠檬哪个好 cleanmymacx有必要买吗
小知识:设置archive_lag_target参数强制日志切换
深度学习系列2——Pytorch 图像分类(AlexNet)
LeetCode_贪心算法_简单_605.种花问题
百战c++(数据库1)
【华为机试真题详解】检查是否存在满足条件的数字组合
SoC Architecture Design & Verification
JuiceFS 在多云存储架构中的应用 | 深势科技分享
【npm如何发布自己的插件包】
2022/7/26 考试总结
-
原文地址:https://blog.csdn.net/m0_72678953/article/details/134063812