• 蓝桥杯第四场双周赛(1~6)


    1、水题

    2、模拟题,写个函数即可

    1. #define pb push_back
    2. #define x first
    3. #define y second
    4. #define int long long
    5. #define endl '\n'
    6. const LL maxn = 4e05+7;
    7. const LL N = 5e05+10;
    8. const LL mod = 1e09+7;
    9. const int inf = 0x3f3f;
    10. const LL llinf = 5e18;
    11. typedef pair<int,int>pl;
    12. priority_queue, greater >mi;//小根堆
    13. priority_queue ma;//大根堆
    14. LL gcd(LL a, LL b){
    15. return b > 0 ? gcd(b , a % b) : a;
    16. }
    17. LL lcm(LL a , LL b){
    18. return a / gcd(a , b) * b;
    19. }
    20. int n , m;
    21. int a[N];
    22. void init(int n){
    23. for(int i = 0 ; i <= n ; i ++){
    24. a[i] = 0;
    25. }
    26. }
    27. int qc(int a, int b , int c){
    28. return (a + b + c)/2;
    29. }
    30. int alg(int a , int b , int c){
    31. int cc = qc(a , b , c);
    32. return (cc * (cc - a) * (cc - b) * (cc - c));
    33. }
    34. void solve()
    35. {
    36. int a , b , c;
    37. cin >> a >> b >> c;
    38. if(a + b <= c || a + c <= b || b + c <= a){
    39. cout << -1;
    40. }
    41. else
    42. cout << alg(a , b , c);
    43. }
    44. signed main()
    45. {
    46. ios::sync_with_stdio(false);
    47. cin.tie(0);
    48. cout.tie(0);
    49. cout.precision(10);
    50. int t=1;
    51. // cin>>t;
    52. while(t--)
    53. {
    54. solve();
    55. }
    56. return 0;
    57. }

    3、模拟题,找规律,第一行和最后一行只有两个数,其余行都是三个数。

         第一行特殊处理,其余行:  (x + 1) / 3 + 1 就是当前所在行rx - ((r - 1) * 3 - 1)就是所在行第s个数 , 每行第一个数是r - 1, 因此所在列就是r - 1 + s。

            

    1. #include
    2. using namespace std;
    3. int main()
    4. {
    5. long long n , m;
    6. cin >> n >> m;
    7. for(int i = 0 ; i < m ; i ++){
    8. long long x;
    9. cin >> x;
    10. if(x <= 1){
    11. cout << 1 << " " << x + 1 << endl;
    12. }
    13. else{
    14. long long r = (x + 1) / 3 + 1;
    15. long long st = x - ((r - 1) * 3 - 1);
    16. long long dc = r - 1 + st;
    17. cout << r << " " << dc << endl;
    18. }
    19. }
    20. return 0;
    21. }

    4、考虑找到x^a , y^b , z^c的所有可能取值,取值上界应该为10^{12} * 10^5 = 10^{17}。由于2^{64}>10^{18},因此每个肯定不超过64种取值。用三重循环找到所有  x^a + y^b + z^c的所有取值,复杂度为O(64^3)。注意x^a*x<inf判断可能会爆long long , 所以在判断是否到达上界需要用x^a < inf/x。用数组或者set去存每种取值,然后从小到大排序。按照题目条件对每个询问搜索即可(二分/暴力)。整体复杂度O(q * 64^3)/O(q*log(64^3))

    1. #include
    2. using namespace std;
    3. #define LL long long
    4. #define pb push_back
    5. #define x first
    6. #define y second
    7. #define endl '\n'
    8. const LL maxn = 4e05+7;
    9. const LL N = 5e05+10;
    10. const LL mod = 1e09+7;
    11. const int inf = 0x3f3f;
    12. const LL llinf = 2e18;
    13. typedef pair<int,int>pl;
    14. priority_queue, greater >mi;//小根堆
    15. priority_queue ma;//大根堆
    16. LL gcd(LL a, LL b){
    17. return b > 0 ? gcd(b , a % b) : a;
    18. }
    19. LL lcm(LL a , LL b){
    20. return a / gcd(a , b) * b;
    21. }
    22. int n , m;
    23. LL a , b , c;
    24. setst;
    25. void solve()
    26. {
    27. cin >> a >> b >> c;
    28. vectoraa , bb , cc;
    29. aa.pb(1);
    30. bb.pb(1);
    31. cc.pb(1);
    32. LL x = 1;
    33. while(a != 1 && x < llinf / a){
    34. x *= a;
    35. aa.pb(x);
    36. }
    37. LL y = 1;
    38. while(b != 1 && y < llinf / b){
    39. y *= b;
    40. bb.pb(y);
    41. }
    42. LL z = 1;
    43. while(c != 1 && z < llinf / c){
    44. z *= c;
    45. cc.pb(z);
    46. }
    47. for(int i = 0 ; i < aa.size() ; i ++){
    48. for(int j = 0 ; j < bb.size() ; j ++){
    49. for(int z = 0 ; z < cc.size() ; z ++){
    50. st.insert(aa[i] + bb[j] + cc[z]);
    51. }
    52. }
    53. }
    54. int m;
    55. cin >> m;
    56. for(int i = 0 ; i < m ; i ++){
    57. LL que;
    58. cin >> que;
    59. auto it = st.upper_bound(que);
    60. while(*it - que == 1){
    61. que = *it;
    62. it = st.upper_bound(que);
    63. }
    64. cout << que + 1 << " " << (*it - que - 1) << endl;
    65. }
    66. }
    67. int main()
    68. {
    69. ios::sync_with_stdio(false);
    70. cin.tie(0);
    71. cout.tie(0);
    72. cout.precision(10);
    73. int t=1;
    74. // cin>>t;
    75. while(t--)
    76. {
    77. solve();
    78. }
    79. return 0;
    80. }

    5、 方法很多,大体思路为将类型一样的宝石放到一起,将他们的作用区间进行合并,然后对整个数组进行区间修改。

            区间合并:将所有区间按照左端点排序,遍历区间,若当前左端点与前一个区间右端点有重合部分,则将他们合并成一个区间,否则将前一个区间存下来,当前区间为一个新的区间。

            区间修改:差分/树状数组/线段树。

            

    1. #include
    2. using namespace std;
    3. #define LL long long
    4. #define pb push_back
    5. #define x first
    6. #define y second
    7. #define endl '\n'
    8. const LL maxn = 4e05+7;
    9. const LL N = 5e05+10;
    10. const LL mod = 1e09+7;
    11. const int inf = 0x3f3f;
    12. const LL llinf = 5e18;
    13. typedef pair<int,int>pl;
    14. priority_queue, greater >mi;//小根堆
    15. priority_queue ma;//大根堆
    16. LL gcd(LL a, LL b){
    17. return b > 0 ? gcd(b , a % b) : a;
    18. }
    19. LL lcm(LL a , LL b){
    20. return a / gcd(a , b) * b;
    21. }
    22. int n , m;
    23. int a[N];
    24. void init(int n){
    25. for(int i = 0 ; i <= n ; i ++){
    26. a[i] = 0;
    27. }
    28. }
    29. struct BIT{//Binary indexed Tree(树状数组)
    30. int n;
    31. vector<int> tr;
    32. BIT(int n) : n(n) , tr(n + 1 , 0){
    33. }
    34. int lowbit(int x){
    35. return x & -x;
    36. }
    37. void modify(int x , int modify_number){
    38. for(int i = x ; i <= n ; i += lowbit(i)){
    39. tr[i] += modify_number;
    40. }
    41. }
    42. void modify(int l , int r , int modify_number){
    43. modify(l , modify_number);
    44. modify(r + 1 , -modify_number);
    45. }
    46. int query(int x){
    47. int res = 0;
    48. for(int i = x ; i ; i -= lowbit(i))
    49. res += tr[i];
    50. return res;
    51. }
    52. int query(int x , int y){
    53. return query(y) - query(x);
    54. }
    55. };
    56. void solve()
    57. {
    58. int n , m , q;
    59. cin >> n >> m >> q;
    60. vector<int>len(m + 5);
    61. for(int i = 1 ; i <= m ; i++){
    62. cin >> len[i];
    63. }
    64. BIT bit(n);
    65. vectorint,int>>que;
    66. for(int i = 0 ; i < q ; i ++){
    67. int x , y;
    68. cin >> x >> y;
    69. que.pb({x , y});
    70. }
    71. sort(que.begin() , que.end());
    72. int r = 0 , pos = 0;
    73. for(int i = 0 ;i < q ; i ++){
    74. if(que[i].x != pos){
    75. pos = que[i].x;
    76. r = 0;
    77. }
    78. bit.modify( max(r + 1, que[i].y) , min(que[i].y + len[pos] - 1 , n) , 1);
    79. r = min(que[i].y + len[pos] - 1 , n);
    80. }
    81. for(int i = 1 ; i <= n ; i ++){
    82. cout << bit.query(i)<<" ";
    83. }
    84. }
    85. int main()
    86. {
    87. ios::sync_with_stdio(false);
    88. cin.tie(0);
    89. cout.tie(0);
    90. cout.precision(10);
    91. int t=1;
    92. // cin>>t;
    93. while(t--)
    94. {
    95. solve();
    96. }
    97. return 0;
    98. }

    6、删除区间求中位数比较困难。相反,增加数求区间中位数就是一道对顶堆的板子题了。因此考虑逆着做题,先将所有会飘走的气球放弃,将其余气球加入对顶堆。然后再从后往前依次添加气球,维护对顶堆找答案即可(对顶堆网上一大堆模板)。

            

    1. #include
    2. using namespace std;
    3. #define LL long long
    4. #define pb push_back
    5. #define x first
    6. #define y second
    7. #define endl '\n'
    8. const LL maxn = 4e05+7;
    9. const LL N = 5e05+10;
    10. const LL mod = 1e09+7;
    11. const int inf = 0x3f3f;
    12. const LL llinf = 5e18;
    13. typedef pair<int,int>pl;
    14. priority_queue, greater >mi;//小根堆
    15. priority_queue ma;//大根堆
    16. LL gcd(LL a, LL b){
    17. return b > 0 ? gcd(b , a % b) : a;
    18. }
    19. LL lcm(LL a , LL b){
    20. return a / gcd(a , b) * b;
    21. }
    22. int n , m;
    23. int a[N];
    24. void init(int n){
    25. for(int i = 0 ; i <= n ; i ++){
    26. a[i] = 0;
    27. }
    28. }
    29. void solve()
    30. {
    31. cin >> n;
    32. for(int i = 1 ; i <= n ; i ++){
    33. cin >> a[i];
    34. }
    35. cin >> m;
    36. double ans[m + 5];
    37. int que[m + 5];
    38. int vis[n + 5];
    39. memset(vis,0,sizeof vis);
    40. for(int i = 1 ; i <= m ; i ++){
    41. cin >> que[i];
    42. vis[que[i]] = 1;
    43. }
    44. for(int i = 1 ;i <= n ; i ++){
    45. if(!vis[i]){
    46. ma.push(a[i]);
    47. }
    48. }
    49. while(ma.size() > mi.size()){
    50. mi.push(ma.top());
    51. ma.pop();
    52. }
    53. for(int i = m ; i > 0 ; i --){
    54. if((mi.size() + ma.size()) % 2 == 0){//偶数
    55. int x = mi.top();
    56. int y = ma.top();
    57. ans[i] = (double)(1.0 * x + y) / 2;
    58. }
    59. else{
    60. double x = mi.top();
    61. ans[i] = (double)(1.0 * x);
    62. }
    63. int yy = mi.top();
    64. if(a[que[i]] > yy){
    65. mi.push(a[que[i]]);
    66. }
    67. else{
    68. ma.push(a[que[i]]);
    69. }
    70. while(mi.size() > ma.size() + 1){
    71. ma.push(mi.top());
    72. mi.pop();
    73. }
    74. while(ma.size() > mi.size()){
    75. mi.push(ma.top());
    76. ma.pop();
    77. }
    78. }
    79. for(int i = 1 ; i <= m ; i++){
    80. printf("%.1f " , ans[i]);
    81. }
    82. }
    83. int main()
    84. {
    85. ios::sync_with_stdio(false);
    86. cin.tie(0);
    87. cout.tie(0);
    88. cout.precision(10);
    89. int t=1;
    90. // cin>>t;
    91. while(t--)
    92. {
    93. solve();
    94. }
    95. return 0;
    96. }

            

    7、边数据较小,网络流问题。

  • 相关阅读:
    2022年中级经济师《工商管理》考试大纲
    使用STM32F103C8T自制freejoy控制板
    ch4-3 音频信号的频域特征
    NDVI时间序列分析之Sen+MK分析全过程梳理
    在Column中嵌入横向滚动的ListView
    国家/行业标准查询及下载全流程
    图像处理:图像清晰度评价
    《统计学习方法》第十九章 马尔可夫链蒙特卡罗法
    【英雄哥七月集训】第 20天:搜索二叉树
    Docker Desktop for Windows 安装过程整理
  • 原文地址:https://blog.csdn.net/weixin_61825750/article/details/134624528