AtCoder_abc326

· · 个人记录

A 2UP3DOWN

A题链接

简单的if判断,做题一分钟,翻译十分钟。。。

代码:

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int x,y;cin>>x>>y;
    if((x<=y&&y-x<=2)||(x>y&&x-y<=3))
        cout<<"Yes";
    else cout<<"No";
    return 0;
}

B 326-like Numbers

B题链接

循环枚举即可,依旧艰难地翻译

代码:

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    for(int i=n;i<=999;i++){
        if((i/100)*(i/10%10)==i%10){
            cout<<i;return 0;
        }
    }
    return 0;
}

做完前两道题然后提交,然后某个聪明蛋就发现交反了。。。。

C Peak

C题链接

枚举坐标,但有两个点需要注意:

  1. 输入坐标不一定是按顺序的,所以要sort();
  2. 如果二层循环枚举会超时,所以我用了lower_bound() 二分就不会T了

代码:

#include<bits/stdc++.h>
using namespace std;
int n,m,a[300005],ans;
int main()
{
    cin>>n>>m;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    sort(a+1,a+1+n);
    for(int i=1;i<=n;i++){
        int p=lower_bound(a+i,a+1+n,a[i]+m)-a-1;
        ans=max(ans,p-i+1);
    }
    cout<<ans;
    return 0;
}

T4 ABC Puzzle

这道翻译了好长时间没懂 然后没写完就寄了