A.

给定一个序列,对于任意1<=k<=n 都满足|ai−ak|+|ak−aj|=|ai−aj|,

找满足条件的i和j并输出

思路:

观察样例,发现输出的是最大值和最小值,那么猜答案是最大值和最小值,进行证明

若答案不是最大值和最小值,则一定存在一个k使得|ak-ap|大于|aj-ai| 一定不满足|ai−ak|+|ak−aj|=|ai−aj| 与命题矛盾

所以记录最大值和最小值 输出即可。

代码:

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define x first
  4. #define y second
  5. #define endl '\n'
  6. #define int long long
  7. #define debug(x) cout << "*" << x << endl;
  8. const int P = 13131;
  9. #define ll long long
  10. const int mod = 1E6 + 7;
  11. const int INF = 0x3f, sINF = 0x3f3f3f3f;
  12. typedef unsigned long long ULL;
  13. typedef pair<int, int> PII;
  14. typedef pair<long long, long long> PLL;
  15. int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
  16. const int N = 3e5 + 10;;
  17. int T;
  18. const int UN = 1e9 + 10;
  19.  
  20. signed main()
  21. {
  22. cin>>T;
  23. while(T--)
  24. {
  25. int n;
  26. int maxa = 0, mina = UN;
  27. cin>>n;
  28. int ans1, ans2;
  29. for(int i = 1; i <= n; i++)
  30. {
  31. int temp;
  32. cin>>temp;
  33.  
  34. if(temp > maxa)
  35. {
  36. ans1 = i;
  37. maxa = temp;
  38. }
  39.  
  40. if(temp < mina)
  41. {
  42. ans2 = i;
  43. mina = temp;
  44. }
  45. }
  46. if(n == 1) cout<<"1 1"<<endl;
  47. else cout<<ans2<<" "<<ans1<<endl;
  48.  
  49. }
  50. }

B

给定一个序列,每次去除任意一个元素,并且将其他剩余元素都减去这个元素的值,给定一个k,能否让最后剩下的那个数为k

思路:

推公式,模拟一下a1,a2 和 a1,a2,a3情况,并且以总和的角度来看,发现所有的答案都只与两个元素之间的差的绝对值有关

a1,a2,a3情况: 总和为a1+a2+a3

假如去除的是a2 那么总和就为(a1 - a2) + (a3 - a2),剩两个元素的时候求得就是他俩的差的绝对值了,那么就是|a1 - a2 - a3 + a2| = |a1 - a3|

去除的是其他同理,发现多个元素的时候都可以消成这种形式。那么答案就是在任意两个元素的差的绝对值之中,哈希表判断是否存在即可。

代码:

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define x first
  4. #define y second
  5. #define endl '\n'
  6. #define int long long
  7. #define debug(x) cout << "*" << x << endl;
  8. const int P = 13131;
  9. #define ll long long
  10. const int mod = 1E6 + 7;
  11. const int INF = 0x3f, sINF = 0x3f3f3f3f;
  12. typedef unsigned long long ULL;
  13. typedef pair<int, int> PII;
  14. typedef pair<long long, long long> PLL;
  15. int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
  16. const int N = 2e5 + 10;;
  17. int T;
  18. const int UN = 1e9 + 10;
  19. int q[N];
  20.  
  21. signed main()
  22. {
  23. cin>>T;
  24. while(T--)
  25. {
  26. map<int, bool> s;
  27. int n, k;
  28. cin>>n>>k;
  29. for(int i = 0; i < n; i++)
  30. {
  31. cin>>q[i];
  32. s[q[i]] = true; //出现过这个
  33. }
  34.  
  35. bool isk = false;
  36. for(int i = 0; i < n; i++)
  37. if(s[q[i] - k] || s[q[i] + k])
  38. {
  39. isk = true;
  40. break;
  41. }
  42.  
  43. if(isk) puts("YES");
  44. else puts("NO");
  45. }
  46. }

 

C

给定一个序列,可以选择任意k>=2 对里面所有元素模k 有没有可能让所有元素相等。

思路:仔细想想即可发现,只要从大到小模,一定可以把所有元素模为0或者1,那么问题仅存在于0,1之间。

1怎么也到不了0 ,所以一旦0,1都出现,就一定NO。如果没0,只有1,那所有元素必须化为1,但对于p %= p-1,如果存在另一个p-1的元素,那么一定会出现0

所以此时不能存在差值为1的元素对。

其他所有情况都输出YES,只要按照从大到小模

