*800*1000速攻

A. Cherry

A.樱桃

time limit per test: 1 second
每次测试的时间限制:1秒

memory limit per test: 256 megabytes
每次测试的内存限制:256兆字节

input. standard input
投入。标准输入

output: standard output
产出:标准产出

You are given n integers a1, a… Qn: Find the maximum value of max(a1, a…,ar) . min(a, a…ar) over all pairs
给出n个整数A1,a.QN:求最大值(A1,a.,ar)。所有对的最小(a,a,a.ar)

(I, r) of integers for which1≤l<r≤n.
(i,r)1≤l<r≤n的整数的(i,r)。

Input
输入

The first line contains a single integert(1 < t < 10 000) - - the number of test cases.
第一行包含一个整数(1<t<10 000)–测试用例的数量。

The first line of each test case contains a single integern(2≤n≤105).
每个测试用例的第一行包含一个整数(2≤n≤105)。

The second line of each test case contains n integers a,a…,an(1 < ai≤10°).
每个测试用例的第二行包含n个整数a,a.,an(1<ai≤10°)。

It is guaranteed that the sum of n over all test cases doesn’t exceed 3.10’.
保证所有测试用例上n的和不超过3.10‘。

Output
输出量

For each test case, print a single integer一the maximum possible value of the product from the statement.
对于每个测试用例,打印一个整数一,这是语句中产品的最大可能值。

滑动窗口法
区间增大无收益

int main()
{
   int t;
   cin>>t;
   while(t--)
   {
       int n;
       cin>>n;
       ll a,b;
       ll maxn=0;
       cin>>b;
       while(--n)
       {
           cin>>a;
           maxn=maxn>a*b?maxn:a*b;
           b=a;
       }
cout<<maxn<<endl;

   }
    return 0;
}

A. Digits Sum

A.数字和

time limit per test: 1 second
每次测试的时间限制:1秒

memory limit per test: 256 megabytes
每次测试的内存限制:256兆字节

input: standard input
输入:标准输入

output: standard output
产出:标准产出

Let’s define S(x) to be the sum of digits of number x witten in decimal system. For example,
让我们把S(X)定义为十进制中数字x Witten的数字之和。例如,

S(5)=5, S(10)= 1, S(322) = 7.
S(5)=5,S(10)=1,S(322)=7。

We will call an integer x interestingif S(x + 1) < S(x). In each test you will be given one
我们将调用一个整数x有趣的S(x+1)<S(X)。在每一次测试中,你都会得到一次。

integer n. Your task is to calculate the number of integers x such that 1 < x≤nand x is
您的任务是计算整数x的数目,以便1<x≤NANDx是

interesting.
有意思的。

Input
输入

The first line contains one integert(1 < t≤1000) - number of test cases.
第一行包含一个整数(1<t≤1000)-测试用例数。

Then t lines fllow, the ith line contains one integern(1≤n≤109) for the i-th test case.
然后t行变,第1行包含一个整数(1≤n≤109),用于第一次测试用例.

Output
输出量

Print t integers, the i -th should be the answer for the i-th test case.
打印t整数时,I-th应该是第一次测试用例的答案.

亦可赛艇数指加一进位的数

int main()
{
   int t;
   cin>>t;
   while(t--)
   {
      int a;
      cin>>a;
      a=(a+1)/10;
      cout<<a<<endl;

   }
    return 0;
}

A. Subsequence Permutation

A.子序列排列

time limit per test: 1 second
每次测试的时间限制:1秒

memory limit per test: 256 megabytes
每次测试的内存限制:256兆字节

input. standard input
投入。标准输入

output: standard output
产出:标准产出

A string s of length n, consisting of lowercase letters of the English alphabet, is given.
A string s of length n, consisting of lowercase letters of the English alphabet, is given.

You must choose some number k between 0 and n. Then, you select k characters of 8 and
您必须在0和n之间选择某个数字k,然后选择k个字符8和

permute them however you want. In this process, the positions of the other n一k characters
permute them however you want. In this process, the positions of the other n一k characters

