Codeforces Goodbye 2018

时间:2019-11-14
本文章向大家介绍Codeforces Goodbye 2018,主要包括Codeforces Goodbye 2018使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

比赛传送门

终于摆脱\(pupil\)!成为\(Specialist\)

元旦\(RP++\)


A.New Year and the Christmas Ornament

没什么好说的,送分题

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main(){
    int y,b,r,ans=0;
    cin>>y>>b>>r;
    ans+=min(y,min(b-1,r-2))*3+1+2;
    cout<<ans;
    return 0;
}

B.New Year and the Treasure Geolocation

因为每个向量和每个坐标都是一一对应的,而它们又都指向目标地点,所以我们枚举目标地点就好了。
我们用第一个坐标去试每个向量,找出目标地点,再判断目标地点是否合法,即目标地点对于每一个向量,都有一个坐标对应
偷懒用\(map\)

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
using namespace std;
map <int,map<int,bool> > q;
int a[1010],b[1010],xx,yy;
int main(){
    int n; cin>>n;
    for(int i=1;i<=n;i++){
        int x,y;
        scanf("%d%d",&x,&y);
        if(i==1) xx=x,yy=y;
        q[x][y]=1;
    }
    for(int i=1;i<=n;i++) cin>>a[i]>>b[i];
    for(int i=1;i<=n;i++){
        int ansx=xx+a[i],ansy=yy+b[i];
        bool flag=0;
        for(int j=1;j<=n;j++){
            if(!q[ansx-a[j]][ansy-b[j]]){
                flag=1; break;
            }
        }
        if(flag) continue;
        else{
            cout<<ansx<<" "<<ansy;
            return 0;
        }
    }
    return 0;
}

C.New Year and the Sphere Transmission

虽然我不会证,但我会猜结论啊!

\(10^9\)的数据范围,不是\(O(\sqrt n)\)就是\(O(\log n)\)
再根据这道题的实际情况,可以猜出\(k\)只跟\(n\)的因数有关。
要快速的算出“快乐值”,可以用等差数列求和公式

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
#include<cmath>
#define LL long long
using namespace std;
LL read(){
    LL k=0; char c=getchar();
    while(c<'0'||c>'9') c=getchar();
    while(c>='0'&&c<='9')
      k=k*10+c-48,c=getchar();
    return k;
}
LL a[100010],tot,ans[100100];
int main(){
    LL n=read();
    for(int i=1;i<=sqrt(n);i++)
      if(n%i==0)
        a[++tot]=i,a[++tot]=n/i;
    for(int i=1;i<=tot;i++)        
      ans[i]=(1+(n-a[i]+1))*(n/a[i])/2; //等差数列求和公式
    sort(ans+1,ans+tot+1);
    int pos=unique(ans+1,ans+tot+1)-ans-1;
    for(int i=1;i<=pos;i++) cout<<ans[i]<<" ";
    return 0;
}

原文地址:https://www.cnblogs.com/morslin/p/11855028.html