今日份的摸鱼到账咯!我今日学习时间共8:40:00

可是。。。我一道题目没做出来。。。Orz

今天上午一直在尝试单词拼接,下午也一样,结果发现样例一直都过不了(???),可能是我思路错了,下午换了个思路重新写了一遍,发现还是错的(???)然后我就去看书了。


大话数据结构,真的很形象地讲述了数据结构的知识点,而且很有趣。目前我只看了个开头,还没有看到后面比较“高级”的内容。

感觉... ...脑子里塞下了好多东西,但是还没消化(。

为了避免这个总结太水,就分享一下我CF写的3题代码吧(我是真的菜)



Polycarp got an array of integers a[1…n]a[1…n] as a gift. Now he wants to perform a certain number of operations (possibly zero) so that all elements of the array become the same (that is, to become a1=a2=⋯=ana1=a2=⋯=an).

  • In one operation, he can take some indices in the array and increase the elements of the array at those indices by 11.

For example, let a=[4,2,1,6,2]a=[4,2,1,6,2]. He can perform the following operation: select indices 1, 2, and 4 and increase elements of the array in those indices by 11. As a result, in one operation, he can get a new state of the array a=[5,3,1,7,2]a=[5,3,1,7,2].

What is the minimum number of operations it can take so that all elements of the array become equal to each other (that is, to become a1=a2=⋯=ana1=a2=⋯=an)?

Input

The first line of the input contains a single integer tt (1≤t≤1041≤t≤104)  — the number of test cases in the test.

The following are descriptions of the input test cases.

The first line of the description of each test case contains one integer nn (1≤n≤501≤n≤50)  — the array aa.

The second line of the description of each test case contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤1091≤ai≤109)  — elements of the array aa.

Output

For each test case, print one integer  — the minimum number of operations to make all elements of the array aa equal.

Example

input

Copy

3
6
3 4 2 4 1 2
3
1000 1002 998
2
12 11

output

Copy

3
4
1

Note

First test case:

  • a=[3,4,2,4,1,2]a=[3,4,2,4,1,2] take a3,a5a3,a5 and perform an operation plus one on them, as a result we get a=[3,4,3,4,2,2]a=[3,4,3,4,2,2].
  • a=[3,4,3,4,2,2]a=[3,4,3,4,2,2] we take a1,a5,a6a1,a5,a6 and perform an operation on them plus one, as a result we get a=[4,4,3,4,3,3]a=[4,4,3,4,3,3].
  • a=[4,4,3,4,3,3]a=[4,4,3,4,3,3] we take a3,a5,a6a3,a5,a6 and perform an operation on them plus one, as a result we get a=[4,4,4,4,4,4]a=[4,4,4,4,4,4].

There are other sequences of 33 operations, after the application of which all elements become equal.

Second test case:

  • a=[1000,1002,998]a=[1000,1002,998] 2 times we take a1,a3a1,a3 and perform an operation plus one on them, as a result we get a=[1002,1002,1000]a=[1002,1002,1000].
  • a=[1002,1002,1000]a=[1002,1002,1000] also take a3a3 2 times and perform an operation plus one on it, as a result we get a=[1002,1002,1002]a=[1002,1002,1002].

Third test case:

  • a=[12,11]a=[12,11] take a2a2 and perform an operation plus one on it, as a result we get a=[12,12]a=[12,12].

这题,大胆地猜一猜,答案是不是就是一组数据里最大值和最小值的差值呢?

#include <bits/stdc++.h>using namespace std;typedef long long ll;int main()
{ios::sync_with_stdio(false);int T;cin >> T;for(int i = 0;i < T;i ++){int n;cin >> n;ll a[n + 1] = {0};ll min = 1e9 + 7;ll max = 0;for(int j = 0;j < n;j ++){cin >> a[j];if(a[j] > max) max = a[j];if(a[j] < min) min = a[j];}cout << max - min << endl;}return 0;
}

然后它就AC了,嗯。


Polycarp has 33 positive integers aa, bb and cc. He can perform the following operation exactly once.

  • Choose a positive integer mm and multiply exactly one of the integers aa, bb or cc by mm.

