题目链接: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. 玩Web虎-运行时受保护文件不可复制

    1. 直接复制粘贴,提示“操作无法完成,因为文件已在system中打开” 2.拔下加密锁后,复制粘贴,依然上错 3.用NoVirusThanks的 kernel-mode driver loader ...

  2. Linux - 版本控制系统SVN

    0. 摘要 本文通过搭建SVN多版本库为例,介绍SVN的使用. SVN是一个集中式版本控制系统,在服务端部署中央版本库,所有开发人员客户端连接到中央版本库进行代码的提交和更新. Apache Subv ...

  3. Hive学习之路 (二)Hive安装

    Hive的下载 下载地址http://mirrors.hust.edu.cn/apache/ 选择合适的Hive版本进行下载,进到stable-2文件夹可以看到稳定的2.x的版本是2.3.3 Hive ...

  4. PHP开发中遇到的问题

    1. 数据库连接 问题:在执行sql语句的函数中,因为strsql用单引号引住,所以里面的变量值无法获得, 方法一: 通过字符串连接的方式完成(.):‘字符串’+.变量来构成一条完整的sql语句.如下 ...

  5. 适合自己的adblock过滤列表

    轻微完美主义,极简主义 已屏蔽广告: 1.CSDN的广告 2.百度侧栏热点搜索 3. 知乎广告 4.stackoverflow的推送广告 5.LeetCode的推送的是否见过这个题 bbs.csdn. ...

  6. MapReduce -- 统计天气信息

    示例 数据: -- :: 34c -- :: 36c -- :: 32c -- :: 37c -- :: 23c -- :: 45c -- :: 50c -- :: 33c -- :: 41c -- ...

  7. RHEL 7.6 安装 Oracle 18c RAC

    RHEL 7.6 安装 Oracle 18c RAC 第一部分 安装规划 虚拟环境 VirtualBox 6.0 OS 版本 Red Hat Enterprise Linux Server relea ...

  8. koa2学习笔记02 - 给koa2添加系统日志 —— node日志管理模块log4js

    前言 没有日志系统的后台应用是没有灵魂的, 平时工作中每次我们遇到接口报错的时候, 都会叫后台的童鞋看下怎么回事, 这时后台的童鞋都会不慌不忙的打开一个骚骚的黑窗口. 一串噼里啪啦的命令输进去, 哐哐 ...

  9. python基础学习1-双层装饰器(实现登陆注册)

    LOGIN_USER = {"IsLogin":False} def check_login(func): #检查登陆的装饰器 def inner(*args,**kwargs): ...

  10. 深度学习与计算机视觉(11)_基于deep learning的快速图像检索系统

    深度学习与计算机视觉(11)_基于deep learning的快速图像检索系统 作者:寒小阳 时间:2016年3月. 出处:http://blog.csdn.net/han_xiaoyang/arti ...