腾讯赞助周|牛客编程巅峰赛最后1场AB题

A题:
bool judge(int x) {
// write code here
if(1<=x<9) return true;
int res1=x%10,res2=0;
while(x>=10)
{
x/=10;
}
res2=x;
return res1==res2?true:false;
}

B题:
int countTriplets(vector<int>& arr, int a, int b) {
// write code here
long long res=0;
long long mod=1000000007;
int len=arr.size();
//sort(arr.begin(),arr.end());//升序
for(int j=0;j<len;j++)
{
int x=0,y=0;
for(int i=0;i<j;i++)
{
if(abs(arr[i]-arr[j])<=a)
x++;
}
for(int i=j+1;i<len;i++)
{
if(abs(arr[i]-arr[j])<=b)
y++;
}
res=(res+x*y)%mod;
}
return res;
}


#牛客编程巅峰赛##题解#
全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务