Codeforce GoodBye2020 A - C

本文探讨了两个算法问题:一是计算在特定约束下能形成的三角形的不同面积,二是如何通过增加音乐曲目的音符多样性来提高歌曲的吸引力。对于前者,涉及排列组合和坐标系中的几何概念;对于后者,关注的是如何在不改变歌曲长度的情况下增加不同音符的数量。这两个问题都涉及到在有限资源下优化特定指标的问题。

A. Bovine Dilemma

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Argus was charged with guarding Io, which is not an ordinary cow. Io is quite an explorer, and she wanders off rather frequently, making Argus' life stressful. So the cowherd decided to construct an enclosed pasture for Io.

There are nn trees growing along the river, where Argus tends Io. For this problem, the river can be viewed as the OXOX axis of the Cartesian coordinate system, and the nn trees as points with the yy-coordinate equal 00. There is also another tree growing in the point (0,1)(0,1).

Argus will tie a rope around three of the trees, creating a triangular pasture. Its exact shape doesn't matter to Io, but its area is crucial to her. There may be many ways for Argus to arrange the fence, but only the ones which result in different areas of the pasture are interesting for Io. Calculate the number of different areas that her pasture may have. Note that the pasture must have nonzero area.

Input

The input consists of multiple test cases. The first line contains an integer tt (1≤t≤1001≤t≤100) — the number of test cases. Then tt test cases follow, each one is described in two lines.

In the first line of each test case there is a single integer nn (1≤n≤501≤n≤50) denoting the number of trees growing along the river. Next line contains nn distinct integers x1<x2<…<xn−1<xnx1<x2<…<xn−1<xn (1≤xi≤501≤xi≤50), the xx-coordinates of trees growing along the river.

Output

In a single line output an integer, the number of different nonzero areas that triangles with trees as vertices may have.

Example

input

Copy

8
4
1 2 4 5
3
1 3 5
3
2 6 8
2
1 2
1
50
5
3 4 5 6 8
3
1 25 26
6
1 2 4 8 16 32

output

Copy

4
2
3
1
0
5
3
15

Note

In the first test case, we have 66 non-degenerate triangles with the following areas: 0.50.5, 0.50.5, 11, 1.51.5, 1.51.5 and 22. The pasture can have 44 different areas, and thus 44 is the answer.

In the second test case, we have 33 non-degenerate triangles with the following areas: 11, 11 and 22. The pasture can have 22 different areas, so 22 is the answer.

The following two drawings present the situation in the second test case. The blue triangles in the first drawing have area 11. The red triangle in the second drawing has area 22.

 

code:

#include<bits/stdc++.h>
using namespace std;
int a[105];
int main()
{
 
    int T, n, sum = 0;
    set<int> S;
    cin >> T;
    while(T--)
    {
        S.clear();
        memset(a, 0, sizeof(a));
        scanf("%d", &n);
        for(int i = 0; i < n; i++)
            scanf("%d", &a[i]);
        for(int i = 0; i < n; i++)
            for(int j = i + 1; j < n; j++)
                S.insert(a[j] - a[i]);
        cout << S.size() << endl;
    }
    return 0;
}

B. Last minute enhancements

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Athenaeus has just finished creating his latest musical composition and will present it tomorrow to the people of Athens. Unfortunately, the melody is rather dull and highly likely won't be met with a warm reception.

His song consists of nn notes, which we will treat as positive integers. The diversity of a song is the number of different notes it contains. As a patron of music, Euterpe watches over composers and guides them throughout the process of creating new melodies. She decided to help Athenaeus by changing his song to make it more diverse.

Being a minor goddess, she cannot arbitrarily change the song. Instead, for each of the nn notes in the song, she can either leave it as it is or increase it by 11.

Given the song as a sequence of integers describing the notes, find out the maximal, achievable diversity.

Input

The input consists of multiple test cases. The first line contains an integer tt (1≤t≤100001≤t≤10000) — the number of test cases. Then tt test cases follow, each one is described in two lines.

In the first line of each test case there is a single integer nn (1≤n≤1051≤n≤105) denoting the length of the song. The next line contains a sequence of nn integers x1,x2,…,xnx1,x2,…,xn (1≤x1≤x2≤…≤xn≤2⋅n)(1≤x1≤x2≤…≤xn≤2⋅n), describing the song.

The sum of nn over all test cases does not exceed 105105.

Output

For each test case, you should output a single line containing precisely one integer, the maximal diversity of the song, i.e. the maximal possible number of different elements in the final sequence.

Example

input

Copy

5
6
1 2 2 2 5 6
2
4 4
6
1 1 3 4 4 5
1
1
6
1 1 1 2 2 2

output

Copy

5
2
6
1
3

Note

In the first test case, Euterpe can increase the second, fifth and sixth element to obtain the sequence 1,3–,2,2,6–,7–1,3_,2,2,6_,7_, which has 55 different elements (increased elements are underlined).

In the second test case, Euterpe can increase the first element to obtain the sequence 5–,45_,4, which has 22 different elements.

In the third test case, Euterpe can increase the second, fifth and sixth element to obtain the sequence 1,2–,3,4,5–,6–1,2_,3,4,5_,6_, which has 66 different elements.

code:

