• codeforces#327 div2


    codeforces#327 div2 

    这场状态不好有点可惜,题目都不难,而且很好。。

    A题:水题。

    #include<bits/stdc++.h>
    #define REP(i,a,b) for(int i=a;i<=b;i++)
    #define MS0(a) memset(a,0,sizeof(a))
    #define lson l,m,rt<<1
    #define rson m+1,r,rt<<1|1
    
    using namespace std;
    
    typedef long long ll;
    const int maxn=1000100;
    const int INF=(1<<29);
    const double EPS=0.000000000001;
    const double Pi=acos(-1.0);
    
    int l,p,q;
    
    int main()
    {
        //freopen("in.txt","r",stdin);
        while(cin>>l>>p>>q){
            printf("%.5f
    ",l*1.0*p/(p+q));
        }
        return 0;
    }
    View Code

    B题:水题。居然卡了,状态真差。。。

    #include<bits/stdc++.h>
    #define REP(i,a,b) for(int i=a;i<=b;i++)
    #define MS0(a) memset(a,0,sizeof(a))
    #define lson l,m,rt<<1
    #define rson m+1,r,rt<<1|1
    
    using namespace std;
    
    typedef long long ll;
    const int maxn=200100;
    const int INF=(1<<29);
    const double EPS=0.000000000001;
    const double Pi=acos(-1.0);
    
    int n,q;
    int val[26];
    char s[maxn];
    int len;
    char u,v;
    char op[maxn];
    
    int main()
    {
        //freopen("in.txt","r",stdin);
        while(cin>>n>>q){
            scanf("%s",s);
            len=strlen(s);
            REP(i,0,25) val[i]=i;
            gets(op);
            while(q--){
                //cin>>u>>v;
                gets(op);
                u=op[0],v=op[2];
                u-='a';v-='a';
                REP(i,0,25){
                    if(val[i]==u) val[i]=v;
                    else if(val[i]==v) val[i]=u;
                }
            }
            REP(i,0,len-1){
                s[i]=val[s[i]-'a']+'a';
            }
            printf("%s
    ",s);
        }
        return 0;
    }
    View Code

    C题:水题。这个有思路,但是想着点到分心了。。

    #include<bits/stdc++.h>
    #define REP(i,a,b) for(int i=a;i<=b;i++)
    #define MS0(a) memset(a,0,sizeof(a))
    #define lson l,m,rt<<1
    #define rson m+1,r,rt<<1|1
    
    using namespace std;
    
    typedef long long ll;
    const int maxn=1000100;
    const int INF=(1<<29);
    const double EPS=0.000000000001;
    const double Pi=acos(-1.0);
    
    int n,a[maxn];
    
    int main()
    {
        //freopen("in.txt","r",stdin);
        while(cin>>n){
            REP(i,1,n) scanf("%d",&a[i]);
            int ans=0;
            for(int i=2;i<n;i++){
                if(a[i]^a[i-1]&&a[i]^a[i+1]){
                    int l=i-1,r=i+1;
                    while(l-1>=1&&a[l]^a[l-1]) l--;
                    while(r+1<=n&&a[r]^a[r+1]) r++;
                    //cout<<l<<" "<<r<<endl;
                    if((r-l+1)&1){
                        REP(j,l,r) a[j]=a[r];
                        ans=max((r-l+1)/2,ans);
                    }
                    else{
                        int m=(l+r)/2;
                        REP(j,l,m) a[j]=a[l];
                        REP(j,m+1,r) a[j]=a[r];
                        ans=max((r-l+1)/2-1,ans);
                    }
                    i=r;
                }
            }
            cout<<ans<<endl;
            REP(i,1,n){
                if(i!=n) printf("%d ",a[i]);
                else printf("%d
    ",a[i]);
            }
        }
        return 0;
    }
    View Code

    D题:二分时间t。因为位移和运动轨迹并没有关系,位移也是满足矢量合成的,直接分解也可以。注意二分三分都写成for循环上1000次,不要带EPS,这样可以防止TLE。

    #include<bits/stdc++.h>
    #define REP(i,a,b) for(int i=a;i<=b;i++)
    #define MS0(a) memset(a,0,sizeof(a))
    #define lson l,m,rt<<1
    #define rson m+1,r,rt<<1|1
    
    using namespace std;
    
    typedef long long ll;
    const int maxn=1000100;
    const int INF=(1<<29);
    const double EPS=0.0000000001;
    const double Pi=acos(-1.0);
    
    double X1,Y1,X2,Y2;
    double vm,t1;
    double vx,vy,wx,wy;
    
    double dist(double x,double y,double x0,double y0)
    {
        double tx=x-x0,ty=y-y0;
        return sqrt(tx*tx+ty*ty);
    }
    
    bool check(double t)
    {
        if(t<t1+EPS){
            double x=X2-vx*t,y=Y2-vy*t;
            double d=dist(x,y,X1,Y1);
            //printf("%.1f %.1f %.1f %.1f %.1f %.1f %.1f 
    ",x,y,d,X1,Y1,X2,Y2);
            if(vm*t>d-EPS) return 1;
            return 0;
        }
        else{
            double x0=X2-vx*t1,y0=Y2-vy*t1;
            double x=x0-wx*(t-t1),y=y0-wy*(t-t1);
            double d=dist(x,y,X1,Y1);
            if(vm*t>d-EPS) return 1;
            return 0;
        }
    }
    
    double bin(double l,double r)
    {
        double res=r;
        REP(i,1,1000){
            double m=(l+r)/2;
            if(check(m)) res=r=m;
            else l=m;
        }
        return res;
    }
    
    int main()
    {
        //freopen("in.txt","r",stdin);
        while(cin>>X1>>Y1>>X2>>Y2>>vm>>t1>>vx>>vy>>wx>>wy){
            double t=bin(0,INF);
            printf("%.7f
    ",t);
        }
        return 0;
    }
    View Code

    E题:bfs预处理出每个点到三个国家的距离即可,然后路的长度就是三个距离直接加。

    #include<bits/stdc++.h>
    #define REP(i,a,b) for(int i=a;i<=b;i++)
    #define MS0(a) memset(a,0,sizeof(a))
    #define lson l,m,rt<<1
    #define rson m+1,r,rt<<1|1
    
    using namespace std;
    
    typedef long long ll;
    const int maxn=1100;
    const int INF=(1<<29);
    const double EPS=0.0000001;
    const double Pi=acos(-1.0);
    
    int n,m;
    char ch[maxn][maxn];
    int d[3][maxn][maxn];
    bool vis[maxn][maxn];
    int dx[]={-1,1,0,0};
    int dy[]={0,0,-1,1};
    struct Node
    {
        int x,y;
        int step;
    };
    
    void bfs(char c)
    {
        memset(d[c-'1'],-1,sizeof(d[c-'1']));
        MS0(vis);
        queue<Node> q;
        REP(i,1,n){
            REP(j,1,m){
                if(ch[i][j]==c) q.push({i,j,0}),vis[i][j]=1;
            }
        }
        while(!q.empty()){
            Node u=q.front();
            q.pop();
            d[c-'1'][u.x][u.y]=u.step;
            REP(i,0,3){
                int nx=u.x+dx[i],ny=u.y+dy[i];
                if(ch[nx][ny]=='#'||vis[nx][ny]) continue;
                vis[nx][ny]=1;
                q.push({nx,ny,u.step+1});
            }
        }
    }
    
    void debug(char c)
    {
        cout<<endl;
        REP(i,1,n){
            REP(j,1,m){
                printf("%2d",d[c][i][j]);
            }
            cout<<endl;
        }
    }
    
    void deal()
    {
        int r1=INF,r2=INF;
        REP(i,1,n){
            REP(j,1,m){
                if(ch[i][j]=='1'){
                    r1=min(d[1][i][j],r1);
                    r2=min(d[2][i][j],r2);
                }
            }
        }
        REP(i,1,n) REP(j,1,m) if(ch[i][j]=='1') d[1][i][j]=r1,d[2][i][j]=r2;
        r1=INF,r2=INF;
        REP(i,1,n){
            REP(j,1,m){
                if(ch[i][j]=='2'){
                    r1=min(d[0][i][j],r1);
                    r2=min(d[2][i][j],r2);
                }
            }
        }
        REP(i,1,n) REP(j,1,m) if(ch[i][j]=='2') d[0][i][j]=r1,d[2][i][j]=r2;
        r1=INF,r2=INF;
        REP(i,1,n){
            REP(j,1,m){
                if(ch[i][j]=='3'){
                    r1=min(d[0][i][j],r1);
                    r2=min(d[1][i][j],r2);
                }
            }
        }
        REP(i,1,n) REP(j,1,m) if(ch[i][j]=='3') d[0][i][j]=r1,d[1][i][j]=r2;
    }
    
    int main()
    {
       // freopen("in.txt","r",stdin);
        while(cin>>n>>m){
            memset(ch,'#',sizeof(ch));
            REP(i,1,n){
                REP(j,1,m) cin>>ch[i][j];
            }
            bfs('1');bfs('2');bfs('3');
            deal();
            //debug(0);debug(1);debug(2);
            int ans=INF;
            REP(i,1,n){
                REP(j,1,m){
                    bool tag=1;
                    REP(k,0,2){
                        if(d[k][i][j]==-1) tag=0;
                    }
                    if(!tag) continue;
                    int tmp=0;
                    tmp=d[0][i][j]+d[1][i][j]+d[2][i][j]-3+1;
                    ans=min(ans,tmp);
                }
            }
            if(ans==INF) puts("-1");
            else cout<<ans<<endl;
        }
        return 0;
    }
    View Code

    做题稳定性有待提升。

    没有AC不了的题,只有不努力的ACMER!
  • 相关阅读:
    python 获取项目的根路径
    信息系统项目管理师-1.4软件工程
    信息系统项目管理师
    信息系统项目管理师-导学
    信息系统项目管理师-考试安排
    读取text行列
    pipeline基本框架思维
    Linux压缩隐藏文件
    python+appium环境搭建
    leetcode for mysql
  • 原文地址:https://www.cnblogs.com/--560/p/4913054.html
Copyright © 2020-2023  润新知