[2018-4-8]BNUZ套题比赛div2 【补题】

不知道怎么了,脑子是傻了吗,又一次零封了,很难受,是自己最近学习方法错了吗,就感觉现在看到题就没什么思路,就想着暴力暴力,然后那些好的办法也想不出来,真的心累。。是自己再多刷刷水题?要么以后尝试每天做两道cf水题?真的不知道错在哪里了。。

A. Check the string
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

A has a string consisting of some number of lowercase English letters 'a'. He gives it to his friend B who appends some number of letters 'b' to the end of this string. Since both A and B like the characters 'a' and 'b', they have made sure that at this point, at least one 'a' and one 'b' exist in the string.

B now gives this string to C and he appends some number of letters 'c' to the end of the string. However, since C is a good friend of A and B, the number of letters 'c' he appends is equal to the number of 'a' or to the number of 'b' in the string. It is also possible that the number of letters 'c' equals both to the number of letters 'a' and to the number of letters 'b' at the same time.

You have a string in your hands, and you want to check if it is possible to obtain the string in this way or not. If it is possible to obtain the string, print "YES", otherwise print "NO" (without the quotes).

Input

The first and only line consists of a string S (1 ≤ |S| ≤ 5 000). It is guaranteed that the string will only consist of the lowercase English letters 'a', 'b', 'c'.

Output

Print "YES" or "NO", according to the condition.

Examples
input
Copy
aaabccc
output
YES
input
Copy
bbacc
output
NO
input
Copy
aabc
output
YES
Note

Consider first example: the number of 'c' is equal to the number of 'a'.

Consider second example: although the number of 'c' is equal to the number of the 'b', the order is not correct.

Consider third example: the number of 'c' is equal to the number of 'b'.

题意:a有字符串,里面有只有a字符,然后给b,b可以向里面添加字符b在字符串后面,然后给c,c可以向
b给的字符串后面添加字符c题目中保证最后的字符串至少有一个a或者b,然后让你检查这个字符串是否合法。合法就是输出YES,否则NO。
    #include<bits/stdc++.h>  
    using namespace std;  
    int main()  
    {  
        string s;  
        cin>>s;  
        int a=0,b=0,c=0,flag=0,flag1=0,flag2=0;  
        for(int i=0; i<s.size(); i++)  
        {  
            if(s[i]=='a')  
            {  
                if(flag1||flag2)  
                {  
                    puts("NO");  
                    return 0;  
                }  
                a++,flag=1;  
            }  
            else if(s[i]=='b')  
            {  
                if(!flag||flag2)  
                {  
                    puts("NO");  
                    return 0;  
                }  
                b++,flag1=1;  
            }  
            else if(s[i]=='c')  
            {  
                if(!flag||!flag1)  
                {  
                    puts("NO");  
                    return 0;  
                }  
                c++,flag2=1;  
            }  
        }  
      
        if(c==a&&c||c==b&&b)///防止只有a那种情况,然后b=c=0会输出yes  
            puts("YES");  
        else puts("NO");  
        return 0;  
    }  
 

B. Minimize the error

time limit per test
1 second
memory limit per test
256 megabytes
input standard input
output standard output

You are given two arrays A and B, each of size n. The error, E, between these two arrays is defined . You have to perform exactly k1 operations on array A and exactly k2 operations on array B. In one operation, you have to choose one element of the array and increase or decrease it by 1.

Output the minimum possible value of error after k1 operations on array A and k2 operations on array B have been performed.

Input

The first line contains three space-separated integers n (1 ≤ n ≤ 103), k1 and k2 (0 ≤ k1 + k2 ≤ 103, k1 and k2 are non-negative) — size of arrays and number of operations to perform on A and B respectively.

Second line contains n space separated integers a1, a2, ..., an ( - 106 ≤ ai ≤ 106) — array A.

Third line contains n space separated integers b1, b2, ..., bn ( - 106 ≤ bi ≤ 106)— array B.

Output

Output a single integer — the minimum possible value of after doing exactly k1 operations on array A and exactly k2 operations on array B.

