UESTCoj - 1329 卿学姐与魔法 (优先队列
2017-03-30 01:33
274 查看
卿学姐与魔法
[/i] EditTime Limit: 1200/800MS (Java/Others)
Memory Limit: 65535/65535KB (Java/Others)
Submit
Status
“你的膜法也救不了你”——蛤
在去拯救公主的道路上,卿学姐披荆斩棘,刀刃早已锈迹斑斑。
一日卿学姐正在为武器的问题发愁,碰到了正在赏树的天行廖。
天行廖嘴角微扬,似乎看穿了卿学姐的心思,故意在此等待。
“少年,你渴望掌握雷电的力量吗?”天行廖如是问道。
已经差不多是条咸鱼的卿学姐欣然答应了。于是卿学姐开始跟随魔法大师天行廖学习魔法的力量。
刚入门的卿学姐发现,每个魔法都是由两种基本元素构成的,A元素和B元素。
而每个魔法的魔力是合成这个魔法的A元素和B元素的大小的和。
例如一个大小为3的A元素和一个大小为6的B元素,能构成一个魔力为9的魔法。
现在卿学姐收集了N” role=”presentation” style=”position: relative;”>NN个B元素。
敏锐的卿学姐立刻发现他能组合出N∗N” role=”presentation” style=”position: relative;”>N∗NN∗N种魔法。
谦虚的卿学姐并不希望自己太跳,所以他准备将这N∗N” role=”presentation” style=”position: relative;”>N∗NN∗N种展示给天行廖检查。
现在卿学姐想知道,这N∗N” role=”presentation” style=”position: relative;”>N∗NN∗N种是什么。
当然,得从小到大输出哦~
Input
第一行一个整数N” role=”presentation” style=”position: relative;”>NN接下来一行有N” role=”presentation” style=”position: relative;”>NN个A元素
接下来一行有N” role=”presentation” style=”position: relative;”>NN个B元素
1≤N≤100000” role=”presentation” style=”position: relative;”>1≤N≤1000001≤N≤100000
1≤A[i],B[i]≤1000000000” role=”presentation” style=”position: relative;”>1≤A[i],B[i]≤10000000001≤A[i],B[i]≤1000000000
Output
输出N” role=”presentation” style=”position: relative;”>NN行,每行一个整数代表N∗N” role=”presentation” style=”position: relative;”>N∗NN∗N个
Sample input and output
Sample Input | Sample Output |
---|---|
5 1 3 2 4 5 6 3 4 1 7 | 2 3 4 4 5 |
Hint
Source
2016 UESTC Training for Data Structures首先暴力肯定会超时,所以要用到优先队列进行维护
#include <cstdio> #include <queue> #include <algorithm> using namespace std; #define N 100000+100 int arr , brr ,crr ; int main() { int n, k; priority_queue<int> fq; scanf("%d",&n); for(int i = 0;i < n; i++) scanf("%d",&arr[i]); for(int i = 0;i < n; i++) scanf("%d",&brr[i]); sort(arr,arr+n); sort(brr,brr+n); for(int i = 0;i < n; i++) fq.push(arr[0]+brr[i]); for(int i = 1;i < n; i++) { if(arr[i]+brr[0]>fq.top()) break; for(int j = 0;j < n; j++) { //这里wa了很多次,博主单纯的认为只要将arr[i]+brr[0]放入优先队列中 //但是要注意的时arr[i]+brr[1]虽然比arr[i]+brr[0]大,但是不一定比优先队列里面的数字大 if(fq.top() > arr[i]+brr[j]) { fq.pop(); fq.push(arr[i]+brr[i]); } else break; } } for(int i = n-1; i >= 0; i--) { crr[i] = fq.top(); fq.pop(); } for(int i = 0;i < n; i++) printf("%d\n",crr[i]); return 0; }
相关文章推荐
- CDOJ 1329 卿学姐与魔法(优先队列)
- uestc--1329 卿学姐与魔法(优先队列)
- 2016 UESTC Training for Data Structures D - 卿学姐与魔法 CDOJ 1329 堆
- 【CDOJ 1329】卿学姐与魔法
- UESTC 1329 卿学姐与魔法
- cdoj 1329 卿学姐与魔法 优先队列
- 【UESTC 1329 卿学姐与魔法】+ 优先队列
- 【cdoj 1349】卿学姐与魔法 (优先队列)
- UVA 12657/COJ 1329 HN第九届省赛 链表模拟
- UESTCoj - 1255- 斓少摘苹果 (贪心
- UESTCoj Grab a hole (二分+贪心)
- UESTCoj 1874 Wally World (计算几何)
- UESTCoj 265 War(Floyd最短路)
- 卿学姐与魔法(贪心模拟)
- 卿学姐与魔法 【优先队列】
- 2016 UESTC Training for Data Structures D - 卿学姐与魔法 优先队列、构造
- CDOJ1329 卿学姐与魔法
- UESTCoj- 149- 解救小Q (BFS
- (UESTCOJ 1004)8球胜负(eight)
- uestcoj 890 Card Trick(dp+逆推)