代码:

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define x first
  4. #define y second
  5. #define endl '\n'
  6. #define int long long
  7. #define debug(x) cout << "*" << x << endl;
  8. const int P = 13131;
  9. #define ll long long
  10. const int mod = 1E6 + 7;
  11. const int INF = 0x3f, sINF = 0x3f3f3f3f;
  12. typedef unsigned long long ULL;
  13. typedef pair<int, int> PII;
  14. typedef pair<long long, long long> PLL;
  15. int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
  16. const int N = 1e5 + 10;;
  17. int T;
  18. const int UN = 1e9 + 10;
  19. int q[N];
  20.  
  21. signed main()
  22. {
  23. cin>>T;
  24. while(T--)
  25. {
  26. int n;
  27. cin>>n;
  28. for(int i = 0; i < n; i++) cin>>q[i];
  29. sort(q, q + n);
  30. bool find0 = false, find1 = false;
  31. int p = 0;
  32. while(q[p] <= 1 && p < n)
  33. {
  34. if(q[p] == 0) find0 = true;
  35. if(q[p] == 1) find1 = true;
  36. p++;
  37. }
  38.  
  39. if(find0 && find1)
  40. {
  41. puts("NO");
  42. continue;
  43. }
  44.  
  45. if(!find0 && find1)
  46. {
  47. bool flag = false;
  48. for(int i = 0; i < n - 1; i++)
  49. if(q[i + 1] - q[i] == 1)
  50. {
  51. flag = true;
  52. break;
  53. }
  54. if(!flag) puts("YES");
  55. else puts("NO");
  56.  
  57. continue;
  58. }
  59.  
  60. puts("YES");
  61.  
  62. }
  63. }

D

给定一个数,如果这个数可以被k个能够被模k后互不相等的数相加而得到,那么这个数称为k-good数,对于这个n,输出任意一个k即可,没有则为-1

