zoukankan      html  css  js  c++  java
  • 第三届ACM山东省赛I题_Chess_STL

    7600B的代码量,不说啥了,现场能不能做出来还要看运气.

    2Y,第一次忘记输出t16,WA了。。。

    代码如下:

    #include <cstdio>
    #include <map>
    #include <cstring>
    #include <vector>
    #include <algorithm>
    using namespace std;
    struct point
    {
        int x,y;
        bool operator<(const point&c) const
        {
            if (x!=c.x)
                return x<c.x;
            return y<c.y;
        }
    };
    struct Information
    {
        int x,y;
        char role;
    };
    struct mark
    {
        int p,id;
        bool operator<(const mark &c) const
        {
            return p<c.p;
        }
    };
    Information information[100005];
    map<point,int>ID;
    map<int,vector<mark> >row,col,k1,k2;
    int _count[100005],cnt_ID,horse[100005],cnt_horse,ans[20];
    int dx[8]= {-2,-2,-1,-1,1,1,2,2},dy[8]= {1,-1,2,-2,2,-2,1,-1};
    int main()
    {
        int i,j,T,n;
        scanf("%d",&T);
        for (int kcase=1; kcase<=T; ++kcase)
        {
            scanf("%d",&n);
            memset(_count,0,sizeof(_count[0])*n);
            ID.clear();
            row.clear();
            col.clear();
            k1.clear();
            k2.clear();
            cnt_horse=cnt_ID=0;
            char c,ch;
            point p;
            mark m;
            int x,y;
            for (i=0; i<n; ++i)
            {
                scanf("%d %d %c%c",&information[i].x,&information[i].y,&information[i].role,&ch);
                x=p.x=information[i].x,p.y=y=information[i].y,c=information[i].role;
                if (c=='N')
                    horse[cnt_horse++]=i;
                ID[p]=i;
                if (!row.count(x))
                    row[x]=vector<mark>();
                if (!col.count(y))
                    col[y]=vector<mark>();
                if (!k1.count(x+y))
                    k1[x+y]=vector<mark>();
                if (!k2.count(x-y))
                    k2[x-y]=vector<mark>();
                m.id=i,m.p=y;
                row[x].push_back(m);
                m.p=x;
                col[y].push_back(m);
                k1[x+y].push_back(m);
                k2[x-y].push_back(m);
            }
            for (map<int,vector<mark> >::iterator it=row.begin(); it!=row.end(); it++)
                sort(row[it->first].begin(),row[it->first].end());
            for (map<int,vector<mark> >::iterator it=col.begin(); it!=col.end(); it++)
                sort(col[it->first].begin(),col[it->first].end());
            for (map<int,vector<mark> >::iterator it=k1.begin(); it!=k1.end(); it++)
                sort(k1[it->first].begin(),k1[it->first].end());
            for (map<int,vector<mark> >::iterator it=k2.begin(); it!=k2.end(); it++)
                sort(k2[it->first].begin(),k2[it->first].end());
    //        printf("row :\n");
    //        for (map<int,vector<mark> >::iterator it=row.begin(); it!=row.end(); it++)
    //        {
    //            printf("%d :    ",it->first);
    //            for (i=0; i<row[it->first].size(); ++i)
    //                printf(" %d",row[it->first][i].id);
    //            printf("\n");
    //        }
    //        for (map<int,vector<mark> >::iterator it=col.begin(); it!=col.end(); it++)
    //            sort(col[it->first].begin(),col[it->first].end());
    //        for (map<int,vector<mark> >::iterator it=k1.begin(); it!=k1.end(); it++)
    //            sort(k1[it->first].begin(),k1[it->first].end());
    //        for (map<int,vector<mark> >::iterator it=k2.begin(); it!=k2.end(); it++)
    //            sort(k2[it->first].begin(),k2[it->first].end());
            for (map<int,vector<mark> >::iterator it=row.begin(); it!=row.end(); it++)
            {
                int size=row[it->first].size();
                for (i=0; i<size; ++i)
                {
                    if (information[row[it->first][i].id].role=='K')
                    {
                        if (i && row[it->first][i-1].p==row[it->first][i].p-1)
                            ++_count[row[it->first][i-1].id];
                        if (i<size-1 && row[it->first][i+1].p==row[it->first][i].p+1)
                            ++_count[row[it->first][i+1].id];
                    }
                    else if (information[row[it->first][i].id].role=='R' || information[row[it->first][i].id].role=='Q')
                    {
                        if (i)
                            ++_count[row[it->first][i-1].id];
                        if (i<size-1)
                            ++_count[row[it->first][i+1].id];
                    }
                }
            }
            for (map<int,vector<mark> >::iterator it=col.begin(); it!=col.end(); it++)
            {
                int size=col[it->first].size();
                for (i=0; i<size; ++i)
                {
                    if (information[col[it->first][i].id].role=='K')
                    {
                        if (i && col[it->first][i-1].p==col[it->first][i].p-1)
                            ++_count[col[it->first][i-1].id];
                        if (i<size-1 && col[it->first][i+1].p==col[it->first][i].p+1)
                            ++_count[col[it->first][i+1].id];
                    }
                    else if (information[col[it->first][i].id].role=='R' || information[col[it->first][i].id].role=='Q')
                    {
                        if (i)
                            ++_count[col[it->first][i-1].id];
                        if (i<size-1)
                            ++_count[col[it->first][i+1].id];
                    }
                }
            }
            for (map<int,vector<mark> >::iterator it=k1.begin(); it!=k1.end(); it++)
            {
                int size=k1[it->first].size();
                for (i=0; i<size; ++i)
                {
                    if (information[k1[it->first][i].id].role=='K')
                    {
                        if (i && k1[it->first][i-1].p==k1[it->first][i].p-1)
                            ++_count[k1[it->first][i-1].id];
                        if (i<size-1 && k1[it->first][i+1].p==k1[it->first][i].p+1)
                            ++_count[k1[it->first][i+1].id];
                    }
                    else if (information[k1[it->first][i].id].role=='B' || information[k1[it->first][i].id].role=='Q')
                    {
                        if (i)
                            ++_count[k1[it->first][i-1].id];
                        if (i<size-1)
                            ++_count[k1[it->first][i+1].id];
                    }
                }
            }
            for (map<int,vector<mark> >::iterator it=k2.begin(); it!=k2.end(); it++)
            {
                int size=k2[it->first].size();
                for (i=0; i<size; ++i)
                {
                    if (information[k2[it->first][i].id].role=='K')
                    {
                        if (i && k2[it->first][i-1].p==k2[it->first][i].p-1)
                            ++_count[k2[it->first][i-1].id];
                        if (i<size-1 && k2[it->first][i+1].p==k2[it->first][i].p+1)
                            ++_count[k2[it->first][i+1].id];
                    }
                    else if (information[k2[it->first][i].id].role=='B' || information[k2[it->first][i].id].role=='Q')
                    {
                        if (i)
                            ++_count[k2[it->first][i-1].id];
                        if (i<size-1)
                            ++_count[k2[it->first][i+1].id];
                    }
                }
            }
            for (i=0; i<cnt_horse; ++i)
                for (j=0; j<8; ++j)
                {
                    p.x=information[horse[i]].x+dx[j];
                    p.y=information[horse[i]].y+dy[j];
                    if (ID.count(p))
                        ++_count[ID[p]];
                }
            memset(ans,0,sizeof(ans));
            for (i=0; i<n; ++i)
                ++ans[_count[i]];
    //        for (i=0; i<n; ++i)
    //            printf("%d ",_count[i]);
    //        printf("\n");
            printf("Case %d:\n",kcase);
            printf("%d",ans[0]);
            for (i=1; i<=16; ++i)
                printf(" %d",ans[i]);
            printf("\n");
        }
        return 0;
    }
    

      

  • 相关阅读:
    DataGridView如何获取某个数据
    扩展方法
    base和this关键字
    装箱和拆箱
    var,object和dynamic
    const和readonly
    react native回调函数刷新页面
    react native打包android,android9.0以上版本http请求不了怎么办?
    react native中android app怎样打包发布
    React Native 实现页面返回监听
  • 原文地址:https://www.cnblogs.com/Chierush/p/3118173.html
Copyright © 2011-2022 走看看