题目链接

Problem Description

Alice has an array a. The array has N positive numbers. She thinks the array is too long, so she wants to shorten the array. She decides to shorten the array via the following operation: every time she will choose an index i(1≤i<n)i (1≤i<n)i(1≤i<n) which ai>0ai>0ai>0 and ai+1>0a_i+1>0ai​+1>0. She will deleteaia_iai​ and ai+1a_i+1ai​+1 and use (ai(a_i(ai​ modmodmod ai+1)ai+1)ai+1) or (ai+1(ai+1(ai+1 modmodmod ai)a_i)ai​) to replace them.

For example, for array [3,2,4,5][3,2,4,5][3,2,4,5], if Alice choose i=2i=2i=2, she can change the array to [3,2,5][3,2,5][3,2,5] or [3,0,5][3,0,5][3,0,5]. Alice wants you to tell her the shortest possible length of the array after several options.

Input

The first line contains a single integer T(1≤T≤10)T (1≤T≤10)T(1≤T≤10), indicating the number of test cases.

For each test cases:

The first line contains one integer N(2≤N≤106)N (2≤N≤10^6)N(2≤N≤106), indicating the size of the array.

The next line containsNNN integers ai(ai≤109)a_i (a_i≤10^9)ai​(ai​≤109), representing the array.

Output

Output TTT lines.

The i−thi-thi−th line contains a single integer, representing the answer of i−thi-thi−th test case.

Sample Input

2
4
1 1 1 1
4
2 3 4 5

Sample Output

2
1

Hint

For the first sample, Alice first choose i=1i=1i=1 to change the array to [0,1,1][0, 1, 1][0,1,1], then choose i=2i=2i=2 to change the array to [0,0][0, 0][0,0], which is the best result she can reach.

解题思路:

取模运算有如下性质:
a%b=a(a<b)a\%b=a \ \ (a<b) a%b=a  (a<b)
Case1:对于样例2:23452\ 3\ 4\ 52 3 4 5

我们可以用最小的数222对其余数进行取模运算,即2%3,2%4,2%52\%3,2\%4,2\%52%3,2%4,2%5,最后数组元素只剩2,长度为1。

Case2:题目要求做运算的数必须大于0。对于样例1:11111\ 1\ 1\ 11 1 1 1
得到最终结果为000 \ 00 0,数组长度为2

可知,当数组中只存在相同的数时,数组长度为iii与i+1i+1i+1将得到同样的结果,都是(i+1)/2(i+1)/2(i+1)/2。

Case3:对于样例2223452\ 2\ 2\ 3\ 4\ 52 2 2 3 4 5
按如上做法将会得到答案为2(02)2\ (0\ 2)2 (0 2)。但若进行运算时可以得到比最小数(min=2)更小的数,如3%2=1,将此更小的数保存下来(而不是保存2%3=2),此时最小数将更新。于是如此处理后的数组将变为2212\ 2\ 12 2 1
最后可以将其他所有的数吞并,最终答案一定为1。

注意:第二次更新的最小数xxx需满足 (x>0&&x<min)(x>0 \&\&x<min)(x>0&&x<min),并且只能转换一个更小的数来达到目标。

AC代码:

#include<iostream>
#define int long long
using namespace std;
int a[1000005];
int t,n;
signed main()
{// ATTENTION %LLD FOR LONG LONG !!!scanf("%lld",&t);while(t--){int minn=1000000005;scanf("%lld",&n);for(int i=0;i<n;i++){scanf("%lld",&a[i]);if(minn>a[i])   minn=a[i];}int s=0,f=0;for(int i=0;i<n;i++){if((a[i]%minn>0&&a[i]%minn<minn))//判断运算后是否能生成更小的数//此处只需判断与minn的余数即可{f=1;break;}if(minn==a[i])  s++;}if(f==1)    printf("1\n");else printf("%lld\n",(s+1)/2);}return 0;
}

