CF刷题-Codeforces Round #481-F. Mentors
题目链接:https://codeforces.com/contest/978/problem/F
题目大意:
n个程序员,k对仇家,每个程序员有一个能力值,当甲程序员的能力值绝对大于乙程序员的能力值时,甲可以做乙的爸爸,对于每个程序员,它可以做多少人的爸爸?(仇家之间不能做父子)
题解:
第一次:WA 失误
第二次:TL 找有效徒弟和仇家时,太复杂

第三次:ML 找有效徒弟依然复杂,找仇家简单了,但是内存超了

第四次:TL 解决了内存问题,找有效徒弟复杂,找仇家简单,时间超了(最接近成功的一次)
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<set>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N = 2e5+;
struct programmer{
int b;
int r;
bool operator == (const int & i){
return (this->r == i);
}
}inip[N],p[N]; int ans[N];
int cmp(programmer&a,programmer&b){
return a.r < b.r;
}
struct ene{
int eff_enemy_num = ;
}d[N];
int main(void){
int n,k;
int tmp_r;
scanf("%d%d",&n,&k);
for(int i = ;i<=n;i++){
scanf("%d",&tmp_r);
p[i].b = i;
p[i].r = tmp_r;
inip[i].b = i;
inip[i].r = tmp_r;
}
sort(p+,p+n+,cmp);
int q1,q2;
for(int i=;i<k;i++){
scanf("%d%d",&q1,&q2);
if(inip[q1].r < inip[q2].r){
d[q2].eff_enemy_num++;
}
else if(inip[q1].r > inip[q2].r){
d[q1].eff_enemy_num++;
}
}
for(int i=;i<=n;i++){
int possibel_enemy_num;
int sum;
possibel_enemy_num = find(p+,p+i+,p[i].r) - p -;
sum = possibel_enemy_num - d[p[i].b].eff_enemy_num;
ans[p[i].b] = sum;
}
ans[p[].b] = ;
for(int i = ;i<=n;i++){
printf("%d",ans[i]);
if(i != n){
printf(" ");
}
}
return ;
}
第五次:TL 自认为优化,但是找有效徒弟还是太复杂
第六次:AC
代码如下:
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<set>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N = 2e5+;
struct programmer{
int b;
int r;
}inip[N],p[N]; map<int,int> z;
int ans[N];
int t[N];
int cmp(programmer&a,programmer&b){
return a.r < b.r;
}
struct ene{
int eff_enemy_num = ;
}d[N];
int main(void){
int n,k;
int tmp_r;
memset(t,,sizeof(t));
scanf("%d%d",&n,&k);
for(int i = ;i<=n;i++){
scanf("%d",&tmp_r);
p[i].b = i;
p[i].r = tmp_r;
inip[i].b = i;
inip[i].r = tmp_r;
}
sort(p+,p+n+,cmp);
int q1,q2;
for(int i=;i<k;i++){
scanf("%d%d",&q1,&q2);
if(inip[q1].r < inip[q2].r){
d[q2].eff_enemy_num++;
}
else if(inip[q1].r > inip[q2].r){
d[q1].eff_enemy_num++;
}
}
for(int i = ;i<=n;i++){
z[p[i].r] = ;
}
for(int i =;i<=n;i++){
t[p[i].b] = z[p[i].r];
z[p[i].r]++;
}
for(int i=;i<=n;i++){
int possibel_enemy_num;
int sum; possibel_enemy_num = i--t[p[i].b];
sum = possibel_enemy_num - d[p[i].b].eff_enemy_num;
ans[p[i].b] = sum;
}
ans[p[].b] = ;
for(int i = ;i<=n;i++){
printf("%d",ans[i]);
if(i != n){
printf(" ");
}
}
return ;
}
神犇代码(思路一致,但是简洁太多了):
#include <bits/stdc++.h> using namespace std;
const int maxn = 2e5 + ;
typedef long long ll; struct NODE {
int va,ans;
}node[maxn]; int n,k,num[maxn]; void init() {
scanf("%d%d",&n,&k);
for(int i=;i<=n;i++) {
scanf("%d",&node[i].va);
num[i] = node[i].va;
}
sort(num+,num++n); for(int i=;i<=n;i++) {
NODE k = node[i];
node[i].ans = lower_bound(num+,num++n,k.va) - num - ;
}
} int main() {
init();
while(k--) {
int a,b;
scanf("%d%d",&a,&b);
if(node[a].va < node[b].va) {
node[b].ans--;
} else if(node[b].va < node[a].va) {
node[a].ans--;
}
}
for(int i=;i<=n;i++)
printf("%d ",node[i].ans);
return ;
}
CF刷题-Codeforces Round #481-F. Mentors的更多相关文章
- CF刷题-Codeforces Round #481-G. Petya's Exams
题目链接:https://codeforces.com/contest/978/problem/G 题目大意:n天m门考试,每门考试给定三个条件,分别为:1.可以开始复习的日期.2.考试日期.3.必须 ...
- CF刷题-Codeforces Round #481-D. Almost Arithmetic Progression
题目链接:https://codeforces.com/contest/978/problem/D 题解: 题目的大意就是:这组序列能否组成等差数列?一旦构成等差数列,等差数列的公差必定确定,而且,对 ...
- [cf contest 893(edu round 33)] F - Subtree Minimum Query
[cf contest 893(edu round 33)] F - Subtree Minimum Query time limit per test 6 seconds memory limit ...
- Educational Codeforces Round 40 F. Runner's Problem
Educational Codeforces Round 40 F. Runner's Problem 题意: 给一个$ 3 * m \(的矩阵,问从\)(2,1)$ 出发 走到 \((2,m)\) ...
- Codeforces Round #481 (Div. 3)
我实在是因为无聊至极来写Div3题解 感觉我主要的作用也就是翻译一下题目 第一次线上打CF的比赛,手速很重要. 这次由于所有题目都是1A,所以罚时还可以. 下面开始讲题 A.Remove Duplic ...
- 水题 Codeforces Round #105 (Div. 2) B. Escape
题目传送门 /* 水题:这题唯一要注意的是要用double,princess可能在一个小时之内被dragon赶上 */ #include <cstdio> #include <alg ...
- 水题 Codeforces Round #302 (Div. 2) A Set of Strings
题目传送门 /* 题意:一个字符串分割成k段,每段开头字母不相同 水题:记录每个字母出现的次数,每一次分割把首字母的次数降为0,最后一段直接全部输出 */ #include <cstdio> ...
- 水题 Codeforces Round #300 A Cutting Banner
题目传送门 /* 水题:一开始看错题意,以为是任意切割,DFS来做:结果只是在中间切出一段来 判断是否余下的是 "CODEFORCES" :) */ #include <cs ...
- 水题 Codeforces Round #299 (Div. 2) A. Tavas and Nafas
题目传送门 /* 很简单的水题,晚上累了,刷刷水题开心一下:) */ #include <bits/stdc++.h> using namespace std; ][] = {" ...
随机推荐
- OSM
一.OSM是什么 开放街道图(OpenStreetMap,简称OSM)是一个网上地图协作计划,目标是创造一个内容自由且能让所有人编辑的世界地图(wiki:http://wiki.openstreetm ...
- BZOJ1189:[HNOI2007]紧急疏散EVACUATE(最大流,枚举)
Description 发生了火警,所有人员需要紧急疏散!假设每个房间是一个N M的矩形区域.每个格子如果是'.',那么表示这是一 块空地:如果是'X',那么表示这是一面墙,如果是'D',那么表示这是 ...
- hive遇到的问题以及解决办法
hive java.lang.ClassNotFoundException: Class org.apache.hive.hcatalog.data.JsonSerDe not found hadoo ...
- 统计Azure存储的HBase各表数据量
场景:HBase存储在Azure上,现在通过访问Azure Storage的接口,获取HBase中各个表的数据量. 注意: 1.Azure存储,默认的副本数为2,即共存3份,但只收1份的费用,取到的s ...
- VC++程序运行时间测试函数
0:介绍 我们在衡量一个函数运行时间,或者判断一个算法的时间效率,或者在程序中我们需要一个定时器,定时执行一个特定的操作,比如在多媒体中,比如在游戏中等,都会用到时间函数.还比如我们通过记录函数或者算 ...
- 愤怒的小鸟【$DP$优化】
卡常的状压\(DP\),愤怒的小鸟. 其实本来是个很水的状压\(DP\),但因为最后三个点\(n=18\),成功地把我的不可能达到的下界为\(\Omega(2^nn^2)\),紧确的上界为\(O(2^ ...
- [LuoguP1462]通往奥格瑞玛的道路($SPFA+$二分)
#\(\mathcal{\color{red}{Description}}\) \(Link\) 有一个图,求其在\(1-N\)的最短路小于一个给定值下,点权最大值的最小值. #\(\mathcal{ ...
- 使用VS Code发布博客
使用VS Code 发布文章 这也是学习别人怎么去使用VS Code 发布文章 上传图片 这是我上传的图片 通过插件的方式上传 ctrl+alt+aQQ截图 使用插件 Markdown All in ...
- iOS url出现特殊字符处理 -- stringByAddingPercentEncodingWithAllowedCharacters
stringByAddingPercentEscapesUsingEncoding(只对 `#%^{}[]|\"<> 加空格共14个字符编码,不包括”&?”等符号), i ...
- json_decode($str,true)的结果为null
//$result为传进来的json值 $result = $this->params['auth_result']; //html_entity_decode进行HTML 实体转换为字符 // ...