思路:(可以先打表找规律

条件转化一下,很容易就能得到条件是 (n - sum(0, 1, ..., k - 1)) % k == 0;

然后观察奇数,发现2-good可以作用于任意奇数,所以奇数全部输出2

根据上述条件来判断偶数,(n - (k - 1) * k / 2 <求和公式>) % k == 0

如果k是n的因子,并且求和项为整数且小于n,那么一定能输出,观察(k - 1) * k / 2项,发现k要么是奇数,要么是2,这两种情况能让这项为整。

又因为枚举的是偶数,所以我们只需要找到2^p * 最大奇因子 = n即可

2^p * 最大奇因子 = n

先判断临界情况 前两者相等时,一定有n - 求和 = 0,此时n = 2^(2*p) 一定不能输出,此时输出-1,(意思是,n是2^a就输出-1就行)

其他情况,一定一个大于sqrt(n), 一个小于sqrt(n), 小于的数的(n - (k - 1) * k / 2 <求和公式>)一定为正,大于的一定为负

那么输出两者的最小值就行。

代码:

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define x first
  4. #define y second
  5. #define endl '\n'
  6. #define int long long
  7. #define debug(x) cout << "*" << x << endl;
  8. const int P = 13131;
  9. #define ll long long
  10. const int mod = 1E6 + 7;
  11. const int INF = 0x3f, sINF = 0x3f3f3f3f;
  12. typedef unsigned long long ULL;
  13. typedef pair<int, int> PII;
  14. typedef pair<long long, long long> PLL;
  15. int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
  16. const int N = 1e5 + 10;;
  17. int T;
  18. const int UN = 1e9 + 10;
  19. int q[N];
  20.  
  21. signed main()
  22. {
  23. cin>>T;
  24. while(T--)
  25. {
  26. ll n;
  27. cin>>n;
  28. ll rem = n;
  29. if(n % 2 == 1) cout<<"2"<<endl;
  30. else {
  31. ll k = 1;
  32. while(n % 2 == 0)
  33. {
  34. n /= 2;
  35. k *= 2;
  36. }
  37. if(n == 1) cout<<"-1"<<endl;
  38. else
  39. { //此时剩下个奇数
  40. k *= 2;
  41. cout<<min(k, n)<<endl;
  42.  
  43. }
  44. }
  45.  
  46. }
  47. }

CodeTON Round 1 (Div. 1 + Div. 2, Rated, Prizes!) A ~ D的更多相关文章

  1. Codeforces 1023 A.Single Wildcard Pattern Matching-匹配字符 (Codeforces Round #504 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Fi)

    Codeforces Round #504 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Final) A. Single Wildcard Patter ...

  2. CF Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined)

    1. Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) B. Batch Sort    暴力枚举,水 1.题意:n*m的数组, ...

  3. Codeforces Beta Round #27 (Codeforces format, Div. 2)

    Codeforces Beta Round #27 (Codeforces format, Div. 2) http://codeforces.com/contest/27 A #include< ...

  4. Codeforces Round #438 (Div.1+Div.2) 总结

    本来兴致勃勃的想乘着这一次上紫,于是很早很早的到了机房 但是好像并没有什么用,反而rating-=47 Codeforces Round #438(Div.1+Div.2) 今天就这样匆匆的总结一下, ...

  5. Manthan, Codefest 19 (open for everyone, rated, Div. 1 + Div. 2)-D. Restore Permutation-构造+树状数组

    Manthan, Codefest 19 (open for everyone, rated, Div. 1 + Div. 2)-D. Restore Permutation-构造+树状数组 [Pro ...

  6. Manthan, Codefest 19 (open for everyone, rated, Div. 1 + Div. 2)-C. Magic Grid-构造

    Manthan, Codefest 19 (open for everyone, rated, Div. 1 + Div. 2)-C. Magic Grid-构造 [Problem Descripti ...

  7. Manthan, Codefest 19 (open for everyone, rated, Div. 1 + Div. 2)-E. Let Them Slide-思维+数据结构

    Manthan, Codefest 19 (open for everyone, rated, Div. 1 + Div. 2)-E. Let Them Slide-思维+数据结构 [Problem ...

  8. Codeforces Round #792 (Div. 1 + Div. 2) A-E

    Codeforces Round #792 (Div. 1 + Div. 2) A-E A 题目 https://codeforces.com/contest/1684/problem/A 题解 思路 ...

  9. Codeforces Round #792 (Div. 1 + Div. 2) // C ~ E

    比赛链接:Dashboard - Codeforces Round #792 (Div. 1 + Div. 2) - Codeforces C. Column Swapping 题意: 给定一个n*m ...

  10. 【codeforces】【比赛题解】#868 CF Round #438 (Div.1+Div.2)

    这次是Div.1+Div.2,所以有7题. 因为时间较早,而且正好赶上训练,所以机房开黑做. 然而我们都只做了3题.:(. 链接. [A]声控解锁 题意: Arkady的宠物狗Mu-mu有一只手机.它 ...

随机推荐

  1. 34、python并发编程之多进程(操作篇)

    目录: 一 multiprocessing模块介绍 二 Process类的介绍 三 Process类的使用 四 守护进程 五 进程同步(锁) 六 队列(推荐使用) 七 管道 八 共享数据 九 信号量( ...

  2. 微服务从代码到k8s部署应有尽有系列(三、鉴权)

    我们用一个系列来讲解从需求到上线.从代码到k8s部署.从日志到监控等各个方面的微服务完整实践. 整个项目使用了go-zero开发的微服务,基本包含了go-zero以及相关go-zero作者开发的一些中 ...

  3. 同事会建模,会数据分析,会可视化图表,而你只会用EXCEL?

    ​小李是一家外企的数据分析师,平时处理的都是亿万行级别数据量的报表,为了可以胜任这份工作,小李早早地就学会了各种大数据工具,而且做出来的数据模型高度自动化,效率极高,为公司创造了非常大的价值.因为小李 ...

  4. 项目报错:/uploads: Read-only file system(解决办法)

    项目报错:/uploads: Read-only file system(解决办法) 本来以为是service层没加注解,翻到最后才发现问题 原因是项目根目录没有对应的文件夹,在项目根目录创建uplo ...

  5. bool? int?等可为空的数值类型的运算 三值逻辑

    算术运算:(+,-,*,/)时,只要一个为null,则结果为null. 比较运算符: <.>.<= 和 >=,也是如此.如果一个或全部两个操作数都为 null,则结果为 fal ...

  6. 45个 GIT 经典操作场景,专治不会合代码

    大家好,我是小富~ 技术交流关注公众号:程序员内点事 传送门:原文地址 git对于大家应该都不太陌生,熟练使用git已经成为程序员的一项基本技能,尽管在工作中有诸如 Sourcetree这样牛X的客户 ...

  7. Linux 启动、停止、重启jar包脚本

    转至:https://www.cnblogs.com/foolash/p/13824647.html startOrStropJar.sh #!/bin/bash #这里可替换为你自己的执行程序,其他 ...

  8. 人工智能之深度学习-初始环境搭建(安装Anaconda3和TensorFlow2步骤详解)

    前言: 本篇文章主要讲解的是在学习人工智能之深度学习时所学到的知识和需要的环境配置(安装Anaconda3和TensorFlow2步骤详解),以及个人的心得体会,汇集成本篇文章,作为自己深度学习的总结 ...

  9. k8s全方位监控-prometheus-配置文件介绍以及基于文件服务发现

    1.scrape_configs 参数介绍 # 默认的全局配置 global: scrape_interval: 15s # 采集间隔15s,默认为1min一次 evaluation_interval ...

  10. vue如何全局引用公共js

    在项目开发中需要调用一些工具类方法,所以需要将公共方法放在公共js中,并且需要全局引用这些公共js 1:创建公共JS(utils.js)  src/common/utils.js export def ...