九度oj 题目1178:复数集合
来源:互联网 发布:淘宝打假人查询 编辑:程序博客网 时间:2024/06/08 10:41
链接
http://ac.jobdu.com/problem.php?pid=1178
- 题目描述:
一个复数(x+iy)集合,两种操作作用在该集合上:
1、Pop 表示读出集合中复数模值最大的那个复数,如集合为空 输出 empty ,不为空就输出最大的那个复数并且从集合中删除那个复数,再输出集合的大小SIZE;
2 Insert a+ib 指令(a,b表示实部和虚部),将a+ib加入到集合中 ,输出集合的大小SIZE;
最开始要读入一个int n,表示接下来的n行每一行都是一条命令。
- 输入:
输入有多组数据。
每组输入一个n(1<=n<=1000),然后再输入n条指令。
- 输出:
根据指令输出结果。
- 样例输入:
3PopInsert 1+i2Pop
- 样例输出:
emptySIZE = 11+i2SIZE = 0
- 提示:
模相等的输出b较小的复数。
a和b都是非负数。
用优先队列,特别要注意的一点是当完成一组操作后,要将优先队列中的所有元素弹出,再开始下一组操作!!!
ac代码
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <string.h>
#include <algorithm>
#include <math.h>
#include <queue>
#include <stack>
#include <map>
#define INF 2<<20
#define BASE 1000
using namespace std;
struct node
{
int a;
int b;
};
struct cmp
{
bool operator()(const node &a,const node &b)
{
if(a.a*a.a+a.b*a.b!=b.a*b.a+b.b*b.b)
return a.a*a.a+a.b*a.b<b.a*b.a+b.b*b.b;
else
return a.b>b.b;
}
};
int main ()
{
priority_queue<node,vector<node>,cmp >q;
int n;
string s1;
while(cin >> n)
{
for(int i=0;i<n;i++)
{
cin >> s1;
if(s1[0]=='P')
{
if(q.empty())
printf("empty\n");
else
{
printf("%d+i%d\n",q.top().a,q.top().b);
q.pop();
printf("SIZE = %d\n",q.size());
}
}
else if(s1[0]=='I')
{
int a,b;
scanf("%d+i%d",&a,&b);
node temp;
temp.a = a;
temp.b = b;
q.push(temp);
printf("SIZE = %d\n",q.size());
}
}
while(!q.empty())
q.pop();
}
return 0;
}
- 九度OJ题目1178:复数集合
- 九度oj 题目1178:复数集合
- 【九度OJ】题目1178:复数集合 解题报告
- 九度OJ 1178:复数集合 (插入排序)
- 九度题目1178 复数集合 北邮网研2011机试
- 题目1178:复数集合
- 题目1178:复数集合
- 题目1178:复数集合
- 题目1178:复数集合
- 题目1178:复数集合
- 题目1178:复数集合
- 题目1178:复数集合
- 题目1178:复数集合
- 九度OJ 题目1029
- 九度OJ 题目1018
- 九度OJ 题目1002
- 九度OJ 题目1058:反序输出
- 九度OJ 题目1062:分段函数
- Linux下批量Kill多个进程
- 优先队列priority_queue 用法详解
- HDU 3641 Treasure Hunting(阶乘素因子分解+二分)
- 【C++】栈空栈满异常处理
- [Leetcode]-Balanced Binary Tree
- 九度oj 题目1178:复数集合
- Linux 下PL2302 USB转串口的使用
- 列表页点击加载更多,无刷新加载更多文章的方法(yii)
- 【剑指Offer学习】【面试题38:数字在排序数组中出现的次数】
- 【问题】java.lang.NoClassDefFoundError
- VS2008切换环境(c#,c++,other)
- MAVEN常用命令学习与常见问题
- Js获取当前日期时间及其它操作
- git tips