A:Three Pairwise Maximums
题意:给你三个整数x、y、z,然后需要找出三个数a、b、c,使这三个数满足 x=max(a,b), y=max(a,c) and z=max(b,c),或者确定这三个数不存在
思路:先排序,分三种情况:三个都一样;两个一样且大于第三个;其他。
#include <bits/stdc++.h>
using namespace std;
int x[4],a,b,c,t;
int main() {
cin>>t;
while(t--){
cin>>x[0]>>x[1]>>x[2];
sort(x,x+3);
//cout<<x[0]<<' '<<x[1]<<' '<<x[2];
if(x[0]==x[1]&&x[1]==x[2])
cout<<"YES"<<endl<<x[0]<<' '<<x[0]<<' '<<x[0]<<endl;
else
if(x[2]==x[1]&&x[1]>x[0])
cout<<"YES"<<endl<<x[0]<<' '<<1<<' '<<x[2]<<endl;
else
cout<<"NO"<<endl;
}
}
B:Restore the Permutation by Merger
题意:一个由互不相同的数组成的数组,按原本顺序插入到自身数组。例如:排列p:[3,1,2],则两个排列合并的可能情况有[3,1,2,3,1,2]、[3,3,1,1,2,2]、[3,1,3,1,2,2],要你还原出原本的排列。
思路:找到第一次出现的数,直接输出。
代码:
#include <bits/stdc++.h>
using namespace std;
int t,n,a[110],b[60];
int main() {
cin>>t;
while(t--){
cin>>n;
memset(b,0,sizeof(b));
for(int i=1;i<=2*n;i++){
cin>>a[i];
if(b[a[i]]==0){
cout<<a[i]<<' ';
b[a[i]]=1;
}
}
cout<<endl;
}
}
C:Make It Good
题意:数组a删除若干前缀,使得删除后的数组取数组“头/尾”数呈非递减序列。
思路:想岔了,想用单调队列来着,没整明白。从后往前看,要求数组先增后减即可。
代码:
#include<bits/stdc++.h>
using namespace std;
int main() {
int t,v[200010];
cin >> t;
while (t--) {
int n;
cin >> n;
int i;
for (i = 0; i < n; i++) {
cin >> v[i];
}
i = n - 1;
while (i > 0 && v[i] <= v[i - 1]) {
i--;
}
while (i > 0 && v[i] >= v[i - 1]) {
i--;
}
int ans = i;
cout << ans << endl;
}
return 0;
}
D:a-Good String
题解:二分+贪心
感受:好久没打cf了,C题做不出来挺不应该的,看完题目是有想到摆动数组的,然后就莫名奇妙思维联想到之前看的优先队列了,结果把自己弄惨了。以至于后面看D题的时候心态有点炸,就挺烦的。明天争取打的好一点吧