Examples
Input
Copy
2 0 0
1 2
2 3
Output
Copy
2
Input
Copy
2 1 0
1 2
2 2
Output
Copy
0
Input
Copy
2 5 7
3 4
14 4
Output
Copy
1
Note

In the first sample case, we cannot perform any operations on A or B. Therefore the minimum possible error E = (1 - 2)2 + (2 - 3)2 = 2.

In the second sample case, we are required to perform exactly one operation on A. In order to minimize error, we increment the first element of A by 1. Now, A = [2, 2]. The error is now E = (2 - 2)2 + (2 - 2)2 = 0. This is the minimum possible error obtainable.

In the third sample case, we can increase the first element of A to 8, using the all of the 5 moves available to us. Also, the first element of B can be reduced to 8 using the 6 of the 7 available moves. Now A = [8, 4] and B = [8, 4]. The error is now E = (8 - 8)2 + (4 - 4)2 = 0, but we are still left with 1 move for array B. Increasing the second element of B to 5 using the left move, we get B = [8, 5] and E = (8 - 8)2 + (4 - 5)2 = 1.


然后是b题 真的题都没看懂,心很累,感觉数学真的要加强,网上搜了题解,才明白题意,给你两个数字序列a,b,每个序列长度都为n,然后E=∑(a[i]-b[i])^2。现在你可以改变a,b序列中的元素k1次和k2次,每次可以使一个元素加一或者减一。使得改变结束之后E的值最小,网上找了代码,自己摸索感觉大概懂了。。过两天再看看吧

A. A Compatible Pair

Nian is a monster which lives deep in the oceans. Once a year, it shows up on the land, devouring livestock and even people. In order to keep the monster away, people fill their villages with red colour, light, and cracking noise, all of which frighten the monster out of coming.

Little Tommy has n lanterns and Big Banban has m lanterns. Tommy's lanterns have brightness a1, a2, ..., an, and Banban's have brightness b1, b2, ..., bm respectively.

Tommy intends to hide one of his lanterns, then Banban picks one of Tommy's non-hidden lanterns and one of his own lanterns to form a pair. The pair's brightness will be the product of the brightness of two lanterns.

Tommy wants to make the product as small as possible, while Banban tries to make it as large as possible.

You are asked to find the brightness of the chosen pair if both of them choose optimally.

Input

The first line contains two space-separated integers n and m (2 ≤ n, m ≤ 50).

The second line contains n space-separated integers a1, a2, ..., an.

The third line contains m space-separated integers b1, b2, ..., bm.

All the integers range from  - 109 to 109.

Output

Print a single integer — the brightness of the chosen pair.

Examples
input
2 2
20 18
2 14
output
252
input
5 3
-1 0 1 2 3
-1 0 1
output
2

题意:现在有A,B两个数组,分别取一个数相乘,可以删掉A数组中一个元素,删除后从AB各挑一个数相乘让这个结果最大。这个题一开始就想着暴力,结果各种wa,想法失误,应该直接把所有结果存起来,直接取去掉一个数的最大值,唉,真的觉得都挺简单,结果就是各种卡题。。

    #include<bits/stdc++.h>  
    #define ll long long  
    using namespace std;  
    ll a[110],b[110],n,m,p1,p2,mmax;  
    int main()  
    {  
        while(~scanf("%lld%lld",&n,&m))  
        {  
            for(ll i=1;i<=n;i++)scanf("%lld",&a[i]);  
            for(ll i=1;i<=m;i++)scanf("%lld",&b[i]);  
            mmax=-9e18;  
            for(ll i=1;i<=n;i++)  
            {  
                for(ll j=1;j<=m;j++)  
                {  
                    if(a[i]*b[j]>mmax)  
                    {  
                        mmax=a[i]*b[j];  
                        p1=i;  
                        p2=j;  
                    }  
                }  
            }  
            mmax=-9e18;  
            for(ll i=1;i<=n;i++)  
            {  
                for(ll j=1;j<=m;j++)  
                {  
                    if(i==p1)continue;  
                    if(a[i]*b[j]>mmax)mmax=a[i]*b[j];  
                }  
            }  
            printf("%lld\n",mmax);  
        }  
        return 0;  
    }  
希望下次可以努力,别天天卡题了 真的难受
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值