UPC组队训练-补题记录(下)

简介: Eggfruit Cake时间限制: 1 Sec 内存限制: 128 MB题目描述Today is Jaime’s birthday and, to celebrate, his friends ordered a cake decorated with eggfruits and persimmons. When the cake arrived, to their surprise, they noticed that the bakery didn’t use equal amounts of eggfruits and persimmons,

Eggfruit Cake

时间限制: 1 Sec 内存限制: 128 MB


题目描述


Today is Jaime’s birthday and, to celebrate, his friends ordered a cake decorated with eggfruits and persimmons. When the cake arrived, to their surprise, they noticed that the bakery didn’t use equal amounts of eggfruits and persimmons, but just randomly distributed the fruits over the cake’s border instead.

Jaime eats persimmons every day, so he was eager to try some eggfruit on his birthday.

However, as he doesn’t want to eat too much, his cake slice should be decorated with at most S fruits. Since Jaime doesn’t like when a fruit is cut into parts, each fruit should either be entirely in his slice or be left in the rest of the cake. The problem is, with the fruits distributed in such a chaotic order, his friends are having trouble cutting a suitable slice for him.

Jaime is about to complain that his friends are taking too long to cut his slice, but in order to do so, he needs to know how many different slices with at least one eggfruit and containing at most S fruits there are. A slice is defined just based on the set of fruits it contains. As Jaime is quite focused on details, he is able to distinguish any two fruits, even if both fruits are of the same type. Hence, two slices are considered different when they do not contain exactly the same set of fruits. The following picture shows a possible cake, as well as the six different slices with at most S = 2 fruits that can be cut from it.


输入


The first line contains a circular string B (3 ≤ |B| ≤ 105) describing the border of the cake.Each character of B is either the uppercase letter “E” or the uppercase letter “P”, indicating

respectively that there’s an eggfruit or a persimmon at the border of the cake. The second line contains an integer S (1 ≤ S < |B|) representing the maximum number of fruits that a slice can contain.


输出


Output a single line with an integer indicating the number of different slices with at most S fruits and at least one eggfruit.


样例输入


【样例1】
PEPEP
2
【样例2】
EPE
1
【样例3】
PPPP
1
【样例4】
EPEP
2


样例输出


【样例1】
6
【样例2】
2
【样例3】
0
【样例4】
6


题目大意:


给出一个首尾相接的字符串,问有多少长度不超过 n 的包含字符 ‘E’ 的子串

方法: 尺取

代码如下:

string s;
int n;
int main()
{
    cin >> s >> n;
    int len = s.length();
    s = s + s;
    for(int i=0,r = 0,x = 0;i < len ;i ++){
        while(r + 1 < s.size() && x == 0){
            if(s[r] == 'E') x++;
            r ++;
        }
        ans += max(n - (r - i - 1) ,0);
        if(s[i] == 'E') x --;
    }
    cout << ans <<endl;
    return 0;
}


队友的暴力代码(据说):


ll m,n,cnt,a[maxn];
string sz;
ll t=1,sum=0;
int main(){
    cin>>sz>>n;
    ll m=sz.size();
    for(ll i=0;i<m;i++)  sz.push_back(sz[i]);
    for(ll i=0;i<m*2;i++)    if(sz[i]=='E')  a[++cnt]=i;
    if(!cnt){
        cout<<0;
        return 0;
    }
    for(ll i=0;i<m;i++){
        if(a[t]<i&&t<=cnt)    t++;
        if(t>cnt)    break;
        sum+=max(ll(0),i+n-a[t]);
    }
    cout<<sum;
}


另一个队友的代码:


const int N = 1e6 + 10;
char s[N];
int f[N];
int cnt;
struct node {
    int l, r;
}q[N];
vector<int> vt;
ll get(ll n, ll x, const int len) {
    if (x == len) {
        return n;
    }
    else if (x >= n) return 0;
    else return n - x;
}
int main() {
    cin >> s + 1;
    int len = strlen(s + 1);
    int n; cin >> n;
    int cntE = 0, pos = 0;
    for (int i = len; i >= 1; i--) {
        if (s[i] == 'E') {
            f[i] = len; cntE++;
            pos = i;
        }
        else if (pos != 0) {
            f[i] = pos - i;
        }
    }
    if (cntE == 0) { cout << 0 << endl; return 0; }
    for (int i = len; i >= 1; i--) {
        if (f[i]) break;
        f[i] = len - i + pos;
    }
    ll ans = 0;
    for (int i = 1; i <= len; i++) {
        //cout << f[i] << " ";
        ans += get(n, f[i], len);
    }
    //puts("");
    cout << ans << endl;
    return 0;
}


Know your Aliens

时间限制: 1 Sec 内存限制: 128 MB


题目描述


Our world has been invaded by shapeshifting aliens that kidnap people and steal their identities.You are an inspector from a task force dedicated to detect and capture them. As such, you were given special tools to detect aliens and differentiate them from real humans. Your current mission is to visit a city that is suspected of have been invaded, secretly inspect every person there so as to know whose are aliens and whose aren’t, and report it all to Headquarters. Then they can send forces to the city by surprise and capture all the aliens at once. The aliens are aware of the work of inspectors like you, and are monitoring all radio channels to detect the transmission of such reports, in order to anticipate any retaliation. Therefore, there have been several efforts to encrypt the reports, and the most recent method uses polynomials.

