Doraemon and Nobita are playing a number game. First, Doraemon will give Nobita Npositive numbers. Then Nobita can deal with these numbers for two rounds. Every time Nobita can delete i (2 ≤ i ≤ K) numbers from the number set. Assume that the numbers deleted is a[ 1 ], a[ 2 ] ... a[ i ]. There should be a new number X = ( a[ 1 ] * a[ 2 ] * ... * a[ i ] + 1 ) to be inserted back into the number set. The operation will be applied to the number set over and over until there remains only one number in the set. The number is the result of round. Assume two results A and Bare produced after two rounds. Nobita can get |A - B| scores.

Now Nobita wants to get the highest score. Please help him.

Input

Input will contain no more than 10 cases. The first line of each case contains two positive integers N and K (1 ≤ N ≤ 100, 1 ≤ K ≤ 50). The following line contains N positive integers no larger than 50, indicating the numbers given by Doraemon.

<h4< dd="">

Output

For each case, you should output highest score in one line.

<h4< dd="">

Sample Input

6 3
1 3 4 10 7 15

<h4< dd="">

Sample Output

5563

<h4< dd="">

Hint

For most cases, N ≤ 20

题解:

题意:

给n个数,有两轮操作,每轮操作你可以选择大于2小于k个数字进行题目说的运算,让你求两轮差值最大为多少

思路:

每次取k个最大的数字合并为最小的值

每次取2个最小的数字合并为最大值

比赛的时候思路和题解思路一模一样。。比赛的时候wa了,也考虑过longlong会炸的情况,但是高精度写起来太麻烦了,所以就放弃了,刚刚搜了个高精度模板。。。卧槽还有这种操作,加上高精度模板这题瞬间就ac了。。感觉捡到一个宝hhhhh

代码:

