2022第8届中国大学生程序设计竞赛CCPC桂林站, 签到题4题

news2024/11/28 6:37:29

文章目录

      • A. Lily
      • M.Youth Finale
      • C.Array Concatenation
      • E.Draw a triangle

A. Lily

A. Lily
time limit per test1 second
memory limit per test512 megabytes
inputstandard input
outputstandard output

  • They serve the purpose of changing hydrogen into breathable oxygen, and they’re as necessary here, as the air is on earth.

  • But I still say, they’re flowers.

  • If you like.

  • Do you sell them?

  • I’m afraid not.

  • But, maybe we can make a deal.

  • What do you mean?

  • Oh you see, you don’t have to send them anywhere. I’ll pay for them. But then, I’ll leave them here, for you.

— Assignment Outerspace, 1960
Everything that has a beginning has an ending. My journey has been reaching its ending, and I’ve been ready to say goodbye to my yesterday. But you, my dear friend, your journey is still thriving here at the 2022 CCPC Guilin Site. We sincerely hope you find a brand new milestone here, and forge ahead in the future with your love and passion.

Lily means a kind of beautiful flower. She usually only blooms once a year, so it could be very precious if you see a lily blooming. However, she is highly toxic to cats, so you must be aware of keeping curious cats away from lovely lilies.

You have n grids of soil land in a row, for 1 to n, some with lilies blooming. We don’t want to hurt lilies, as well as cats. You can put some cat food on the grids, but for any grid i with cat food, grids with indices falling in the range [i−1,i+1] must not contain lily flowers. You love cats and lilies, so you want to maximize the number of grids having cat food.

Design a plan to fulfill the above requirements.

Input
There’s a single integer n (1≤n≤1000) in the first line, denoting the number of grids.

The second line contains a string R consisting of only ‘L’ and ‘.’, denoting the grids with and without lilies.

Output
The output contains a single line with string R′ consisting of only ‘L’, ‘.’ and ‘C’, where ‘C’ means the cat food you assigned to the empty grids in R while fulfilling the above requirements.

If there are multiple solutions, print any.

Examples
inputCopy
5
…L…
outputCopy
C.L.C
inputCopy
2

outputCopy
CC

题意:

  • 给出一个长为n的字符串,由.和L组成。
  • 在.的位置放C,要求满足L的相邻两个没有C,求构造一种方案输出。

思路:

  • 扫一遍,对于.,如果前后都没有L就改成C,然后输出即可。
#include<bits/stdc++.h>
using namespace std;

int main(){
    int n;  string s;  cin>>n>>s;
    if(s[0]=='.' && s[1]!='L')s[0] = 'C';
    if(s[n-1]=='.' && s[n-2]!='L')s[n-1] = 'C';
    for(int i = 1; i < n-1; i++){
        if(s[i]=='.' && s[i+1] != 'L' && s[i-1]!='L'){
            s[i] = 'C';
        }
    }
    cout<<s<<"\n";
    return 0;
}

M.Youth Finale

M. Youth Finale
time limit per test3 seconds
memory limit per test512 megabytes
inputstandard input
outputstandard output
Finales are born to be exciting. Performers play hard to draw audiences’ attention and then take a perfect curtain call. As the last problem and the finale of the problem set, however, we want you to recall a simple algorithm. Like me, it may be the first algorithm you’ve learned, called Bubble Sort.

void bubble_sort(int a[], int n) { // 0-based, sort from lowest to highest
for (int i = 1; i < n; i++) {
for (int j = 0; j < n - i; j++) {
if (a[j] > a[j + 1]) {
swap(a[j], a[j + 1]);
}
} // after i-th inner iteration, a[n - i] is correct
}
}
Given a permutation of length n, as you might know, Bubble Sort runs in Ω(n2) in the worst case. It’s quite a traditional idea to count the number of calls of “swap” in the algorithm. As you are stronger now, you want to count that number in a dynamic permutation with the following events that might happen:

Reverse the permutation, meaning that the permutation is replaced with
p′={pn,pn−1,…,p2,p1}.
Shift the permutation to the left by 1, meaning that the permutation is replaced with
p′={p2,p3,…,pn,p1}.
All you need to do is to output the number of “swap” that would be called if we sort the permutation with the above Bubble Sort code after each operation.

