现在有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;
- }
-
相关阅读:
FWT小结
【Spark NLP】第 8 章:使用 Keras 进行序列建模
Java项目:洗浴中心管理系统(java+SSM+JSP+jQuery+javascript+Mysql)
web前端期末大作业:青岛旅游网页主题网站设计——青岛民俗4页 HTML+CSS 民俗网页设计与制作 web网页设计实例作业 html实训大作业
全栈知识体系
Linux用户和权限
自定义权限指令与防止连点指令
【leetcode】最长斐波那契数列
哪种品牌台灯适合学生用?盘点学生护眼台灯十大牌子
基于SpringBoot+Vue+uniapp的家政服务预约系统的详细设计和实现(源码+lw+部署文档+讲解等)
-
原文地址:https://blog.csdn.net/m0_72678953/article/details/134063812