不知道怎么了,脑子是傻了吗,又一次零封了,很难受,是自己最近学习方法错了吗,就感觉现在看到题就没什么思路,就想着暴力暴力,然后那些好的办法也想不出来,真的心累。。是自己再多刷刷水题?要么以后尝试每天做两道cf水题?真的不知道错在哪里了。。
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).
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'.
Print "YES" or "NO", according to the condition.
aaabccc
YES
bbacc
NO
aabc
YES
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
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.
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 a single integer — the minimum possible value of after doing exactly k1 operations on array A and exactly k2 operations on array B.
2 0 0 1 2 2 3
2
2 1 0 1 2 2 2
0
2 5 7 3 4 14 4
1
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的值最小,网上找了代码,自己摸索感觉大概懂了。。过两天再看看吧
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.
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.
Print a single integer — the brightness of the chosen pair.
2 2 20 18 2 14
252
5 3 -1 0 1 2 3 -1 0 1
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;
}
希望下次可以努力,别天天卡题了 真的难受