Input
The first line contains two integers n,m(1≤n≤3×105,1≤m≤6×105), denoting the length of permutation and the number of operations.

The second line contains n integers separated by spaces, and the i-th denotes the initial pi.

The third line contains a single string containing m letters consisting of ‘R’ and ‘S’. The i-th letter denotes the i-th operation, where ‘R’ or ‘S’ denotes the Reverse or Shift operation, respectively.

It’s guaranteed that p forms a correct permutation of 1,2,…,n.

Output
In the first line, print the number of “swap” would be called when Bubble Sort the initial p.

In the second line, print a single string of m digits. The i-th denotes the number of “swap” would be called to Bubble Sort the permutation, modulo 10.

Example
inputCopy
5 10
5 4 3 2 1
SSSSRSSSSR
outputCopy
10
6446466400

题意:

  • 给出一个长为n的排列,每次操作可以反转排列,或将排列循环左移一位。给出m次操作的操作方案。
  • 给出一个冒泡从低到高排序的代码。求每次操作后,需要多少次冒泡排序将该数组变成排好序的数组。 输出答案%10。

思路:

  • 不难发现未操作时的冒泡排序次数就是原数组的逆序对个数。
  • 对于每次操作,因为是个排列,如果他左移,逆序对个数就会少掉比他小的数的个数,并多上比他大的数的个数。如果翻转,则逆序对个数和正序对个数交换。
  • 知道规律后, deque维护一下数组,然后根据规律输出即可。
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = 1e6+10;

LL n, m, a[maxn];
deque<LL>q;

LL b[maxn];
void add(LL x, LL v){ for(LL i = x; i <= n; i+=i&(-i))b[i]+=v;}
LL query(LL x){ LL ans=0;for(LL i=x;i>0;i-=i&(-i))ans+=b[i];return ans;}

int main(){
    cin>>n>>m;
    for(LL i = 0; i < n; i++)cin>>a[i], q.push_back(a[i]);
    long long ans = 0;
    for(LL i = n-1; i >= 0; i--){
        add(a[i], 1);
        ans += query(a[i]-1);
    }
    cout<<ans<<"\n";
    string s;  cin>>s;
    LL ward = 0, x;
    for(LL i = 0; i < m; i++){
        if(s[i]=='S'){
            if(ward==0){
                x = q.front();  q.pop_front();
                q.push_back(x);
            }else{
                x = q.back();  q.pop_back();
                q.push_front(x);
            }
            ans = (ans-(x-1)+10)%10;
            ans = (ans+(n-x)+10)%10;
        }else{
            ans = (n*(n-1)/2-ans+10)%10;
            ward = !ward;
        }
        ans = (ans+10)%10;
        cout<<ans;
    }
    return 0;
}

C.Array Concatenation

C. Array Concatenation
time limit per test1 second
memory limit per test512 megabytes
inputstandard input
outputstandard output
Little relyt871 has a magical machine. In each operation, his machine can do one of the following operations to the input array b:

Generate a copy of b and concatenate it after b. More formally, the resulting array should be
b′={b1,b2,…,b|b|,b1,b2,…,b|b|}.
Generate a copy of b, reverse it, then concatenate it before b. More formally, the resulting array should be
b′={b|b|,b|b−1|,…,b1,b1,b2,…,b|b|}.
Initially, he has an array a of length n. Then, he wants to operate the machine exactly m times using the array on his hand while maximizing the sum of all prefix sums of the final array. Since he has a somewhat finite brain, when he adds some integers, he only cares about the sum modulo 1000000007. Formally, suppose after all m operations he has array b of length n′, he wants to maximize the following value:
(∑i=1n′∑j=1ibj)(mod1000000007).
Please note that you should maximize the value after taking the modulo: the array with answer 1000000007 before taking the modulo is considered less than the array with answer 1.

Input
The first line contains two integers n and m (1≤n,m≤105).

The second line contains n integers a1, a2,…, an (1≤ai≤109) separated by spaces.

Output
Print a single integer in one line, denoting the answer.

Examples
inputCopy
2 1
1 2
outputCopy
15
inputCopy
5 10
26463 39326 86411 75307 85926
outputCopy
806275469