#include<algorithm>
#include<iostream>
#include<cstring>
#include<stdio.h>
#include<math.h>
#include<string>
#include<stdio.h>
#include<queue>
#include<stack>
#include<map>
#include<deque>
#define M (t[k].l+t[k].r)/2
#define lson k*2
#define rson k*2+1
#define ll long long
#define INF 100861111;
using namespace std;
class bigInt//大数运算模板
{
public:int num[302],len;bigInt() {num[0]=0,len=0;}bigInt operator=(const int &a){int tmp=a;len=0;while(tmp)num[len++]=tmp%10,tmp/=10;if (!len)num[0]=0,len=1;}bigInt(const int &a){int tmp=a;len=0;while(tmp)num[len++]=tmp%10,tmp/=10;if (!len)num[0]=0,len= 1;}friend bool operator<(const bigInt &b,const bigInt &a){if (a.len!=b.len)return b.len<a.len;for (int i=b.len-1;i>=0;i--)if (b.num[i]!=a.num[i])return b.num[i]<a.num[i];return false;}friend bool operator>(const bigInt & b,const bigInt &a){if (a.len!=b.len)return b.len>a.len;for (int i=b.len-1;i>=0;i--)if (b.num[i]!=a.num[i])return b.num[i]>a.num[i];return false;}bigInt operator+(const bigInt &a){bigInt res;int i,j,c =0,adda,addb;for (i=0,j=0;i<len||j<a.len||c;){adda=0,addb=0;if(i <len)adda= num[i++];if(j< a.len)addb=a.num[j++];res.num[res.len++]=(adda+addb+c)%10;c=(adda+addb+c)/10;}return res;}bigInt operator-(const bigInt &b){bigInt res;int i,j,c=0,suba,subb;for(i=0,j=0;i<len||j<b.len||c;){suba=0,subb=0;if(i<len)suba=num[i++];if(j<b.len)subb=b.num[j++];res.num[res.len++] =(suba-subb+c+10)%10;c=(suba-subb+c+10)/10-1;}for(i=res.len-1;i>0;i--)if (res.num[i])break;res.len=i+1;return res;}bigInt operator*(const bigInt &b){bigInt res;int i,j,c,now,mulb,tmp;memset(res.num,0,sizeof(int)*(len+b.len));for(i=0;i<len;i++){now=i,c=0;for(j=0;j<b.len||c;){mulb=0;if (j<b.len)mulb=b.num[j++];tmp=res.num[now]+num[i]*mulb+c;res.num[now++]=tmp % 10;c=tmp/10;}}for(i=len+b.len-1;i>0;i--)if (res.num[i]) break;res.len = i + 1;return res;}void display(){int i;for (i=len-1;i>1;i--)if (num[i])break;for (;i>=0;i--)printf("%d",num[i]);printf("\n");}
};
priority_queue<bigInt,vector<bigInt>,less<bigInt> >q1;//最大堆
priority_queue<bigInt,vector<bigInt>,greater<bigInt> >q2;//最小堆
int main()
{int i,j,n,k,x;while(scanf("%d%d",&n,&k)!=EOF){while(!q1.empty())q1.pop();while(!q2.empty())q2.pop();for(i=0;i<n;i++){scanf("%d",&x);bigInt t=x;q1.push(t);q2.push(t);}while(q1.size()>1)//最小值情况{if(q1.size()>=k){bigInt t=1;for(i=0;i<k;i++){t=t*q1.top();q1.pop();}t=t+1;q1.push(t);}else{bigInt t=1;while(!q1.empty()){t=t*q1.top();q1.pop();}t=t+1;q1.push(t);break;}}while(q2.size()>1)//最大值情况{bigInt t=1;for(i=0;i<2;i++){t=t*q2.top();q2.pop();}t=t+1;q2.push(t);}bigInt t1=q2.top();bigInt t2=q1.top();bigInt temp=t1-t2;//差temp.display();}return 0;
}

ZOJ 3447 Doraemon's Number Game(优先队列+高精度运算)相关推荐

  1. ZOJ 3449 Doraemon's Number Game III

    ZOJ   3449   Doraemon's Number Game III    题目链接 组队赛的一个题,只能说自己太菜,完全不知道有数根这个东西... 题意:   把一个十进制的数,写成按b进 ...

  2. POJ - 1220 NUMBER BASE CONVERSION(高精度运算+进制转换+模拟)

    题目链接:点击查看 题目大意:给出两个进制x和y,再给出一个x进制下的数num,求num转换为y进制后的答案 题目分析:直接套模板就行了,进制转换没什么好说的,直接模拟,这个题开了加速外挂只能优化几十 ...

  3. c语言用数组存储高精度数,高精度运算c语言.pptx

    <高精度运算c语言.pptx>由会员分享,可在线阅读,更多相关<高精度运算c语言.pptx(20页珍藏版)>请在人人文库网上搜索. 1.高精度运算,运算的前提条件:类型范围,确 ...

  4. 关于__int128高精度运算

    参考文章 使用__int128可以实现高精度运算,但是这种大整数无法使用函数printf输出结果,所以需要手写输出 #include <bits/stdc++.h> using names ...

  5. float php 运算_系统的讲解 - PHP 浮点数高精度运算

    概述 记录下,工作中遇到的坑 ... 关于 PHP 浮点数运算,特别是金融行业.电子商务订单管理.数据报表等相关业务,利用浮点数进行加减乘除时,稍不留神运算结果就会出现偏差,轻则损失几十万,重则会有信 ...

  6. CCF NOI1089 高精度运算

    问题链接:CCF NOI1089 高精度运算. 时间限制: 1000 ms  空间限制: 262144 KB 题目描述 输入N对位数不超过1000的正整数,求它们的和.   (编程使用strunc创建 ...

  7. 2022/2/3 四舍五入 分数化简 高精度运算

    电费分段收费 1.四舍五入 b=int((b*10)+0.5)/10.0;//四舍五入到小数点后一位 2.分段的一个方法 for(i=1;i<=150;i++)cost[i]=0.4463;fo ...

  8. 大数运算(高精度运算)

    高精度运算 1.高精度加法 给定两个正整数,计算它们的和. 输入格式 共两行,每行包含一个整数. 输出格式 共一行,包含所求的和. 数据范围 1≤整数长度≤100000 输入样例: 12 23 输出样 ...

  9. java中小数的处理:高精度运算用bigDecimal类,精度保留方法,即舍入方式的指定

    java中小数的处理:高精度运算用bigDecimal类,精度保留方法,即舍入方式的指定 2016年05月11日 11:20:08 阅读数:6336 一. 计算机的小数计算一定范围内精确,超过范围只能 ...

最新文章

  1. 从FCKEDITOR到ckeditor(二) 撰写自定义对话框,增加数学公式(与webEq的结合)
  2. Nginx反向代理缓冲区优化
  3. codevs1520 回文字符串
  4. 解密迈向量产的百度Apollo自动驾驶技术与产品
  5. c++别让异常逃离析构函数
  6. MyBatis源码分析-2-基础支持层-反射模块-TypeParameterResolver/ObjectFactory
  7. 单图说TDSQL;OceanBase 2.2 事务引擎核心功能;穿云箭2.0版发布;RMAN DUPLICATE配置19C DG;外键上有无索引的影响;MySQL8.0 索引新功能;GaussDB C
  8. 5G商用正式启动:最全套餐资费详情都在这里了
  9. 哈希码以及Object.toString()简单理解
  10. unity 陀螺仪控制节点旋转
  11. Android版日语学习应用的逆向分析
  12. NullableTypes for .NET
  13. (苹果Mac OSX系统)绿联USB无法连接网络解决方案
  14. 微信公众号:提示“redirect_uri 参数错误”
  15. HTK中Vocab字典的结构
  16. Vue项目中实现改变屏幕尺寸重新刷新页面-计算页面尺寸
  17. 计算机术语中的letters表示,letter是什么意思_letter在线翻译_英语_读音_用法_例句_海词词典...
  18. html5 调用系统相册,iOS之H5调用系统相册相机浏览文件
  19. 如何将网址放到桌面并修改桌面快捷方式的图标
  20. 通信研究生适合发表的优质期刊(中文)

热门文章

  1. 天子呼来不上船,自称臣是酒中仙——我的嗜酒情节
  2. 华为鸿蒙如何内测,华为鸿蒙内测体验曝光,与EMUI有明显区别
  3. 18 打印日期 华科复试
  4. 做领导要会说话!高情商的18个说话技巧,受益无穷!
  5. 多项目同时进行,如何做好项目管理?
  6. 互联网人如何拓展自己的人脉
  7. Python——创建二维列表的简易方法
  8. airpods pro动画不显示_今天教大家如何重新设置苹果AirPods Pro
  9. Java开发环境的搭建—Java JDK的下载与安装!
  10. 欧盟玩具标准EN71-3更新至2019版