The city you must visit has N citizens, each identified by a distinct even integer from 2 to 2N. You want to find a polynomial P such that, for every citizen i, P(i) > 0 if citizen i is

a human, and P(i) < 0 otherwise. This polynomial will be transmitted to the Headquarters.With the aim of minimizing bandwidth, the polynomial has some additional requirements:each root and coefficient must be an integer, the coefficient of its highest degree term must be either 1 or −1, and its degree must be the lowest possible.

For each citizen, you know whether they’re a human or not. Given this information, you must find a polynomial that satisfies the described constraints.


输入


The input consists of a single line that contains a string S of length N (1 ≤ N ≤ 104),where N is the population of the city. For i = 1, 2, . . . , N, the i-th character of S is either the uppercase letter “H” or the uppercase letter “A”, indicating respectively that citizen 2i is a human or an alien.


输出


The first line must contain an integer D indicating the degree of a polynomial that satisfies the described constraints. The second line must contain D + 1 integers representing the coefficients of the polynomial, in decreasing order of the corresponding terms. It’s guaranteed that there exists at least one solution such that the absolute value of each coefficient is less than 263.


样例输入


【样例1】
HHH
【样例2】
AHHA
【样例3】
AHHHAH


样例输出


【样例1】
0
1
【样例2】
2
-1 10 -21
【样例3】
3
1 -23 159 -297


Code :


具体的方法

string s;
ll x[maxn];
ll b[maxn];
int cnt;
void _Get_x(){
    int len = s.size();
    for(int i=1;i < len-1;i++){
        if(s[i] != s[i+1]) x[++cnt] = 2*i+1;
    }
    cout<<cnt<<endl;
}
void _Get_xi(){
    for(int i=1;i<= cnt;i++){
        for(int j=i+1;j>=1;j--){
            b[j] = b[j - 1];
        }
        for(int j=1;j<=i;j++){
            b[j] += b[j+1] * x[i];
        }
    }
}
int main()
{
    b[1] = 1;
    cin >> s;
    s = 'a' + s;
    _Get_x();
    _Get_xi();
    int oper = 1;
    if(s[1] == 'H' && cnt % 2) oper *= -1;
    if(s[1] == 'A' && cnt % 2 == 0) oper *= -1;
    for(int i=cnt + 1;i >= 1;i --){
        printf("%lld",b[i]*oper);
        oper *= -1;
        if(i != 1) printf(" ");
    }
    return 0;
}


目录
相关文章
|
5月前
|
算法 图形学 计算机视觉
CVPR 2024:合成视频数据集里只有单人数据?M3Act破解人群行为标注难题
【6月更文挑战第12天】CVPR 2024上的M3Act数据集解决了复杂人群行为标注难题,提供多视角、多群体的合成视频数据,助力计算机视觉研究。利用Unity引擎生成高度真实的人类动作和群体活动,促进以人类为中心任务的学习。实验显示,M3Act能提升目标检测等任务性能,降低数据收集成本,并支持3D群体活动的可控生成。尽管面临数据复杂性、偏差和计算资源限制等问题,M3Act为相关研究提供了宝贵资源。[论文链接](https://arxiv.org/abs/2306.16772)
74 4
|
6月前
|
算法 数据可视化 数据挖掘
JCR一区10.9分|单细胞:有一手数据的肿瘤课题组怎么冲高分文章
这篇文章介绍了在《肿瘤免疫疗法》杂志上发表的一项研究,该研究利用单细胞RNA测序技术揭示了肝细胞癌(HCC)中FABP1(脂肪酸结合蛋白1)依赖的免疫抑制环境。研究分析了II期和III期HCC患者样本的免疫细胞,发现FABP1在III期HCC的肿瘤相关巨噬细胞(TAMs)中过度表达,并与免疫抑制有关。FABP1与PPARG(过氧化物酶体增殖物激活受体伽玛)相互作用,促进了HCC中的脂肪酸氧化,进而影响免疫应答。
94 0
成信大ENVI_IDL第二周实验内容:提取所有MODIS气溶胶产品中AOD+详细解析
成信大ENVI_IDL第二周实验内容:提取所有MODIS气溶胶产品中AOD+详细解析
205 0
|
机器学习/深度学习 自然语言处理 JavaScript
用modelscope分析了百万字的《天龙八部》,原来金庸大师最偏爱的是TA
用modelscope分析了下百万字的《天龙八部》,摸清楚了金庸大师的取名智慧
|
人工智能
UPC——2020年春混合个人训练第二十四场(DEFG)
UPC——2020年春混合个人训练第二十四场(DEFG)
117 0
UPC——2020年春混合个人训练第二十四场(DEFG)
|
运维 监控 Cloud Native
3.2 行程卡识别应用实践(一)|学习笔记
快速学习3.2 行程卡识别应用实践(一)
3.2 行程卡识别应用实践(一)|学习笔记
|
JSON 文字识别 Serverless
3.2 行程卡识别应用实践(二)|学习笔记
快速学习3.2 行程卡识别应用实践(二)
3.2 行程卡识别应用实践(二)|学习笔记
|
人工智能 定位技术 Go
UPC——2020年春混合个人训练第二十五场(FG)
UPC——2020年春混合个人训练第二十五场(FG)
93 0
|
监控
UPC——西⽐拉先知系统(分块)
UPC——西⽐拉先知系统(分块)
101 0
|
人工智能
upc2021个人训练赛第23场M: 紫罗兰(dsu)
upc2021个人训练赛第23场M: 紫罗兰(dsu)
95 0