zoukankan      html  css  js  c++  java
  • Codeforces Round 492 (Div.1)

    大概这一场考的还算可以吧..

    上来刚A...然后A死难写...

    然后B是水题..

    C猜了个结论错掉了,也找到了反例

    然后后面干脆的直接把数据random_shuffle以后再跑这个贪心...

    就过了...

    D..

    感谢Q巨...

    Q巨猜了个结论让我交了一发..

    然后过了...

    ========================================================

    A题

    给你一个4*n的网格图,第一行第四行是停车场

    第二行第三行是过道

    现在一共有k辆车(编号1~k)停在过道上,你需要把它们挪到正确的位置上

    你一旦将一辆车停入停车区,就不可以移动它,也就是说你必须让正确的车进入正确的位置

    求一个20000步以内的方案,n<=50,k<=2n

    做法;

    你可以考虑,整个2*n的区域直接把它变成一个环,

    例如上图

    把它变成

    1->2->0->4

    ^               |

    |               v

    5<-0<-0<-3

    的一个环,然后在这个环上每次移动一个车,顺便把前面所有的车都往前推一格(或者推进目的地)

    时间复杂度O(100*99+100) 99表示最多移动99下才能到目的地(这个环上)

    我们就一直让它转直到所有车都到目的地

    (如果位置是满的,而且一开始没有车可以到目的地,输出-1)

    实现的时候不是这么写的..而是把每个没到终点的都往终点推...

    B题

    2n个数,1~n各出现2次

    每次可以交换两个连续的数

    问几次能让每个数出现的两次是连续的

    n<=100

    直接...暴力把跟第一个相同的拖到第二个....然后依次做下去...

    C题

    n个向量,长度<=1e6

    每个向量可以选择+1或者-1倍,要求

    最后向量的和加起来长度<=1.5*1e6

    我的做法:

    直接每次让当前向量和下一个合并,取小的那一个

    如果最后发现错了,就把数据random_shuffle一下,再做一次,直到做出来为止

    过了,虽然不知道为啥

    std做法:

    每次三个里面,肯定有两个(可能经过乘以-1后)会有一对成为一个120°以外的角

    那么两个<=1e6的向量加起来还在1e6以内

    那么最后就可以得到两个,加起来一定在1.5*1e6(实际上在sqrt(2)*1e6)以内

    D题:

    A和B在玩一个游戏

    它们在填一个n位的二进制数,每次随机一个人过来选一位填成0或者1

    最后得分是c[二进制数数值]

    A要让它尽量大,B要让它尽量小

    问期望得到的值是多少,然后接下来r次修改

    每次修改c数组里面一个数的值,然后再询问

    n<=18

    r<=218

    做法:

    直接所有的c的和然后除以2^n

    Q老师的结论...

    EF不会做

    A

    #include<set>
    #include<map>
    #include<list>
    #include<queue>
    #include<stack>
    #include<string>
    #include<math.h>
    #include<time.h>
    #include<vector>
    #include<bitset>
    #include<memory>
    #include<utility>
    #include<fstream>
    #include<stdio.h>
    #include<sstream>
    #include<iostream>
    #include<stdlib.h>
    #include<string.h>
    #include<algorithm>
    using namespace std;
    #define move moasudoasjsap
    int a[4][55];
    struct move
    {
        int id;
        int x;
        int y;
        move (int iid=0,int xx=0,int yy=0)
        {
            id=iid;
            x=xx+1;
            y=yy+1;
        }
        void output()
        {
            printf("%d %d %d
    ",id,x,y);
        }
    };
    vector<move> ans;
    bool vis[105];
    int n;
    int newx,newy;
    void find_next(int sx,int sy)
    {
        newx=sx;
        newy=sy;
        if (sx==1)
        {
            if (sy==0)
            {
                newx++;
            }
            else
            {
                newy--;
            }
        }
        else
        {
            if (sy==n-1)
            {
                newx--;
            }
            else
            {
                newy++;
            }
        }
    }
    void find_way(int sx,int sy,int tx,int ty,int id)
    {
        if ((sx==tx)&&(sy==ty)) return;
        find_next(sx,sy);
        int ttx=newx;
        int tty=newy;
        if (a[newx][newy]!=0)
        {
            if (a[ttx^1][tty]==a[ttx][tty])
            {
                ans.push_back(move(a[ttx][tty],ttx^1,tty));
                vis[a[ttx][tty]]=true;
                a[ttx][tty]=0;
            }
            else
            {
                find_next(ttx,tty);
                find_way(ttx,tty,newx,newy,a[ttx][tty]);
            }
        }
        ans.push_back(move(id,ttx,tty));
        a[ttx][tty]=id;
        a[sx][sy]=0;
        find_way(ttx,tty,tx,ty,id);
    }
    int main()
    {
        #ifdef absi2011
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
        #endif
        int k;
        scanf("%d%d",&n,&k);
        int i;
        for (i=0;i<4;i++)
        {
            int j;
            for (j=0;j<n;j++)
            {
                scanf("%d",&a[i][j]);
            }
        }
        if (k==n+n)
        {
            for (i=1;i<=2;i++)
            {
                int j;
                for (j=0;j<n;j++)
                {
                    if (a[i][j]==a[i^1][j])
                    {
                        ans.push_back(move(a[i][j],i^1,j));
                        vis[a[i][j]]=true;
                        a[i][j]=0;
                        break;
                    }
                }
                if (j!=n) break;
            }
            if (i==3)
            {
                puts("-1");
                return 0;
            }
        }
        for (i=1;i<=k;i++)
        {
            if (vis[i]) continue;
            int j;
            int final_x,final_y;
            int start_x,start_y;
            for (j=0;j<n;j++)
            {
                if (a[0][j]==i)
                {
                    final_x=1;
                    final_y=j;
                }
                if (a[3][j]==i)
                {
                    final_x=2;
                    final_y=j;
                }
                if (a[1][j]==i)
                {
                    start_x=1;
                    start_y=j;
                }
                if (a[2][j]==i)
                {
                    start_x=2;
                    start_y=j;
                }
            }
            find_way(start_x,start_y,final_x,final_y,i);
            ans.push_back(move(i,final_x^1,final_y));
            a[final_x][final_y]=0;
            vis[i]=true;
        }
        printf("%d
    ",ans.size());
        for (i=0;i<ans.size();i++)
        {
            ans[i].output();
        }
        return 0;
    } 

    B

    #include<set>
    #include<map>
    #include<list>
    #include<queue>
    #include<stack>
    #include<string>
    #include<math.h>
    #include<time.h>
    #include<vector>
    #include<bitset>
    #include<memory>
    #include<utility>
    #include<fstream>
    #include<stdio.h>
    #include<sstream>
    #include<iostream>
    #include<stdlib.h>
    #include<string.h>
    #include<algorithm>
    using namespace std;
    int a[1005];
    int main()
    {
        #ifdef absi2011
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
        #endif
        int n;
        scanf("%d",&n);
        int i;
        for (i=0;i<n+n;i++)
        {
            scanf("%d",&a[i]);
        }
        int ans=0;
        for (i=0;i<n+n;i+=2)
        {
            int j;
            for (j=i+1;j<n+n;j++)
            {
                if (a[i]==a[j])
                {
                    int k;
                    for (k=j;k>i+1;k--)
                    {
                        swap(a[k],a[k-1]);
                        ans++;
                    }
                }
            }
        }
        printf("%d
    ",ans);
        return 0;
    } 

    C

    #include<set>
    #include<map>
    #include<list>
    #include<queue>
    #include<stack>
    #include<string>
    #include<math.h>
    #include<time.h>
    #include<vector>
    #include<bitset>
    #include<memory>
    #include<utility>
    #include<fstream>
    #include<stdio.h>
    #include<sstream>
    #include<iostream>
    #include<stdlib.h>
    #include<string.h>
    #include<algorithm>
    using namespace std;
    struct vv
    {
        int x;
        int y;
        int id;
    };
    vv v[100005];
    int ans[100005];
    int main()
    {
        #ifdef absi2011
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
        #endif
        srand(time(0));
        int n;
        scanf("%d",&n);
        int nowx=0,nowy=0;
        int i;
        for (i=0;i<n;i++)
        {
            int x,y;
            scanf("%d%d",&x,&y);
            v[i].id=i;
            v[i].x=x;
            v[i].y=y;
            long long t1=(long long)(nowx-x)*(nowx-x)+(long long)(nowy-y)*(nowy-y);
            long long t2=(long long)(nowx+x)*(nowx+x)+(long long)(nowy+y)*(nowy+y);
            if (t1<t2)
            {
                ans[i]=-1;
                nowx-=x;
                nowy-=y;
            }
            else
            {
                ans[i]=1;
                nowx+=x;
                nowy+=y;
            }
        }
        if ((long long)nowx*nowx+(long long)nowy*nowy>(long long)1500000*1500000)
        {
            for (;;)
            {
                random_shuffle(v,v+n);
                int nowx=0,nowy=0;
                for (i=0;i<n;i++)
                {
                    int x=v[i].x;
                    int y=v[i].y;
                    long long t1=(long long)(nowx-x)*(nowx-x)+(long long)(nowy-y)*(nowy-y);
                    long long t2=(long long)(nowx+x)*(nowx+x)+(long long)(nowy+y)*(nowy+y);
                    if (t1<t2)
                    {
                        ans[v[i].id]=-1;
                        nowx-=x;
                        nowy-=y;
                    }
                    else
                    {
                        ans[v[i].id]=1;
                        nowx+=x;
                        nowy+=y;
                    }
                }
                if ((long long)nowx*nowx+(long long)nowy*nowy<=(long long)1500000*1500000)
                {
                    for (i=0;i<n;i++)
                    {
                        printf("%d ",ans[i]);
                    }
                    printf("
    ");
                    return 0;
                }
            }
        }
        for (i=0;i<n;i++)
        {
            printf("%d ",ans[i]);
        }
        printf("
    ");
        return 0;
    } 

    D

    #include<set>
    #include<map>
    #include<list>
    #include<queue>
    #include<stack>
    #include<string>
    #include<math.h>
    #include<time.h>
    #include<vector>
    #include<bitset>
    #include<memory>
    #include<utility>
    #include<fstream>
    #include<stdio.h>
    #include<sstream>
    #include<iostream>
    #include<stdlib.h>
    #include<string.h>
    #include<algorithm>
    using namespace std;
    int a[1<<18];
    int main()
    {
        #ifdef absi2011
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
        #endif
        int n,r;
        scanf("%d%d",&n,&r);
        int k=(1<<n);
        int i;
        long long sum=0;
        for (i=0;i<k;i++)
        {
            scanf("%d",&a[i]);
            sum+=a[i];
        }
        printf("%.12lf
    ",sum*1.0/k);
        for (i=0;i<r;i++)
        {
            int x,y;
            scanf("%d%d",&x,&y);
            sum-=a[x];
            a[x]=y;
            sum+=y;
            printf("%.12lf
    ",sum*1.0/k);
        }
        return 0;
    } 
  • 相关阅读:
    python的三大控制机构(ifelse、for、while)
    python 异常处理
    《精通javascript》笔记
    IE6与!important
    point
    js 自制滚动条
    《Head first 设计模式》读书笔记
    Asp.net Webform 数据源绑定控件的扩展(懒人的办法):DropDownList
    Asp.net Binarysoft.Library 数据库通用操作层(Binarysoft.Library.Data)
    Asp.net Webform 从项目的数据库设计说起,什么是一个好的数据库设计。
  • 原文地址:https://www.cnblogs.com/absi2011/p/9226653.html
Copyright © 2011-2022 走看看