当前位置:   article > 正文

2018.5.12—记录菜菜的一场比赛_you are given an array a consisting of n distinct

you are given an array a consisting of n distinct positive integers. let's c

写个博客记录一下菜鸟成长记~

赛后认真总结反思了一下,还是基础不牢固,思路有了要么是细节处理有问题,要么是题意有遗漏。

A:说是规律。。反正我没想到。。还在研究。

B:

You are given an array a consisting of n elements a1, a2, ..., an. Array a has a special property, which is:

ai = ( ai - 1 + 1) % m, for each i (1 < i ≤ n)
You are given the array a with some lost elements from it, each lost element is replaced by -1. Your task is to find all the lost elements again, can you?
Input
The first line contains an integer T, where T is the number of test cases.
The first line of each test case contains two integers n and m (1 ≤ n ≤ 1000) (1 ≤ m ≤ 109), where n is the size of the array, and m is the described modulus in the problem statement.
The second line of each test case contains n integers a1, a2, ..., an ( - 1 ≤ ai < m), giving the array a. If the ith element is lost, then ai will be -1. Otherwise, ai will be a non-negative integer less than m.
It is guaranteed that the input is correct, and there is at least one non-lost element in the given array.
Output
For each test case, print a single line containing n integers a1, a2, ..., an, giving the array a after finding all the lost elements.
It is guaranteed that an answer exists for the given input.
Example
Input
4
5 10
1 2 3 4 5
4 10
7 -1 9 -1
6 7
5 -1 -1 1 2 3
6 10
5 -1 7 -1 9 0
Output
1 2 3 4 5
7 8 9 0
5 6 0 1 2 3

5 6 7 8 9 0

水题:就是根据一个已知的就能推其它的。

代码:

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int a[1010];
  4. int main()
  5. {
  6. int t;
  7. int n,m;
  8. scanf("%d",&t);
  9. while(t--)
  10. {
  11. scanf("%d%d",&n,&m);
  12. for(int i=1;i<=n;i++)
  13. {
  14. scanf("%d",&a[i]);
  15. }
  16. int lala;
  17. for(int i=1;i<=n;i++)
  18. {
  19. if(a[i]!=-1)
  20. {
  21. a[i+1]=(a[i]+1)%m;
  22. lala=i;
  23. for(int j=i+2;j<=n;j++)
  24. {
  25. a[j]=(a[j-1]+1)%m;
  26. }
  27. break;
  28. }
  29. }
  30. for(int i=lala-1;i>=1;i--)
  31. {
  32. a[i]=a[i+1]-1;
  33. if(a[i]<0)
  34. a[i]+=m;
  35. }
  36. for(int i=1;i<=n;i++)
  37. {
  38. cout<<a[i]<<" ";
  39. }
  40. cout<<endl;
  41. }
  42. return 0;
  43. }

C:二分!!!

You are given an array a consisting of n element a1, a2, ..., an. For each element ai you must find another element aj (i ≠ j), such that the summation of ai and aj mod (109 + 7) (i.e. (ai + aj) % (109 + 7)) is as maximal as possible.


Can you help judges by solving this hard problem?


Input
The first line contains an integer T, where T is the number of test cases.


The first line of each test contains an integer n (2 ≤ n ≤ 10

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Guff_9hys/article/detail/745240
推荐阅读
相关标签
  

闽ICP备14008679号