Can Polycarp make it so that after performing the operation, the sequence of three numbers aa, bb, cc (in this order) forms an arithmetic progression? Note that you cannot change the order of aa, bb and cc.

Formally, a sequence x1,x2,…,xnx1,x2,…,xn is called an arithmetic progression (AP) if there exists a number dd (called "common difference") such that xi+1=xi+dxi+1=xi+d for all ii from 11 to n−1n−1. In this problem, n=3n=3.

For example, the following sequences are AP: [5,10,15][5,10,15], [3,2,1][3,2,1], [1,1,1][1,1,1], and [13,10,7][13,10,7]. The following sequences are not AP: [1,2,4][1,2,4], [0,1,0][0,1,0] and [1,3,2][1,3,2].

You need to answer tt independent test cases.

Input

The first line contains the number tt (1≤t≤1041≤t≤104) — the number of test cases.

Each of the following tt lines contains 33 integers aa, bb, cc (1≤a,b,c≤1081≤a,b,c≤108).

Output

For each test case print "YES" (without quotes) if Polycarp can choose a positive integer mm and multiply exactly one of the integers aa, bb or cc by mm to make [a,b,c][a,b,c] be an arithmetic progression. Print "NO" (without quotes) otherwise.

You can print YES and NO in any (upper or lower) case (for example, the strings yEs, yes, Yes and YES will be recognized as a positive answer).

Example

input

Copy

11
10 5 30
30 5 10
1 2 3
1 6 3
2 6 3
1 1 1
1 1 2
1 1 3
1 100000000 1
2 1 1
1 2 2

output

Copy

YES
YES
YES
YES
NO
YES
NO
YES
YES
NO
YES

Note

In the first and second test cases, you can choose the number m=4m=4 and multiply the second number (b=5b=5) by 44.

In the first test case the resulting sequence will be [10,20,30][10,20,30]. This is an AP with a difference d=10d=10.

In the second test case the resulting sequence will be [30,20,10][30,20,10]. This is an AP with a difference d=−10d=−10.

In the third test case, you can choose m=1m=1 and multiply any number by 11. The resulting sequence will be [1,2,3][1,2,3]. This is an AP with a difference d=1d=1.

In the fourth test case, you can choose m=9m=9 and multiply the first number (a=1a=1) by 99. The resulting sequence will be [9,6,3][9,6,3]. This is an AP with a difference d=−3d=−3.

In the fifth test case, it is impossible to make an AP.

这道题,就是看能不能通过乘数制造一个只有三个元素的等差数列。因为是只有3个元素嘛,把各种情况列出来,我们就可以得到2个不同的公差,然后各种情况枚举一下就可以得出答案了。

#include <bits/stdc++.h>using namespace std;typedef long long ll;bool check(ll *a);int main()
{ios::sync_with_stdio(false);int T;cin >> T;ll a[3] = {0};for(int i = 0;i < T;i ++){for(int j = 0;j < 3;j ++){cin >> a[j];}bool c = check(a);if(c) cout << "YES" << endl;else cout << "NO" << endl;}return 0;
}bool check(ll *a)
{ll a1 = *a;ll a2 = *(a + 1);ll a3 = *(a + 2);ll pre = 0;ll d = 0;if(a3 - a2 == a2 - a1){return true;}d = a3 - a2;pre = a2 - d;if(pre > 0 && pre % a1 == 0){
//      cout << "a1: " << pre << endl;return true;  } d = a2 - a1;pre = a2 + d;if(pre > 0 && pre % a3 == 0){
//      cout << "a3: " << pre << endl;return true;  }
//  if(1.0 * (a3 - a1) / 2 != (a3 - a1) / 2) return false;d = (a3 - a1) / 2;pre = a1 + d;if(pre > 0 && pre % a2 == 0 && pre - a1 == a3 - pre){
//      cout << "a2: " << pre << endl;return true;  } return false;
}

好了,这题就AC了。


You are given an array aa consisting of nn positive integers. You can perform operations on it.

In one operation you can replace any element of the array aiai with ⌊ai2⌋⌊ai2⌋, that is, by an integer part of dividing aiai by 22 (rounding down).

See if you can apply the operation some number of times (possible 00) to make the array aa become a permutation of numbers from 11 to nn —that is, so that it contains all numbers from 11 to nn, each exactly once.

For example, if a=[1,8,25,2]a=[1,8,25,2], n=4n=4, then the answer is yes. You could do the following:

  1. Replace 88 with ⌊82⌋=4⌊82⌋=4, then a=[1,4,25,2]a=[1,4,25,2].
  2. Replace 2525 with ⌊252⌋=12⌊252⌋=12, then a=[1,4,12,2]a=[1,4,12,2].
  3. Replace 1212 with ⌊122⌋=6⌊122⌋=6, then a=[1,4,6,2]a=[1,4,6,2].
  4. Replace 66 with ⌊62⌋=3⌊62⌋=3, then a=[1,4,3,2]a=[1,4,3,2].

Input

The first line of input data contains an integer tt (1≤t≤1041≤t≤104) —the number of test cases.

Each test case contains exactly two lines. The first one contains an integer nn (1≤n≤501≤n≤50), the second one contains integers a1,a2,…,ana1,a2,…,an (1≤ai≤1091≤ai≤109).

Output

For each test case, output on a separate line:

  • YES if you can make the array aa become a permutation of numbers from 11 to nn,
  • NO otherwise.

You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as a positive response).

