心路历程:一开始把签到的题目AC了,然后干A题,好家伙,到比赛结束都没有人AC掉A题qwq,1H过去了…然后是H题,这题还比较好过一点,然后又成功卡在了F题,我在题意上卡了好久(赛去打了场球后再看才明白在问什么QWQ)
总的来说,题目质量极佳,可惜就是我太菜
比赛链接
题解的链接
dalao的题解
TA
谁TM能想到这题是拿来防AK的啊啊
TD
找众数即可,众数一定是答案之一
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define N 110000
using namespace std;
int z,n,a[N],t,maxx=-1;
int main()
{
cin>>n;
for(int i=1;i<=n;i++)
{
scanf("%d",&t);
a[t]++;
if( maxx<a[t] )
{
maxx = a[t];
z = t;
}
}
if( a[z] == n ) cout<<-1;
else cout<<z;
return 0;
}
TF
二分找答案
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define LL long long
using namespace std;
string s1="01101001",s2="10010110";
LL m[100],t,ans;
int work(LL n,int x,int pd)
{
if( n<=8 )
{
if( pd==0 ) return s1[n-1]-'0';
else return s2[n-1]-'0';
}
if( n<=m[x-1] ) return work(n,x-1,pd);
else return work(n-m[x-1],x-1,1-pd);
}
int main()
{
LL n;
m[0] = 1;
for(int i=1;i<=62;i++)
{
m[i] = m[i-1]<<1;
}
cin>>t;
while(t--)
{
cin>>n;
n++;
int x = -1;
for(int i=1;i<=62;i++)
{
if( m[i-1]<n && m[i]>n )
{
x = i;
break;
}
}
if( x==-1 ) x = 63;
ans = work(n,x,0);
cout<<ans<<endl;
}
return 0;
}
当然如果找到规律更好
#include<iostream>
#include<cstdio>
#include<cstring>
#define LL long long
using namespace std;
LL n,m,sum1=0,sum0=0;
int main()
{
cin>>m;
while( m-- )
{
sum1 = 0;
scanf("%lld",&n);
while( n!=0 )
{
if( n%2==1 ) sum1++;
n >>= 1;
}
printf("%d\n",sum1%2);
}
return 0;
}
TI
关键是找到一个数左边第二个比它大的数,找第一个比它大的数可以用单调栈,找第二个可以稍微加点暴力…
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stack>
#define N 110000
#define INF 0x3f3f3f3f
using namespace std;
stack<int> s;
int n,m,a[N],l[N],ans[N];
int main()
{
int k;
cin>>n;
a[0] = 0x3f3f3f3f;
s.push(0);
for(int i=1;i<=n;i++)
{
scanf("%d",&a[i]);
while( a[ s.top() ] <= a[i] ) s.pop();
l[i] = s.top();
if( l[i] == 0 )
{
ans[i] = 1;
printf("1\n");
}
else
{
if( a[i]>a[i-1] && l[i]==l[i-1] ) k = ans[i-1] - 1;
else k = l[i]-1;
while( a[k] < a[i] ) k--;
ans[i] = k+1;
printf("%d\n",ans[i]);
}
s.push(i);
}
return 0;
}