HDU 6917 Shorten the array相关推荐

  1. HDU 6917 Shorten the array(构造)

    题目地址 原题 Description Alice has an array a. The array has N positive numbers. She thinks the array is ...

  2. hdu 2441(ACM(Array Complicated Manipulation))

    打表规律猜想代码: #include<stdio.h> #include<string.h> const int N=100; int a[N]; bool p[N];int ...

  3. 【HDU 5532 Almost Sorted Array】水题,模拟

    给出一个序列(长度>=2),问去掉一个元素后是否能成为单调不降序列或单调不增序列. 对任一序列,先假设其可改造为单调不降序列,若成立则输出YES,不成立再假设其可改造为单调不增序列,若成立则输出 ...

  4. 区域赛铜牌专题(一)

    区域赛铜牌专题 题号 题目 知识点 HDU 5532 Almost Sorted Array 贪心,LIS HDU 5533 Dancing Stars on Me HDU 5536 Chip Fac ...

  5. 杭电OJ分类题目(2)

    原题出处:HDOJ Problem Index by Type,http://acm.hdu.edu.cn/typeclass.php 杭电OJ分类题目(2) HDU Water~~~ HDU 100 ...

  6. 安卓base64与其他语言base64算法还原出来差异问题???

    今天逆向某app时,发现了最后一步base64编码后后几位不一致. 之前有遇到空格及换行等问题,eg : 在在线工具生成对比后,确实后几位有出入. 回看了代码base64就是调用的标准算法,且也没更换 ...

  7. java实现数据AES加密

    1.AES加密 AES是美国国家标准技术研究所NIST旨在取代DES的21世纪的加密标准. AES是基于数据块的加密方式,也就是说,每次处理的数据是一块(16字节),当数据不是16字节的倍数时填充,这 ...

  8. 「团队训练赛」The 14th Jilin Provincial Collegiate Programming Contest「ABCEFGJLM」

    The 14th Jilin Provincial Collegiate Programming Contest A. Chord 题目描述: 给出C, C#, D, D#, E, F, F#, G, ...

  9. 一、java项目常用工具类之加密工具类

    项目环境: jdk1.8+spring4.3.12 一.问题描述及试用场景: 在项目规范中,有时需要对一些数据进行加密解密,常见的就是前后端加密参数在网络上传输.一方面,数据在网络上是以加密的方式传输 ...

最新文章

  1. SAP质量管理模块常见问题及解决方案
  2. threejs模型可视化编辑器_一个近乎无门槛、零基础的3D场景编辑器
  3. Adb connection Error:远程主机强迫关闭了一个现有的连接
  4. 字符缓冲流特有功能复制Java文件
  5. WebAPI(part11)--DOM重点核心
  6. php外联样式,css外联样式不起作用怎么办
  7. val什么意思vb中的属性值_老司机带你探索Mysql中int(1)、int(10)、int(11)的区别是什么?...
  8. collections模块的Counter类
  9. Deferred Shading,延迟渲染(提高渲染效率,减少多余光照计算)
  10. 网站策划:如何书写网站的商业计划书
  11. 对有些反编译不成功的apk,请更新最新的apktool.jar、 dex2jar试试
  12. 微信小程序API之getSystemInfo
  13. 测试工程师常见的算法面试题
  14. 绝妙一招 教你如何拍出烟雾缥缈的作品
  15. 【微软2017年预科生计划在线编程笔试第二场 B】Diligent Robots
  16. 淘宝开店之旅_我要充一充
  17. 让学前端不再害怕英语单词(四)
  18. 树结构——2-3树图解
  19. 2018年应届毕业宇视科技嵌入式软件开发工程师面试笔试总结
  20. 漫谈 MQ:要消息队列(MQ)有什么用?

热门文章

  1. vps赚钱的小项目,通过售卖流量赚钱
  2. 解决mei_me 0000:00:16.0:initialization failed.错误
  3. Android 如何判断 Wi-Fi 是 2.4G+5G 双频?
  4. 简约手绘竞聘通用PPT模板
  5. 微信关闭页面分享及其余功能
  6. 趣图:用户眼中的程序员 VS 程序员眼中的用户
  7. 【Android -- 动画】Activity 转场动画
  8. java接收的文件转换成临时文件,java实现酷狗音乐临时缓存文件转换为MP3文件的方法...
  9. Linux 管理联网 nmcli用法 新建动静连接
  10. 陇萃堂:CRM系统赋能业务人员以及渠道商,线上线下快速突破和拓展