题意:

  • 给出一个长为n的数组,进行m次操作。每次操作可以将原数组复制一份放到原数组的前面,或者复制一份并翻转后放到原数组的前面,构成一个新的长度为2n的数组。
  • 求最终进行完m次操作后,最后数组的前缀和的和%1e9+7的最大值。 注意是取模后的最大值。

思路:

  • 对于样例2,打表发现答案是一次翻一次不翻的情况,再发现修改m的次数对最终的结果并没有造成影响。
  • 所以不难猜规律肯定是特殊的情况,要么先翻再不翻,或者先不翻再翻,要么就是全翻转,要么就是全不翻转,一共就四种情况。取个max就可以过。
  • 官方题解证明:
    在这里插入图片描述
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL maxn = 1e6+10, mod = 1e9+7;

LL n, m, a[maxn];
LL pows(LL a, LL x) { if(x==0)return 1; LL t = pows(a, x>>1); if(x%2==0)return t*t%mod; return t*t%mod*a%mod; }

int main(){
    cin>>n>>m;
    LL s = 0, ss = 0;
    for(LL i = 1; i <= n; i++){cin>>a[i];  s += a[i];  ss += a[i]*(n-i+1)%mod;}
    s %= mod;  ss %= mod;
    LL res1 = 2*n+1;
    for(LL i = 1; i < m; i++){
        res1 = (res1*2%mod+n*pows(2,2*i)%mod)%mod;
    }
    res1 = res1*s%mod;
    LL res2 = ss;
    for(LL i = 1; i <= m; i++){
        res2 = (res2*2%mod+s*n%mod)%mod;
        s = s*2%mod;
        n = n*2%mod;
    }
    cout<<max(res1,res2)%mod<<"\n";
    return 0;
}

E.Draw a triangle

E. Draw a triangle
time limit per test1 second
memory limit per test512 megabytes
inputstandard input
outputstandard output
Little Desprado2 is a student of Springfield Flowers Kindergarten. On this day, he had just learned how to draw triangles on grid coordinate paper. However, he soon found it very dull, so he came up with a more interesting question:

He had drawn two integral points of the triangle on the grid paper, and he denotes them (x1,y1) and (x2,y2). Now, he wanted to know the answer to the following question: where can he draw the third point (x3,y3) so that the area of the triangle is positive but minimized?

Obviously, he can’t solve this problem because he is too young and simple. Can you tell him the answer?

Please note that your answer’s coordinates must consist of integers because he is drawing on grid paper, and the triangle shouldn’t be a degenerated triangle to keep the area positive.

Input
The first line contains one integer T (1≤T≤50000), denoting the number of Little Desprado2’s queries.

For each test case, there’s a single line contains four integers x1, y1, x2, y2 (−109≤x1, y1, x2, y2≤109) seperated by spaces, denoting two points are at (x1,y1) and (x2,y2), respectively.

It is guaranteed that the two points won’t coincide.

Output
For each test case, print two integers x3, y3 (−1018≤x3, y3≤1018) in a separated line, denoting your answer.

If there are multiple answers, you can print any one of them. It is guaranteed that there exists a solution in the above range.

Example
inputCopy
3
1 0 1 4
0 1 0 9
0 0 2 2
outputCopy
2 0
1 1
-1 0

题意:

  • 给出平面上的两个点(x1,y1)(x2,y2),求第三个整数点(x3,y3)让三个点构成的三角形面积最小。
  • 5e4次询问,输入小于正负1e9,输出小于正负1e18。