remain unchanged. You have to perform this operation exactly once.
保持不变。你必须精确地执行这个操作一次。

For example, ifs = " andrea", you can choose the k = 4 characters “a_ d_ ea” and
For example, ifs = " andrea", you can choose the k = 4 characters “a_ d_ ea” and

permute them into “d_ e aa” so that after the operation the string becomes “dneraa” .
将它们转换为“d_e_aa”,以便操作后字符串变为“dneraa”。

Determine the minimum k so that it is possible to sort 8 alphabetically (that is, after the
确定最小k,以便按字母顺序对8进行排序(即,在

operation its characters appear in alphabetical order).
操作其字符按字母顺序显示)。

Input,
投入,

The first line contains a single integert(1≤t≤1000)- - the number of test cases. Then t
The first line contains a single integert(1≤t≤1000)- - the number of test cases. Then t

test cases follow.
接下来是测试用例。

The first line of each test case contains one integern(1≤n < 40)一the length of the string.
The first line of each test case contains one integern(1≤n < 40)一the length of the string.

The second line of each test case contains the string 8. It is guaranteed that 8 contains only
每个测试用例的第二行包含字符串8。

lowercase letters of the English alphabet.
英文字母的小写字母。

Output
输出量

For each test case, output the minimum k: that allows you to obtain a string sorted
对于每个测试用例,输出最小k:,这允许您获得排序的字符串。

alphabetically, through the operation described above.
按字母顺序,通过上面描述的操作。

即求与字典序有多少位不同

int main()
{
   int t;
   cin>>t;
   while(t--)
   {
       int e;
      string a,b;
      cin>>e>>a;
      b=a;
       std::sort(b.begin(), b.end());
       int k=0;
       for (int i = 0; i < b.size(); ++i) {
           if(a[i]!=b[i])++k;

       }
cout<<k<<endl;
   }
    return 0;
}

B1. Wonderful Coloring - 1

B1.奇妙的色彩-1

time limit per test: 1 second
每次测试的时间限制:1秒

memory limit per test: 256 megabytes
每次测试的内存限制:256兆字节

input. standard input
投入。标准输入

output: standard output
产出:标准产出

This is a simpliied version of the problem B2. Perhaps you should read the problem B2 before
这是问题B2的简化版本。也许你应该先读一下问题B2。

you start so/ving B1.
从B1开始。

Paul and Mary have a favorite string 8 which consists of lowercase letters of the Latin alphabet.
保罗和玛丽有一个最喜欢的字符串8,由拉丁字母的小写字母组成。

They want to paint it using pieces of chalk of two colors: red and green. Let’s call a coloring of a
他们想用两种颜色的粉笔来粉刷:红色和绿色。让我们称其为

string wonderful if the following conditions are met:
如果满足以下条件,则字符串非常棒:

  1. each letter of the string is either painted in exactly one color (red or green) or isn’t painted,
    1.字符串的每一个字母要么用一种颜色(红色或绿色)涂,要么不画,

  2. each two letters which are painted in the same color are different;,
    2.同一颜色的两个字母各不相同;

  3. the number of letters painted in red is equal to the number of letters painted in green;
    3.红色字母数等于绿色字母数;

  4. the number of painted ltters of this coloring is maximum among all colorings of the string
    4.在字符串的所有颜色中,这种着色的着色者的数量最大。

which meet the first three conditions .
符合前三个条件。

E. g. consider a string 8 equal to “kzaaa”. One of the wonderful colorings of the string is
E. g. consider a string 8 equal to “kzaaa”. One of the wonderful colorings of the string is

shown in the figure.
如图所示。

在这里插入图片描述

The example of a wonderful coloring of the string “kzaaa”.
字符串“kzaaa”精彩着色的例子。

Paul and Mary want to learn by themselves how to find a wonderful coloring of the string. But .
保罗和玛丽想自己学习如何找到一种奇妙的色彩的字符串。但是。

