AcWing
  • 首页
  • 课程
  • 题库
  • 更多
    • 竞赛
    • 题解
    • 分享
    • 问答
    • 应用
    • 校园
  • 关闭
    历史记录
    清除记录
    猜你想搜
    AcWing热点
  • App
  • 登录/注册

AcWing 101. 最高的牛    原题链接    简单

作者: 作者的头像   呼和 ,  2019-09-12 00:41:05 ,  所有人可见 ,  阅读 1795


3


1

题目做法 差分

没有用到pair 敲代码,为了思路。搞懂思路,少用库函数。对你思维提高很大的。

面对noip的同学的一种解答。

/*****************************************
Problem Name  : 
******************************************/
#include <queue>
#include <math.h>
#include <stack>
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <algorithm>
using namespace std;
#define LL long long
const int N = 1e5 + 10;
int f[N];
int head[N],to[N],ne[N],len = 0;
int n , p , h , m;
void add(int a, int b)
{
    to[len] = b;
    ne[len] = head[a];
    head[a] = len++;
}
bool find(int a, int b)
{
    for(int i = head[a] ; i ; i = ne[i])
    {
        if(to[i] == b)
            return false;
    }
    return true;
}
int main()
{
    cin >> n >> p >> h >> m;
    for(int i = 0 ; i < m ; i++)
    {
        int a, b;
        cin >> a >> b;
        if(a > b)
            swap(a,b);
        if(find(a,b))
        {
            add(a,b);
            f[a+1]--,f[b]++;
        }
    }
    for(int i = 1 ; i <= n ; i++ )
    {
        f[i] = f[i-1] + f[i];
    }
    int x = h - f[p];
    for(int i = 1 ; i <= n ;i++)
        cout << f[i] + x << endl;
}

2 评论


用户头像
World_Devastator   2020-10-12 17:03         踩      回复

少用库函数为啥不敲平衡树,库就是为了简化程序

用户头像
胡学伟   2020-12-05 11:43         踩      回复

杠精


App 内打开
你确定删除吗?
1024
x

© 2018-2025 AcWing 版权所有  |  京ICP备2021015969号-2
用户协议  |  隐私政策  |  常见问题  |  联系我们
AcWing
请输入登录信息
更多登录方式: 微信图标 qq图标 qq图标
请输入绑定的邮箱地址
请输入注册信息