CodeForces 840A - Leha and Function | Codeforces Round #429 (Div. 1)

/*
CodeForces 840A - Leha and Function [ 贪心 ]  |  Codeforces Round #429 (Div. 1)
A越大,B越小,越好
*/
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5+5;
int a[N], b[N], c[N], n;
int aa[N], bb[N];
bool cmp1(int x, int y) {
    return a[x] > a[y];
}
bool cmp2(int x, int y) {
    return b[x] < b[y];
}
int main()
{
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    for (int i = 1; i <= n; i++) scanf("%d", &b[i]);
    for (int i = 1; i <= n; i++) aa[i] = bb[i] = i;
    sort(aa+1, aa+n+1, cmp1);
    sort(bb+1, bb+n+1, cmp2);
    for (int i = 1; i <= n; i++) c[bb[i]] = a[aa[i]];
    for (int i = 1; i < n; i++) printf("%d ", c[i]);
    printf("%d\n", c[n]);
}

  

时间: 2024-10-27 14:15:00

CodeForces 840A - Leha and Function | Codeforces Round #429 (Div. 1)的相关文章

CodeForces 840B - Leha and another game about graph | Codeforces Round #429(Div 1)

思路来自这里,重点大概是想到建树和无解情况,然后就变成树形DP了- - /* CodeForces 840B - Leha and another game about graph [ 增量构造,树上差分 ] | Codeforces Round #429(Div 1) 题意: 选择一个边集合,满足某些点度数的奇偶性 分析: 将d = 1的点连成一颗树,不在树上的点都不连边. 可以发现,当某个节点u的所有子节点si均可操控 (u, si) 来满足自身要求 即整棵树上至多只有1个点不满足自身要求,

Codeforces Round#429(Div.2)

A. Generous Kefa 如果有字母的个数大于k则NO #include<bits/stdc++.h> using namespace std; int arr[28],n,k; string str; int main(){ cin>>n>>k; cin>>str; for(int i = 0;i<str.length();i++){ arr[(int)(str[i]-'a')]++; } for(int i = 0;i<26;i++)

【CodeForces】841C. Leha and Function(Codeforces Round #429 (Div. 2))

[题意]定义函数F(n,k)为1~n的集合中选择k个数字,其中最小数字的期望. 给定两个数字集A,B,A中任意数字>=B中任意数字,要求重组A使得对于i=1~n,sigma(F(Ai,Bi))最大. [算法]数学结论+数学期望+排序 [题解]很无奈,这题放在div2 C,难以推导的期望公式,广为人知的结论,容易观察样例得出的做法,都体现了这道题的不合理性. F(n,k)=(n+1)/(k+1) 公式推导可能触及我的知识盲区了QAQ 得到公式后,显然要求k尽可能小,n尽可能大,经验告诉我们随着两数

【推导】【DFS】Codeforces Round #429 (Div. 1) B. Leha and another game about graph

题意:给你一张图,给你每个点的权值,要么是-1,要么是1,要么是0.如果是-1就不用管,否则就要删除图中的某些边,使得该点的度数 mod 2等于该点的权值.让你输出一个留边的方案. 首先如果图内有-1,那么必有解.否则如果初始不合法的点数为偶数,那么必有解,否则无解.因为删一条边,要么使图中不合法的点数+2,要么不变,要么-2. 如果有解,构造图的任意一个生成树,如果有-1,就让-1为根,否则任意结点为根.然后从叶子向根定每个点的入度数,由于自底向上,一个结点的儿子边都被处理完后,只需要决定父边

Codeforces Round #429 (Div. 2) 841B Godsend(签到题)

B. Godsend Leha somehow found an array consisting of n integers. Looking at it, he came up with a task. Two players play the game on the array. Players move one by one. The first player can choose for his move a subsegment of non-zero length with an

Codeforces Round #429 (Div. 2) 841A. Generous Kefa(签到题)

A. Generous Kefa One day Kefa found n baloons. For convenience, we denote color of i-th baloon as si - lowercase letter of the Latin alphabet. Also Kefa has k friends. Friend will be upset, If he get two baloons of the same color. Kefa want to give o

Codeforces Round #429 (Div. 2)ABC

A: 题意:n个东西,k个朋友,全部给朋友,每个朋友不可以拿同样的,问是否可行 1 #include<bits/stdc++.h> 2 using namespace std; 3 4 map<char ,int >ma; 5 int main(){ 6 int n,k; 7 cin>>n>>k; 8 string s; 9 cin>>s; 10 for(int i=0;i<n;i++){ 11 ma[s[i]]++; 12 if(ma[s

Round #429 (Div.2)

---恢复内容开始--- One day Kefa found n baloons. For convenience, we denote color of i-th baloon as si - lowercase letter of the Latin alphabet. Also Kefa has k friends. Friend will be upset, If he get two baloons of the same color. Kefa want to give out a

Codeforces Round #245 (Div. 1)——Tricky Function

l and dished out an assist in the Blackhawks' 5-3 win over the Nashville Predators.Shaw said just playing with the Blackhawks was enough motivation for him."Positive, I'm playing in the NHL," Shaw said after Sunday's win. "What can't you be