思路:

  • 官方
    在这里插入图片描述
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL maxn = 1e6+10, mod = 1e9+7;
LL exgcd(LL a, LL b, LL &x, LL &y){
    if(b==0){  x=1; y=0; return a; }
    LL r = exgcd(b,a%b,x,y);
    LL temp = y;
    y=x-(a/b)*y;
    x=temp;
    return r;
}
int main(){
    LL T;  cin>>T;
    while(T--){
        LL x1, y1, x2, y2;  cin>>x1>>y1>>x2>>y2;
        //AB=(a,b)=(x2-x1, y2-y1), AC=(c,d)=(x3-x1,y3-y1)
        //S = ABxAC = -b*c+a*d = gcd(a,b), 所以a=-(y2-y1), b = x2-x1, exgcd得c,d
        LL a = -(y2-y1), b = x2-x1, c, d;
        LL k1 = 1, k2 = 1;      //符号取正最后再乘回来
        if(a <= 0)k1=-k1, a=-a;
        if(b <= 0)k2=-k2, b=-b;
        exgcd(a, b, c, d);
        c *= k1;  d *= k2;
        cout<<(c+x1)<<" "<<(d+y1)<<"\n";
    }
    return 0;
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/3756.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

MySQL数据库 -- 库和表的操作

关于数据库方面&#xff0c;还是需要多多练习的&#xff0c;否则很多指令不容易记住&#xff0c;所以大家也要在自己的电脑上多写写&#xff0c;熟悉熟悉~ 目录 库的操作 创建数据库 操纵数据库 查看数据库 显示创建语句 修改数据库 数据库的删除 数据库备份和恢复 …

重学数据库基础

幸福找到我&#xff0c;幸福说&#xff1a;“瞧这个诗人&#xff0c;他比我本人还要幸福” 一、数据库相关概念 数据库 存储数据的仓库&#xff0c;数据是有组织的进行存储英文&#xff1a;DataBase&#xff0c;简称 DB 数据库管理系统 管理数据库的大型软件英文&#xff1a;Da…

CSI室内指纹定位——相关通信名词解释

目录 1、无线信道 2、时域与频域 3、信道频率响应&#xff08;Channel Frequency Response,CFR&#xff09; 4、信道冲激响应&#xff08;Channel Impulse Response, CIR&#xff09; 5、信道带宽 6、带宽 7、子载波 9、波长 10、频率 11、振幅 12、相位 13、相位差…

高数值孔径(NA)物镜的聚焦分析

1. 摘要 高NA物镜广泛用于光刻&#xff0c;显微等技术。因此&#xff0c;聚焦仿真中考虑光的矢量性质至关重要。VirtualLab可以非常便捷地对此类镜头进行光线追迹和场追迹分析。通过场追迹&#xff0c;可以清楚地观察由于矢量效应引起的聚焦光斑失对称现象。利用相机探测器和电…

第十四届蓝桥杯(Web应用开发)模拟赛1期-大学组

数据类型检测 请看这篇数据类型检测 渐变色背景生成器 html <!DOCTYPE html> <html lang"en"><head><meta charset"UTF-8" /><meta http-equiv"X-UA-Compatible" content"IEedge" /><meta name&…

java面试官:程序员,请你告诉我是谁把公司面试题泄露给你的?

前情提要&#xff1a; 面试官&#xff1a;你好&#xff01;请先做一下自我介绍&#xff01; 程序员&#xff1a;balabalabala... 前戏先过了.... 面试官&#xff1a;先介绍SpringCloud核心组件及其作用 程序员&#xff1a;SpringCloud由以下5个核心组件构成...另外&#x…

MySQL事务基本操作(方式1)

在观看本文前 你需要了解什么事事务 如果不太了解 可以先查看我的文章 MySQL事务基本概念 首先 我们这里有一张 staff 用户表 然后来一波 减岁交易大法 赵敏买个了 黄飞鸿十年时光 那么就是 先查询确认赵敏加上十岁不会过百 将赵敏年龄加十岁 确认黄飞鸿减去十岁不会小于零 然…

Java项目(三)-- SSM开发社交网站(9)--后台图书管理功能

后台图书管理功能 富文本编辑器wangEditor 基于javascript与css开发是Web富文本编辑器&#xff0c;轻量、简洁、易用、开源免费。 代码演示 我们在test.ftl中添加富文本编辑器演示下 <!DOCTYPE html> <html lang"en"> <head><meta charset&…

CMake中string的使用

CMake中的string命令用于字符串操作,其格式如下&#xff1a; Search and Replacestring(FIND <string> <substring> <out-var> [...])string(REPLACE <match-string> <replace-string> <out-var> <input>...)string(REGEX MATCH &l…

【数据库Redis】Redis五种基本数据结构以及三种配置方式——默认配置、运行配置、配置文件启动

文章目录一、初识Redis1.1 了解Redis1.2 Redis特性1.3 Redis使用场景Redis不适合场景1.4 用好Redis的建议1.5 正确安装并启动Redis在Linux上安装Redis在Windows上安装Redis配置、启动、操作、关闭Redis1)、启动Redis2)、Redis命令行客户端3)、停止Redis服务1.6 Redis重大版本一…