#include<bits/stdc++.h>
using namespace std;
int a[100005];
int main()
{

    int T, n, sum = 0;
    set<int> S;
    cin >> T;
    while(T--)
    {
        S.clear();
        memset(a, 0, sizeof(a));
        scanf("%d", &n);
        for(int i = 1; i <= n; i++)
            scanf("%d", &a[i]);
        for(int i = 1; i < n; i++)
        {
            if(a[i] == a[i - 1] && a[i] != a[i + 1])
            {
                a[i]++;
                S.insert(a[i]);
            }
            else
                S.insert(a[i]);
        }
        S.insert(a[n] + 1);
        //for(int i = 1; i <= n; i++)
           // cout << a[i] << " ";
        //cout << endl;
        cout << S.size() << endl;
    }
    return 0;
}

C. Canine poetry

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

After his wife's tragic death, Eurydice, Orpheus descended to the realm of death to see her. Reaching its gates was uneasy, but passing through them proved to be even more challenging. Mostly because of Cerberus, the three-headed hound of Hades.

Orpheus, a famous poet, and musician plans to calm Cerberus with his poetry and safely walk past him. He created a very peculiar poem for Cerberus. It consists only of lowercase English letters.

We call a poem's substring a palindrome if and only if it reads the same backwards and forwards. A string aa is a substring of a string bb if aa can be obtained from bb by deleting several (possibly zero or all) characters from the beginning and several (possibly zero or all) characters from the end.

Unfortunately, Cerberus dislikes palindromes of length greater than 11. For example in the poem abaa the hound of Hades wouldn't like substrings aba and aa.

Orpheus can only calm Cerberus if the hound likes his poetry. That's why he wants to change his poem so that it does not contain any palindrome substrings of length greater than 11.

Orpheus can modify the poem by replacing a letter at any position with any lowercase English letter. He can use this operation arbitrarily many times (possibly zero). Since there can be many palindromes in his poem, he may have to make some corrections. But how many, exactly? Given the poem, determine the minimal number of letters that have to be changed so that the poem does not contain any palindromes of length greater than 11.

Input

The first line of the input contains a single integer tt (1≤t≤1051≤t≤105) denoting the number of test cases, then tt test cases follow.

The first and only line of each test case contains a non-empty string of lowercase English letters, Orpheus' poem.

The sum of the length of Orpheus' poems in all test cases will not exceed 105105.

Output

You should output tt lines, ii-th line should contain a single integer, answer to the ii-th test case.

Example

input

Copy

7
babba
abaac
codeforces
zeroorez
abcdcba
bbbbbbb
a

output

Copy

1
1
0
1
1
4
0

Note

In the first test case, we can replace the third character with c and obtain a palindrome-less poem bacba.

In the second test case, we can replace the third character with d and obtain a palindrome-less poem abdac.

In the third test case, the initial poem already doesn't contain any palindromes, so Orpheus doesn't need to change anything there.

code:

#include<bits/stdc++.h>
using namespace std;
int main()
{
    string S;
    int T;
    cin >> T;
    while(T--)
    {
        S.clear();
        cin >> S;
        int ans  = 0;
        for(int i = 0; i < S.size(); i++)
        {
            if(i > 0 &&S[i] == S[i - 1] && S[i] != '0')
                S[i] = '0';
            else if(i > 1 && S[i] == S[i - 2] && S[i] != '0')
                S[i] = '0';
        }
        for(int i = 0; i < S.size(); i++)
            if(S[i] == '0')
                ans++;
        cout << ans << endl;
    }

    return 0;
}

 

内容概要:本文围绕“计及V2G主动支撑的光伏-储能-电动汽车输配协同日前优化调度”展开研究,提出了一种综合考虑光伏发电、储能系统与电动汽车(EV)在V2G(Vehicle-to-Grid)模式下协同参与电网调度的优化模型。通过Matlab代码实现,构建了日前优化调度框架,充分挖掘电动汽车作为移动储能单元的潜力,利用其双向充放电能力为主动配电网提供调峰、填谷和备用等主动支撑服务。研究综合考虑了可再生能源出力不确定性、负荷需求波动以及电动汽车出行行为特征,建立了多主体、多目标的协同优化机制,旨在降低系统运行成本、提高新能源消纳水平,并增强电网运行的稳定性与可靠性。该资源属于电力系统与综合能源系统领域的高水平科研复现资料,具备较强的理论深度与工程应用价值; 适合人群:具备电力系统分析、优化建模基础及Matlab编程能力的研究生、科研人员,以及从事智能电网、能源互联网、综合能源系统等相关领域技术研发的专业技术人员; 使用场景及目标:①用于学习和复现源---储协同优化调度的核心建模方法与求解流程;②掌握V2G技术在电网调频调峰中的数学建模方法及其在优化调度中的集成应用;③支撑光伏、储能与电动汽车耦合系统的低碳经济调度、鲁棒优化或分布鲁棒优化等前沿课题的研究与仿真验证; 阅读建议:建议结合文中提供的Matlab代码与主流优化工具箱(如YALMIP、CPLEX、Gurobi等)进行实践操作,重点理解目标函数设计、约束条件构建及多变量耦合关系的处理策略,同时可进一步拓展至日内滚动优化、实时调度或多时间尺度协调优化方向开展深入研究。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值