they are very young, S0 they need a hint. Help them find k一the number of red (or green,
他们很年轻,他们需要一点提示。帮助他们找到红色(或绿色)的数字k一,

these numbers are equal) letters in a wonderful coloring.
这些数字是相等的)字母在一个奇妙的颜色。

Input
输入

The first line contains one integert(1 < t < 1000)- the number of test cases. Then t test
第一行包含一个整数(1<t<1000)–测试用例的数量。然后t检验

cases follow.
案件接踵而至。

Each test case consists of one non-empty string 8 which consists of lowercase letters of the
每个测试用例由一个非空字符串8组成,该字符串由

Latin alphabet. The number of characters in the string doesn’t exceed 50.
拉丁字母。字符串中的字符数不超过50个。

如果某只有一个必须有另一个同样只有一个的单词才可涂色,数量多于一个字母红绿个图一个

int lib[26];
int main()
{
    int t;
    cin >> t;
    while (t--)
    {
        string s;
        cin >> s;
        for(int i=0;i<26;++i)
            lib[i]=0;
        for (char c : s) lib[c - 'a']++;
        int cnt1 = 0;
        int cnt2 = 0;
        for (int i = 0; i < 26; i++)
            if (lib[i] == 1)
                cnt1++;
            else if (lib[i] > 0)
                cnt2++;
            cout << (cnt2 + cnt1 / 2) << endl;
    }
    return 0;
}

A. Polycarp and Coins

A.鲤鱼和硬币

time limit per test: 1 second
每次测试的时间限制:1秒

memory limit per test: 256 megabytes
每次测试的内存限制:256兆字节

input: standard input
输入:标准输入

output: standard output
产出:标准产出

Polycarp must pay exactly n burles at the checkout. He has coins of two nominal values: 1
波利卡必须在结账时支付准确的伯勒斯。他有两个面值的硬币:1

burle and 2 burles. Polycarp likes both kinds of coins equally. So he doesn’t want to pay with
Burle和2 Burles。波利哥同样喜欢这两种硬币。所以他不想用

more coins of one type than with the other.
一种硬币比另一种硬币多。

Thus, Polycarp wants to minimize the difference between the count of coins of 1 burle and 2
因此,Polycarin希望将1 Burle硬币和2枚硬币的数量之差降到最低。

burles being used. Help him by determining two non-negative integer values C1 and C2 which
伯勒斯被利用了。通过确定两个非负整数值c1和c2来帮助他

are the number of coins of 1 burle and 2 burles, respectively, so that the total value of that
分别是1 Burle和2 Burles的硬币数,所以它的总价值是

number of coins is exactly n(i.e. C1 +2.C2 = n), and the absolute value of the difference
硬币的数目正好是n(即C1+2.C2=n),以及差额的绝对值。

between C1 and C2 is as ltte as possible (. e. you must minimize |C1 - C2|).
在C1和C2之间尽可能地作为猛虎组织(LTTE)。E.你必须最小化C1-C2)。

Input
输入

The first line contains one integert(1 < t≤10*)- the number of test cases. Then t test
第一行包含一个整数(1<t≤10*)–测试用例的数量。然后t检验

cases follow.
案件接踵而至。

Each test case consists of one line. This line contains one integern(1≤n≤109)- - the
每个测试用例由一行组成。这一行包含一个整数(1≤n≤109)–

number of burles to be paid by Polycarp.
波利卡公司将支付的Burles数量。

Output
输出量

For each test case, output a separate line containing two integersC1 andC2(C1,C2≥0)
对于每个测试用例,输出一个单独的行,其中包含两个整数C1和C2(C1,C2≥0)

separated by a space where C1 is the number of coins of 1 burle and C2 is the number of coins
用空格分隔,其中C1是1 Burle的硬币数,C2是硬币的数目。

of 2 burles. If there are multiple optimal solutions, print any one.
两个Burles。如果有多个最优解,请打印任意一个。

模三即可

int main()
{
    int t;
    cin >> t;
    while (t--)
    {
        ll a,b,c;
        cin>>c;
        a=b=c/3;
        if(c%3==1)
            ++a;
        else if(c%3==2)
            ++b;
        cout<<a<<" "<<b<<endl;
    }
    return 0;
}