JVM(十四)—— StringTable

JVM&#xff08;十四&#xff09;—— StringTableString的基本特性String的内存分配字符串拼接intern方法常见面试题&#xff1a;到底创建了几个String对象String的基本特性 作为一名Java程序员肯定少不了和 String打交道&#xff0c;使用方法就是将字符串用一对""…

SpringCloud 远程调用

目录 1. SpringCloud 2. Nacos 3. 远程通信 3.1 创建公共子模块 (nacos_commons) 3.1.1 DTO对象 3.2 父项目引入子项目 (nacos_commons) 打成的jar包 3.3 父项目指向子项目 (nacos_commons) 为儿子 3.4 子项目 (nacos_provider) 3.5 子项目 (nacos_consumer) …

【Netty】九、Netty自定义协议

Netty自定义协议一、Netty自定义协议二、 协议设计三、 协议实现编码&#xff1a;解码&#xff1a;时间轮算法Netty中的时间轮一、Netty自定义协议 公有协议&#xff08;http、tcp&#xff09;、私有协议&#xff08;自己定义的&#xff0c;不是行业标准&#xff09; 我们知道…

[Qt]QMainWindow

目录 1.基本概述 2.菜单栏 3.工具栏 4.状态栏 5.铆接部件 6.中心部件 7.资源文件 &#xff08;1&#xff09;创建菜单栏&#xff0c;及菜单项 (2)创建工具栏 (3)创建锚接部件 (4)创建中心文件 &#xff08;5&#xff09;创建状态栏 1.基本概述 QMainWindow是一个为…

腾讯网关TGW基础原理入门

本文是在组内技术分享的发言稿&#xff0c;主要介绍 TGW 基本原理和架构&#xff0c;同时为了加深理解&#xff0c;会辅助对比 TGW 与 LVS&#xff08;ipvs&#xff09;的异同。 本次分享是偏基础性的 TGW 介绍&#xff0c;不会特别深入技术细节&#xff0c;目的是帮助需要用到…

算法7:迪杰斯特拉算法

目录1. 应用场景-最短路径问题2. 迪杰斯特拉(Dijkstra)算法介绍3. 迪杰斯特拉(Dijkstra)算法过程4. 算法分析过程5. 代码实现1. 应用场景-最短路径问题 看一个应用场景和问题 胜利乡有7个村庄(A, B, C, D, E, F, G) &#xff0c;现在有六个邮差&#xff0c;从G点出发&#xff…

贪吃蛇OneDay

环境 配置git环境 安装Git Bash&#xff08;使用Mac和Linux的同学可以跳过这一步&#xff09;&#xff1a;https://gitforwindows.org/ 进入家目录生成秘钥&#xff1a;执行命令ssh-keygen 在Ac Git上注册账号&#xff0c;地址&#xff1a;https://git.acwing.com/ 将id_rsa.p…

Unity中的AssetBundle

AssetBundle的概念 AssetBundle又称AB包&#xff0c;是Unity提供的一种用于存储资源的资源压缩包&#xff0c;是对Unity 初始Resources的一种扩展&#xff1b;一般使用的策略是把必须的资源和不需要更新的资源放在Resources文件夹下&#xff0c;其他的资源放在AssetBundle下面…

【微信小程序】flex布局

&#x1f3c6;今日学习目标&#xff1a;flex布局 &#x1f603;创作者&#xff1a;颜颜yan_ ✨个人主页&#xff1a;颜颜yan_的个人主页 ⏰预计时间&#xff1a;20分钟 &#x1f389;专栏系列&#xff1a;微信小程序开发 文章目录前言Flex布局什么是flex&#xff1f;flex-direc…

Hive中内部表、外部表、分区表、分桶表之间的关系

文章目录Hive中内部表、外部表、分区表、分桶表之间的关系1.0&#x1f680;内部表2.0&#x1f440;外部表3.0&#x1fae5;内部表和外部表的差异3.0&#x1f418;分区表4.0&#x1f603;分桶表Hive中内部表、外部表、分区表、分桶表之间的关系 1.0&#x1f680;内部表 内部表&…