题目列表
1.A. Integer Diversity-Good Bye 2021: 2022 is NEAR
题解:
整数多样性。用map建立一个映射,如果这个数用过就标记1。我们只需要从头开始输入,然后判断这个数如果没有出现ans++并把map设为1,如果出现过判断这个数的负数在map中是否出现,如果出现就过,如果没有出现,置1并ans++。
AC代码:
#include <iostream>
#include <string>
#include <string.h>
#include <cmath>
#include <math.h>
#include <iomanip>
#include <cstdio>
#include <stdlib.h>
#include <algorithm>
#include <map>
using namespace std;
#define ll long long
map<int,int> it;
int n,m;
int main()
{
// freopen("1.txt","r",stdin);
int t;
int i1,i2,i3,i4,i5;
cin>>t;
while(t--)
{
cin>>n;
int ans=0;
it.clear();
for(i1=1;i1<=n;i1++)
{
cin>>i2;
if(it[i2]==0) {it[i2]=1;ans++;continue;}
if(it[-i2]==0) {it[-i2]=1;ans++;continue;}
}
cout<<ans<<endl;
}
return 0;
}
2.B. Mirror in the String-Good Bye 2021: 2022 is NEAR
题解:
从头开始找如果是递减的就继续向后找,否则就加上逆序然后输出。但是有一种特殊情况,就是前两个字符相等,就直接输出前两个。找最小的序列还要把序列的逆序加上,这个特性说明了有的序列虽然短但是不一定是最小的,只有当两个序列前面的同样大小时短的才是序列小的,也就是这种特殊情况。所以咱们可以放心的找下降的序列了。
总结:
这题看的题解,想了很长时间也不会,确实是想不到,其实长的只要是递减的会很小,一直被bbaa这个特殊情况卡住了,总想着找一个普遍的公式。
AC代码:
#include <iostream>
#include <string>
#include <string.h>
#include <cmath>
#include <math.h>
#include <iomanip>
#include <cstdio>
#include <stdlib.h>
#include <algorithm>
using namespace std;
#define ll long long
string x;
int n,m;
int main()
{
// freopen("1.txt","r",stdin);
int t;
int i1,i2,i3,i4,i5;
cin>>t;
while(t--)
{
cin>>n;
cin>>x;
string y=x.substr(0,1);
// cout<<y<<endl;
for(i1=0;i1<x.size();i1++)
{
// cout<<x[i1]<<endl;
if(i1==0&&x[0]==x[1]) {i1=1;break;}
else
{
if(i1!=0)
if(x[i1]<=x[i1-1]) continue;
else break;
}
}
y=x.substr(0,i1);
reverse(y.begin(),y.end());
x=x.substr(0,i1);
x+=y;
cout<<x<<endl;
}
return 0;
}
3.C. Representative Edges-Good Bye 2021: 2022 is NEAR
题解:
代表性的边缘。题目中给出了一个公式,其实这个公式就是等差数列求和公式。╯▂╰。只需要出一个等差数列的首相a1和公差k使得改变的数最少就可以。具体怎么着就是贪心。因为等差数列在笛卡尔坐标系中就是一条直线,所以问题就转换为求直线的斜率和截距。首先确定两个点,然后判断剩下的点是否在该直线上,如果不在就改变,在的话就继续下一个数。可以看到如果确定了两个点,那第三个数的改变不会影响后面的判断。
总结:
服了( •̥́ ˍ •̀ू )嘤嘤嘤~。也是看的题解。没看出是等差数列求和公式,然后自己在推a1,a1+a2,一只算到a1+a7,都没看出规律。这题还有一个难点就是把等差数列转换为了求直线斜率。而且求直线斜率时要用x1y2=x2y1。
AC代码:
#include <iostream>
#include <string>
#include <string.h>
#include <cmath>
#include <math.h>
#include <iomanip>
#include <cstdio>
#include <stdlib.h>
#include <algorithm>
using namespace std;
#define ll long long
int n,m;
int a[100];
int main()
{
// freopen("1.txt","r",stdin);
int t;
int i1,i2,i3,i4,i5;
cin>>t;
while(t--)
{
cin>>n;
for(i1=1;i1<=n;i1++)
{
scanf("%d",&a[i1]);
}
if(n==1) {cout<<0<<endl;continue;}
/**
* !!!!!!!!
*
* !!!!!!!!
*
* !!!!!!!!
* !!!!!!!!特
* !!!!!!!! 判
* !!!!!!!! 啊
*!!!!!!!!
*
*!!!!!!!!
* !!!!!!!!
*/
int ans=INT_MAX;
for(i1=1;i1<n;i1++)
{
for(i2=i1+1;i2<=n;i2++)
{
int min1=0;
for(i3=1;i3<=n;i3++)
{
if((a[i1]-a[i3])*(i2-i3)!=(a[i2]-a[i3])*(i1-i3)) min1++;
}
ans=min(ans,min1);
}
}
cout<<ans<<endl;
}
return 0;
}