A. Group of Students

A.学生群体

time limit per test: 1 second
每次测试的时间限制:1秒

memory limit per test: 256 megabytes
每次测试的内存限制:256兆字节

input. standard input
投入。标准输入

output: standard output
产出:标准产出

At the beginning of the school year Berland State University starts two city school programming
在学年开始时,伯兰州立大学开始了两所城市学校的规划

groups, for beginners and for intermediate coders. The children were tested in order to sort
团体,初学者和中级程序员。为了对孩子们进行排序,对他们进行了测试。

them into groups. According to the results, each student got some score from 1 to m points. We
他们分成几组。根据结果,每个学生在1到m之间得到了一些分数。我们

know that C1 schoolchildren got 1 point, C2 children got 2 points, - Cm children got m points.
知道C1学童得了1分,C2儿童得了2分,-cm儿童得了m分。

Now you need to set the passing rate k (integer from 1 to m). all schoolchildren who got less
现在您需要设置通过率k(整数从1到m)。所有收入较少的学童

than k points go to the beginner group and those who get at strictly least k points go to the
而不是k点给初学者组,而那些严格意义上至少得到k点的人去了

intermediate group. We know that if the size of a group is more than y, then the university won’t
中间基团我们知道,如果一个群体的规模超过y,那么大学就不会

find a room for them. We also know that if a group has less than x schoolchildren, then it is too
给他们找个房间。我们也知道,如果一个群体的学生少于x,那么它也是如此。

small and there’s no point in having classes with it. So, you need to split all schoolchildren into
很小,没有必要用它来上课。所以,你需要把所有的学生

two groups so that the size of each group was from x to y, inclusive .
两组,使每组的大小从x到y,包括在内。

Help the university pick the passing rate in a way that meets these requirements.
帮助大学选择符合这些要求的通过率。

Input
输入

The first line contains integer m (2≤m < 100). The second line contains m integers C1, C2…
第一行包含整数m(2≤m<100)。第二行包含m个整数C1,C2.

Cm, separated by single spaces (0≤c;S 100). The third line contains two space- separated
厘米,由单个空格分隔(0≤c;S 100)。第三行包含两个分隔的空格。

integers x andy(1≤x≤y≤10000). At least one Cq is greater than 0.
整数x Andy(1≤x≤y≤10000)。至少一个CQ大于0。

Output
输出量

If it is impossible to pick a passing rate in a way that makes the size of each resulting groups at
如果不可能选择一个通过率使每个结果组的大小在

least x and at mosty, print 0. Otherwise, print an integer from 1 to m一the passing rate you’d
至少x,在最拥挤的地方,打印0。否则,将整数从1打印到m一,即您想要的通过率。

like to suggest. If there are multiple possible answers, print any of them.
我想建议。如果有多个可能的答案,请打印其中任何一个。

模拟

int a[103];
int main()
{
    int t;
    cin >> t;

int sum=0;
    for (int i = 0; i < t; ++i) {
       cin>>a[i];
       sum+=a[i];
    }
    int f=0;
    int e=0;
    int x,y;
    cin>>x>>y;
    for (int i = 0; i < t; ++i)
    {
        e+=a[i];
        if(e<=y&&e>=x&&sum-e<=y&&sum-e>=x)
        {
            f=i+2;
            break;
        }
    }
    if(f==0)
        cout<<0<<endl;
    else
        cout<<f<<endl;
    return 0;
}

B. Maximum Cost Deletion

B.最大费用删除

time limit per test: 2 seconds
每次测试的时间限制:2秒

memory limit per test: 256 megabytes
每次测试的内存限制:256兆字节

input. standard input
投入。标准输入

output: standard output
产出:标准产出

You are given a string 8 of length n consisting only of the characters 0 and 1.
您将得到一个长度为n的字符串8,该字符串仅由字符0和1组成。

You perform the following operation until the string becomes empty: choose some consecutive
执行以下操作,直到字符串变为空为止:选择连续的