Example

input

Copy

6
4
1 8 25 2
2
1 1
9
9 8 3 4 2 7 1 5 6
3
8 2 1
4
24 7 16 7
5
22 6 22 4 22

output

Copy

YES
NO
YES
NO
NO
YES

Note

The first test case is explained in the text of the problem statement.

In the second test case, it is not possible to get a permutation.

这题,就是不停地把元素除以二得到它的整数部分,直到它是1~n的值,即1<=x<=n。那么我们只要把拥有的数值给标记出来,下一个数除到1~n之间时如果重复即再除以二,直到为0或等于下一个“缺席”的1~n的值。遍历完数组元素后,我们就得到了一个1~n的"在位"列表,如果都在位,那么是可以实现答案的,输出"YES",如果有"缺席"的,那么就意味着不能实现,输出"NO",下面放上AC代码(其实这题我做了很久很久)

#include <bits/stdc++.h>using namespace std;typedef long long ll;int main()
{ios::sync_with_stdio(false);int T;cin >> T;for(int i = 0;i < T;i ++){int n;cin >> n;
//      ll L = 0;
//      ll R = 1e9 + 7;ll a[n + 1] = {0};int have[n + 1] = {0};bool can = true;for(int j = 0;j < n;j ++){int pos = 0;cin >> a[j];
//          if(a[j] > L) L = a[j];
//          if(a[j] < R) R = a[j];ll tmp = a[j];while(1){if(tmp == 0){can = false;break;    } if(tmp <= n && !have[tmp]){have[tmp] = 1;break;}tmp /= 2;}}for(int i = 1;i <= n;i ++){if(!have[i]){can = false;break;}}if(can){cout << "YES" << endl;}else{cout << "NO" << endl;}}return 0;
}

明天休息,好诶!可以抽空看看书啦! :D

2022/1/14总结相关推荐

  1. 3934:C 10 Aug 2022 00:14:04.239 # Fatal error, can‘t open config file ‘/usr/local/redis/./redis-conf

    报错:3934:C 10 Aug 2022 00:14:04.239 # Fatal error, can't open config file '/usr/local/redis/./redis-c ...

  2. English Learning - Day8 作业打卡 2022.12.14 周三

    English Learning - Day8 作业打卡 2022.12.14 周三 引言 1. 学习让我感觉很棒.(什么关系?动作 or 描述?主语部分是?) 2. 她忽然想起来钥匙放另一个包里了. ...

  3. TS:解决win10的wsl2下Ubuntu系统里中文乱码问题(已解决)-2022.3.14

    TS:解决win10的wsl2下Ubuntu系统里中文乱码问题(已解决)-2022.3.14 目录 文章目录 TS:解决win10的wsl2下Ubuntu系统里中文乱码问题(已解决)-2022.3.1 ...

  4. 2022.3.14密码学基础题【网络攻防CTF】(保姆级图文)

    目录 解码软件工具下载(2022.5.13) 1. 埃特巴什密码 `flaghahactfisnice` 2. 疑惑的汉字,当铺密码 `CTF{RM}` 3. 莫斯密码 flag 4. 培根密码 fl ...

  5. java发布WCS服务到GeoServer服务器并解析XML生成可下载的WCS服务数据url(2022.2.14)

    GeoServer上的WCS服务发布调用及解析生成可下载为Tif的WCSUrl 2022.2.14 所用软件环境(Java.Tomcat.GeoServer.Google Browser.Eclips ...

  6. 递推法与递归法2022.3.14

    递推法与递归法2022.3.14 递推法是用于数值求解的一个重要算法. 存储型的递归和递推: 存储就加个数组就好了吧. 三角形递推,先赋好值然后从后往前递推.甚至都不需要额外的空间,最后返回a[1][ ...

  7. 【数字IC前端笔试真题精刷(2022.8.14)】大疆——数字芯片开发工程师B卷

    声明:本专栏所收集的数字IC笔试题目均来源于互联网,仅供学习交流使用.如有侵犯您的知识产权,请及时与博主联系,博主将会立即删除相关内容. 笔试时间:2022年8月14日 19:00 题目类型: 单选题 ...

  8. 2023考研资料每日更新(2022.04.14)

    2023考研全程班-同步更新 弓****Z*****耗:[考场青年]直接获取 2023考研公共课 4月14日更新进度如下: [03] [2023考研英语] 何凯文培优班 起跑导学 1575逐词过关 第 ...

  9. 洛谷 深基 第1部分 语言入门 第4章 循环结构程序设计(2022.02.14)

    P5718 [深基4.例2]找最小值 [深基4.例2]找最小值 - 洛谷 P5718 [深基4.例2]找最小值(python3实现)-2022.02.01 P5718 [深基4.例2]找最小值(pyt ...

  10. 棕榈油跌停见顶,铁矿石认沽上涨,YP05惊天大反弹2022.3.14

    本篇内容包括6个部分: 01.今日商品跟踪表:主要跟踪当前52个交易活跃的品种,对当日的品种涨跌幅.增减仓.板块指数的涨跌幅和增减仓进行排序: 02.宏观窥探:主要是对国内外股市.资本市场主要宏观指标 ...

最新文章

  1. Spring 5.0 源码编译, 403, 404 依赖pom 无法下载问题
  2. SpringBatch 多线程(TaskExecutor)启动Job详解 (七)
  3. hdu4533 威威猫系列故事——晒被子
  4. 在windows下codeblocks中配置pthread库
  5. 可爱的python测试开发库及项目(python测试开发工具库汇总)
  6. java 反射 单例类_利用反射机制破坏单例模式
  7. trados 2007 2009 共用一个LICENSE服务器
  8. js语音播报android浏览器,JS 简单调用百度TTS接口实现语音朗读
  9. python windows api截图_Winapi快速截图并打开
  10. 安装mysql详细教程(windows 10安装mysql详细教程新手必看)
  11. 「倍轻松」要上科创板,按摩器为什么总要和科技沾点边?
  12. Python Flask学习_使用flask-login实现认证蓝本(一)
  13. Word 宏命令大全
  14. QtCreator生成标准多行函数或者类详细注释
  15. 金融跨计算机考研,计算机跨金融——我的二战考研复习计划给你们
  16. STM32CubeMX生成工程失败
  17. 属于你的舞台——安卓优化大师UI设计
  18. 边缘检测 从Roberts到Canny算子
  19. movielens推荐_电影推荐系统movielens grouplens
  20. 贵阳副市长刚写了一本区块链的书,趁热乎推荐给你!

热门文章

  1. Buu-crypto-write up
  2. 飞船撞击到外星人后,返回不了底部中央,只能手动设置参数,明天好好研究一下
  3. [源码和文档分享]基于Android Studio实现的学生蹭课APP
  4. P3709 大爷的字符串题【普通莫队】
  5. SCLS | 朱永官院士等-噬菌体技术阻抑抗生素耐药风险流行(视频)
  6. 3dmark android 中文,Android版3DMark现在登场
  7. java调接口实现发送手机短信验证码功能,手机验证码,接口调用
  8. 机器学习实验—K-MEANS聚类
  9. Python入门(二十二)- 常见模块2(正则表达式及容器)
  10. 使用pe安装系统windows系统