[Updating] Tinkoff Challenge - Elimination Round 解题报告

Problem A- Oleg and shares

判断 Ai 是否满足 AiC(modK) 其中C为常数

//Author: Lixiang
#include<stdio.h>
#include<algorithm>
const int maxn=100001;
struct A{
    int a[maxn];
    int Min,N,K;
    void init(){
        Min=1000000000;
        scanf("%d%d",&N,&K);
        for(int i=1;i<=N;i++){
            scanf("%d",&a[i]);
            Min=std::min(a[i],Min);
        }
    }
    void work(){
        long long ans=0;
        int now=a[1]%K;
        for(int i=2;i<=N;i++)
            if(a[i]%K!=now){
                puts("-1");
                return;
            }
        for(int i=1;i<=N;i++)
            ans+=(a[i]-Min)/K;
        printf("%I64d\n",ans);
    }
}sol;
int main(){
    sol.init();
    sol.work();
    return 0;
}

Problem B - Igor and his way to work

判断是否能在最多两次转弯后到达目的地
BFS就行了

//Author: Lixiang
#include<stdio.h>
#include<queue>
using namespace std;
const int dx[]={0,0,1,-1};
const int dy[]={1,-1,0,0};
const int maxn=1001;
struct Node{
    short x,y;
    char s,last;
    Node make(int a,int b,int c,int la){
        x=a;y=b;s=c;last=la;
        return *this;
    }
}tmp;
struct B{
    queue <Node> Q;
    bool a[maxn][maxn],hash[maxn][maxn][5];
    int N,M,sx,sy,ex,ey;
    char s[maxn];
    void init(){
        scanf("%d%d",&N,&M);
        for(int i=1;i<=N;i++){
            scanf("%s",s+1);
            for(int j=1;j<=M;j++){
                if(s[j]=='*')a[i][j]=0;
                else{
                    a[i][j]=1;
                    if(s[j]=='S')sx=i,sy=j;
                    if(s[j]=='T')ex=i,ey=j;
                }
            }
        }
    }
    bool check(int x,int y){
        if(x>=1&&x<=N&&y>=1&&y<=M&&a[x][y]==1)return 1;
        else return 0;
    }
    void work(){
        int x,y,turns,nx,ny,la;
        Q.push(tmp.make(sx,sy,0,-1));
        //hash[sx][sy]=1;
        while(!Q.empty()){
            x=Q.front().x;y=Q.front().y;turns=Q.front().s;
            la=Q.front().last;
            if(la!=-1)hash[x][y][la]=0;
            Q.pop();
            for(int i=0;i<4;i++){
                nx=x+dx[i];ny=y+dy[i];
                if(!check(nx,ny))continue;
                if(hash[nx][ny][i])continue;
                if(nx==ex&&ny==ey){
                    puts("YES");
                    return ;
                }
                if(i==la){
                    Q.push(tmp.make(nx,ny,turns,i));
                    hash[nx][ny][i]=1;
                }
                else if(turns<=2){
                    if(turns==2&&nx!=ex&&ny!=ey)continue;
                    Q.push(tmp.make(nx,ny,turns+1,i));
                    hash[nx][ny][i]=1;
                }
            }
        }
        puts("NO");
    }
}sol;
int main(){
    sol.init();
    sol.work();
    return 0;
}

Problem C - Mice Problem

求出每个老鼠经过捕鼠器的时间段,找有没有重合的时间就行了

//Author: Lixiang
#include<stdio.h>
#include<algorithm>
using namespace std;
const int maxn=100001;
const double eps=1e-11;
double x1,y1,x2,y2,tmin,tmax;
struct Mice{
    double rx,ry,vx,vy;
    void init(){
        scanf("%lf%lf%lf%lf",&rx,&ry,&vx,&vy);
    }
    void update(double a,double b,double v){
        if(v==0){
            if(a<0&&b>0)return;
            tmax=-1;
        }
        double p=a/v,q=b/v;
        if(p>q)swap(p,q);
        tmin=max(tmin,p);
        tmax=min(tmax,q);
    }
    void Update(){
        update(x1-rx,x2-rx,vx);
        update(y1-ry,y2-ry,vy);
    }
};
struct C{
    Mice mice[maxn];
    int N;
    void init(){
        tmin=0;tmax=1e100;
        scanf("%d%lf%lf%lf%lf",&N,&x1,&y1,&x2,&y2);
        for(int i=1;i<=N;i++){
            mice[i].init();
            mice[i].Update();
        }
    }
    void work(){
        if(tmin+eps>tmax)puts("-1");
        else printf("%.20lf\n",tmin);
    }
}sol;
int main(){
    sol.init();
    sol.work();
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值