substring of equal characters, erase it from the string and glue the remaining two parts
等号字符的子字符串,将其从字符串中删除,并将剩下的两部分粘合在一起。

together (any of them can be empty) in the same order. For example, if you erase the substring
(它们中的任何一个都可以是空的)以相同的顺序组合在一起。例如,如果删除子字符串

111 from the string 111110, you will get the string 110. When you delete a substring of
从字符串111110中,您将得到字符串110。当您删除

length l, you geta.l + b points.
长度l,你得到。l+b点。

Your task is to calculate the maximum number of points that you can score in total, if you have
如果你有,你的任务是计算你能得到的最大积分数。

to make the given string empty.
使给定字符串为空。

Input
输入

The first line contains a single integert(1 < t≤2000)一the number of testcases.
第一行包含一个整数(1<t≤2000),一测试用例的数量。

The first line of each testcase contains three integers n, a and b (
每个测试用例的第一行包含三个整数n、a和b(

1≤n≤100;-100< a,b≤100)- the length of the string 8 and the parameters a and b.
1≤n≤100;-100<a,b≤100)-字符串8的长度和参数a和b。

The second line contains the string 8. The string 8 consists only of the characters 0 and 1.
第二行包含字符串8,字符串8只包含字符0和1。

Output
输出量

For each testcase, print a single integer一the maximum number of points that you can score.
For each testcase, print a single integer一the maximum number of points that you can score.

单纯形 线性规划
总la已定,故尽量多分组或尽量少分组*

int main()
{
    int t;
    cin >> t;
    while (t--)
    {
        int n, a, b;
        string s;
        cin >> n >> a >> b >> s;
        int m = unique(s.begin(), s.end()) - s.begin();
        cout << n * a + max(n * b, (m / 2 + 1) * b) << '\n';
    }

    return 0;
}

A. Contest Start

A.比赛开始

time limit per test: 1 second
每次测试的时间限制:1秒

memory limit per test: 256 megabytes
每次测试的内存限制:256兆字节

input: standard input
输入:标准输入

output: standard output
产出:标准产出

There are n people participating in some contest, they start participating in x minutes intervals. That means the first participant starts at
There are n people participating in some contest, they start participating in x minutes intervals. That means the first participant starts at

time 0, the second participant starts at time x, the third- at time 2●x, and S0 on.
时间0,第二个参与者从时间x开始,第三个参与者在时间2x开始,S0开始。

Duration of contest is t minutes for each participant, so the first participant finishes the contest at time t, the second- at timet + x, and
比赛持续时间为每一位参赛者不分,因此第一位参赛者在t时完成比赛,第二位在TIMET+x时完成比赛,以及

so on. When a participant finishes the contest, their dissatisfaction equals to the number of participants that started the contest (or starting
就这样吧。当参赛者完成比赛时,他们的不满等于开始比赛的人数(或开始)。

now), but haven’t yet finished it.
但还没有完成。

Determine the sum of dissatifaction of all participants.
确定所有参与者不满的总和。

Input
输入

The first line contains a single integerk(1 < k < 1000)- the number of test cases.
第一行包含一个整数(1<k<1000)–测试用例的数量。

Each of the next k lines contains three integersn, x, t(1 < n,x,t < 2. 109)- - the number of participants, the start interval and the
下一个k行包含三个整数n,x,t(1<n,x,t<2.109)–参与者数,起始间隔和

contest duration.
比赛持续时间。

Output
输出量

Print k lines, in the i-th line print the total dissatisfaction of participants in the i-th test case.
打印k行,在第一行中打印第一测试用例参与者的总体不满.

等差数列求和
n|x/t|-|x/t|(|x/t|+1)/2*

int main()
{
    int k;
    cin >> k;
    while (k--)
    {
        int n,x,t;
        cin>>n>>x>>t;
        ll e=t/x;
        cout<<e*n-(ll)(e*(e+1)*0.5)<<endl;
    }
//int sum=0;
//    for (int i = 0; i < t; ++i) {
//       cin>>a[i];
//       sum+=a[i];
//    }

    return 0;
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值