zoukankan      html  css  js  c++  java
  • AtCoder Beginning Contest 176

    A:

    签到题。

     1 #include <iostream>
     2 using namespace std;
     3 int main(void)
     4 {
     5    long long n,x,t;
     6    cin>>n>>x>>t;
     7    if(n%x==0)cout<<n/x*t<<endl;
     8    else cout<<(n/x+1)*t<<endl;
     9    return 0;
    10 }

    B:

    判断是否为9的倍数。

     1 #include <iostream>
     2 #include <string>
     3 using namespace std;
     4 int main(void)
     5 {
     6    string s;
     7    long long k=0;
     8    cin>>s;
     9    for(int i=0;i<s.size();i++)
    10    {
    11        k+=s[i]-'0';
    12    }
    13    if(k%9==0)cout<<"Yes"<<endl;
    14    else cout<<"No"<<endl;
    15    return 0;
    16 }

    C:

    从前到后,如果前面的比后面的高,把后面的提升到同一高度。(不开longlong见祖宗)

    #include <iostream>
    #include <string>
    using namespace std;
    int main(void)
    {
       long long n,a,x,ans=0;
       cin>>n>>a;
       while(--n)
       {
           cin>>x;
           if(x<a)ans+=a-x;
           else a=x;
       }
       cout<<ans<<endl;
       return 0;
    }

    D:

    双端队列bfs,确保先跑完当前连通块再转其他连通块。这里的dis即为所用魔法次数。

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <deque>
     4 using namespace std;
     5 typedef pair<int,int>P;
     6 const int INF=23333333;
     7 int f[1100][1100],dis[1100][1100],h,w,x1,Y1,x2,y2;
     8 int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
     9 char c[1100][1100];
    10 void bfs(void)
    11 {
    12     deque<P>q;
    13     dis[x1][Y1]=0;
    14     P start(x1,Y1);
    15     q.push_front(start);
    16     while(q.size())
    17     {
    18         P t=q.front();
    19         q.pop_front();
    20         if(f[t.first][t.second])continue;
    21         f[t.first][t.second]=1;
    22         int x,y,d=dis[t.first][t.second];
    23         for(int i=0;i<4;i++)
    24         {
    25             x=t.first+dx[i],y=t.second+dy[i];
    26             if(x<0||x>=h||y<0||y>=w||c[x][y]=='#'||dis[x][y]<=d)continue;
    27             dis[x][y]=d;
    28             q.push_front(P(x,y));
    29         }
    30         for(int i=t.first-2;i<=t.first+2;i++)
    31         {
    32             if(i<0||i>=h)continue;
    33             for(int j=t.second-2;j<=t.second+2;j++)
    34             {
    35                 if(j<0||j>=w||c[i][j]=='#'||dis[i][j]<=d+1)continue;
    36                 dis[i][j]=d+1;
    37                 q.push_back(P(i,j));
    38             }
    39         }
    40     }
    41 }
    42 int main(void)
    43 {
    44     scanf("%d %d %d %d %d %d",&h,&w,&x1,&Y1,&x2,&y2);
    45     x1--;Y1--;x2--;y2--;
    46     for(int i=0;i<h;i++)scanf("%s",c[i]);
    47     for(int i=0;i<h;i++)
    48     {
    49         for(int j=0;j<w;j++)dis[i][j]=INF;
    50     }
    51     bfs();
    52     printf("%d
    ",dis[x2][y2]==INF?-1:dis[x2][y2]);
    53     return 0;
    54 }

    E:

    对每个目标所在的行、列+1,找出目标数最多的行和列进行组合,如果存在该点无目标的组合,则输出行列目标数的和;否则输出目标数的和减一。(减去当前位置的目标)(然鹅极端数据应该会超时的。。可能数据水一点)

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <string>
     4 #include <map>
     5 #include <vector>
     6 using namespace std;
     7 typedef pair<int,int>P;
     8 int h[310000],w[310000];
     9 int H,W,m,x,y,maxh,maxw;
    10 map<P,int>f;
    11 int main(void)
    12 {
    13     scanf("%d %d %d",&H,&W,&m);
    14     while(m--)
    15     {
    16         scanf("%d %d",&x,&y);
    17         f[P(x,y)]=1;
    18         h[x]++;
    19         w[y]++;
    20     }
    21     for(int i=1;i<=H;i++)maxh=max(maxh,h[i]);
    22     for(int i=1;i<=W;i++)maxw=max(maxw,w[i]);
    23     vector<int>hh,ww;
    24     for(int i=1;i<=H;i++)
    25     {
    26         if(h[i]==maxh)hh.push_back(i);
    27     }
    28     for(int i=1;i<=W;i++)
    29     {
    30         if(w[i]==maxw)ww.push_back(i);
    31     }
    32     for(int i=0;i<hh.size();i++)
    33     {
    34         for(int j=0;j<ww.size();j++)
    35         {
    36             if(f[P(hh[i],ww[j])]==0)
    37             {
    38                 printf("%d
    ",maxw+maxh);
    39                 return 0;
    40             }
    41         }
    42     }
    43     printf("%d
    ",maxh+maxw-1);
    44     return 0;
    45 }

    F:

    待补。。

  • 相关阅读:
    Invalid column name on sql server update after column create
    个人工资计算表
    xxxx
    excel cannot access the file there are several possible reasons
    .NET/VB.NET: solving the error “The system cannot find the file specified.” “Temp.NETFramework,Version=v4.0.AssemblyAttributes.vb”
    GIT
    时区
    create Excel file
    开发类分组
    判断是否已安装.net framework
  • 原文地址:https://www.cnblogs.com/yanying7/p/13556590.html
Copyright © 2011-2022 走看看