题目链接: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的更多相关文章

  1. CF刷题-Codeforces Round #481-G. Petya's Exams

    题目链接:https://codeforces.com/contest/978/problem/G 题目大意:n天m门考试,每门考试给定三个条件,分别为:1.可以开始复习的日期.2.考试日期.3.必须 ...

  2. CF刷题-Codeforces Round #481-D. Almost Arithmetic Progression

    题目链接:https://codeforces.com/contest/978/problem/D 题解: 题目的大意就是:这组序列能否组成等差数列?一旦构成等差数列,等差数列的公差必定确定,而且,对 ...

  3. [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 ...

  4. Educational Codeforces Round 40 F. Runner's Problem

    Educational Codeforces Round 40 F. Runner's Problem 题意: 给一个$ 3 * m \(的矩阵,问从\)(2,1)$ 出发 走到 \((2,m)\) ...

  5. Codeforces Round #481 (Div. 3)

    我实在是因为无聊至极来写Div3题解 感觉我主要的作用也就是翻译一下题目 第一次线上打CF的比赛,手速很重要. 这次由于所有题目都是1A,所以罚时还可以. 下面开始讲题 A.Remove Duplic ...

  6. 水题 Codeforces Round #105 (Div. 2) B. Escape

    题目传送门 /* 水题:这题唯一要注意的是要用double,princess可能在一个小时之内被dragon赶上 */ #include <cstdio> #include <alg ...

  7. 水题 Codeforces Round #302 (Div. 2) A Set of Strings

    题目传送门 /* 题意:一个字符串分割成k段,每段开头字母不相同 水题:记录每个字母出现的次数,每一次分割把首字母的次数降为0,最后一段直接全部输出 */ #include <cstdio> ...

  8. 水题 Codeforces Round #300 A Cutting Banner

    题目传送门 /* 水题:一开始看错题意,以为是任意切割,DFS来做:结果只是在中间切出一段来 判断是否余下的是 "CODEFORCES" :) */ #include <cs ...

  9. 水题 Codeforces Round #299 (Div. 2) A. Tavas and Nafas

    题目传送门 /* 很简单的水题,晚上累了,刷刷水题开心一下:) */ #include <bits/stdc++.h> using namespace std; ][] = {" ...

随机推荐

  1. 为什么ConcurrentHashMap是弱一致的

    为什么ConcurrentHashMap是弱一致的 本文将用到Java内存模型的happens-before偏序关系(下文将简称为hb)以及ConcurrentHashMap的底层模型相关的知识.ha ...

  2. redis开启远程连接访问和需要密码的方法

    redis默认是不能远程访问的,如果希望多台机子共用redis数据库,那就需要开启redis远程连接访问.既然可以远程连接了,那就需要密码登陆,否则不安全.下面是具体的方法,按照步骤一步一步来就OK了 ...

  3. HDU 5550 - Game Rooms(DP + 前缀和预处理)

    链接: http://acm.hdu.edu.cn/showproblem.php?pid=5550 题意: 一个大楼有n(2≤n≤4000)层,每层可以建一个乒乓球房或者一个游泳房,且每种房间在大楼 ...

  4. P3694 邦邦的大合唱站队

    题目背景 BanG Dream!里的所有偶像乐队要一起大合唱,不过在排队上出了一些问题. 题目描述 N个偶像排成一列,他们来自M个不同的乐队.每个团队至少有一个偶像. 现在要求重新安排队列,使来自同一 ...

  5. Spring源码分析(十)注册解析的BeanDefinition

    摘要:本文结合<Spring源码深度解析>来分析Spring 5.0.6版本的源代码.若有描述错误之处,欢迎指正. 对配置文件解析完成后,获取的beanDefiniton已经可以进行使用了 ...

  6. 使用Ceph集群作为Kubernetes的动态分配持久化存储(转)

    使用Docker快速部署Ceph集群 , 然后使用这个Ceph集群作为Kubernetes的动态分配持久化存储. Kubernetes集群要使用Ceph集群需要在每个Kubernetes节点上安装ce ...

  7. block本质探寻四之copy

    说明: <1>阅读本文,最好阅读之前的block文章加以理解: <2>本文内容:三种block类型的copy情况(MRC).是否深拷贝.错误copy: 一.MRC模式下,三种b ...

  8. helpera64开发板下制作ubuntu rootfs镜像

    下一篇路径:https://www.cnblogs.com/jizizh/p/10499448.html 环境: HelperA64开发板 Linux3.10内核 时间:2019.02.14 目标:定 ...

  9. WPF之ListView使用WrapPanel

    原文:WPF之ListView使用WrapPanel 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/jiuzaizuotian2014/articl ...

  10. Angular基础开始

    这个我是想用Angular写一个简单的WebApp,这个是一个简简单单路由: 公共模板--index.html: <!DOCTYPE html> <html ng-app='myAp ...