zoukankan      html  css  js  c++  java
  • D

    卿学姐与魔法

    Time Limit: 1200/800MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others)
     

    “你的膜法也救不了你

    在去拯救公主的道路上,卿学姐披荆斩棘,刀刃早已锈迹斑斑。

    一日卿学姐正在为武器的问题发愁,碰到了正在赏树的天行廖。

    天行廖嘴角微扬,似乎看穿了卿学姐的心思,故意在此等待。

    “少年,你渴望掌握雷电的力量吗?”天行廖如是问道。

    已经差不多是条咸鱼的卿学姐欣然答应了。于是卿学姐开始跟随魔法大师天行廖学习魔法的力量。

    刚入门的卿学姐发现,每个魔法都是由两种基本元素构成的,A元素和B元素。

    而每个魔法的魔力是合成这个魔法的A元素和B元素的大小的和。

    例如一个大小为3的A元素和一个大小为6的B元素,能构成一个魔力为9的魔法。

    现在卿学姐收集了NN个A元素和NN个B元素。

    敏锐的卿学姐立刻发现他能组合出NNN∗N种魔法。

    谦虚的卿学姐并不希望自己太跳,所以他准备将这NNN∗N种魔法中的最小的NN种展示给天行廖检查。

    现在卿学姐想知道,这NNN∗N种魔法中最小的NN种是什么。

    当然,得从小到大输出哦~

    Input

    第一行一个整数NN

    接下来一行有NN个数,表示NN个A元素

    接下来一行有NN个数,表示NN个B元素

    1N1000001≤N≤100000

    1A[i],B[i]10000000001≤A[i],B[i]≤1000000000

    Output

    输出NN行,每行一个整数

    代表NNN∗N种魔法中最小的NN个

    Sample input and output

    Sample InputSample Output
    5
    1 3 2 4 5 
    6 3 4 1 7
    2
    3
    4
    4
    5
    #pragma GCC diagnostic error "-std=c++11"
    #include<algorithm>
    #include<iostream>
    #include<cstring>
    #include<cstdio>
    #include<vector>
    #include<queue>
    
    using namespace std;
    const int N = 100000 + 5;
    int A[N], B[N];
    struct node{
        int a, b;
        bool operator < (const node & x)const{
            return A[a] + B[b] > A[x.a] + B[x.b];
        }
    };
    
    priority_queue<node> Q;
    
    void Work(int n){
        for(int i = 0; i < n; i++) Q.push((node){i, 0});
        for(int i = 0; i < n; i++){
            node tmp = Q.top(); Q.pop();
            printf("%d
    ", A[tmp.a] + B[tmp.b]);
            tmp.b++;
            if(tmp.b == n) continue;
            Q.push( tmp );
        }
    }
    int main(){
        int n;
        scanf("%d", &n);
        for(int i = 0; i < n; i++) scanf("%d", &A[i]);
        for(int i = 0; i < n; i++) scanf("%d", &B[i]);
        sort(A, A + n);
        sort(B, B + n);
        Work( n );
        return 0;
    }
  • 相关阅读:
    写了一个抓飞信包的小工具
    Drools.Net Bug?
    论坛系统分析比较
    在线个人财务管理服务推荐:财客在线网络账本
    多站点的google analytics的使用心得
    FeedSky更新出现很大延时
    愚人节,中华民族的伟大梦想实现了
    Community Server 2008.5 SP2发布啦
    [已上传流程图]在线服务器状态监控预警软件推荐:网站保姆
    五一公司搬家记
  • 原文地址:https://www.cnblogs.com/Pretty9/p/7418763.html
Copyright © 2011-2022 走看看