1. 程式人生 > >Codeforces Round #556 (Div. 2)-ABC(這次的題前三題真心水)

Codeforces Round #556 (Div. 2)-ABC(這次的題前三題真心水)

getchar hal tdi pac char prim img end rime

A. Stock Arbitraging

技術分享圖片

直接上代碼:

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<vector>
#include<cmath>


const int maxn=1e5+5;
typedef 
long long ll; using namespace std; int main() { int n,m,r; cin>>n>>m>>r; int x; int minn=0x3f3f3f3f; for(int t=0;t<n;t++) { scanf("%d",&x); minn=min(minn,x); } int maxnn=0; for(int t=0;t<m;t++) { scanf(
"%d",&x); maxnn=max(maxnn,x); } if(maxnn<=minn) { cout<<r<<endl; } else { int k=r; r=r%minn; r+=(maxnn)*(k/minn); cout<<r<<endl; } return 0; }

B. Tiling Challenge

技術分享圖片

找一下就行了

代碼:

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<vector>
#include<cmath>

const int maxn=1e5+5;
typedef long long ll;
using namespace std;
char Map[55][55];
int n;
int dir[4][2]={{0,1},{0,-1},{-1,0},{1,0}};
bool check(int x,int y)
{
    if(x>=0&&x<n&&y>=0&&y<n)
    {
        return true;
    }
    else
    {
        return false;
    }
}
int main()
{
    
    cin>>n;
    getchar();
    for(int t=0;t<n;t++)
    {
        scanf("%s",Map[t]);
    }
    for(int t=0;t<n;t++)
    {
        for(int j=0;j<n;j++)
        {
            int sum=0;
            if(Map[t][j]==.)
            {
            for(int k=0;k<4;k++)
            {
                int xx=t+dir[k][0];
                int yy=j+dir[k][1];
                //cout<<xx<<" "<<yy<<endl;
                if(check(xx,yy)&&Map[xx][yy]==.)
                {
                    sum++;
                }
            }
            }
            if(sum==4)
            {
                Map[t][j]=#;
                for(int k=0;k<4;k++)
                {
                int xx=t+dir[k][0];
                int yy=j+dir[k][1];
                Map[xx][yy]=#;
                }
            }
        }
    }
    bool flag=true;
    for(int t=0;t<n;t++)
    {
        for(int j=0;j<n;j++)
        {
            if(Map[t][j]==.)
            {
                flag=false;
            }
        }
    }
    if(flag)
    {
        cout<<"YES"<<endl;
    }
    else
    {
        cout<<"NO"<<endl;
    }
    return 0;
}

C. Prefix Sum Primes

思維+構造也很好想

代碼;

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<vector>
#include<cmath>

const int maxn=1e5+5;
typedef long long ll;
using namespace std;
vector<int>v1,v2;
int main()
{
    int n;
    cin>>n;
    int x;
    for(int t=0;t<n;t++)
    {
        scanf("%d",&x);
        if(x==1)
        v1.push_back(x);
        else
        {
            v2.push_back(x);
        }
    }
    
    if(v1.size()==n)
    {
        vector<int>::iterator it=v1.begin();
        for(it=v1.begin();it!=v1.end();it++)
        {
            cout<<*it<<" ";
        }
    }
    else if(v2.size()==n)
    {
        vector<int>::iterator it=v2.begin();
        for(it=v2.begin();it!=v2.end();it++)
        {
            cout<<*it<<" ";
        }
    }
    else
    {
      cout<<"2 1 ";
      int xx=v1.size()-1;
      int yy=v2.size()-1;
      for(int t=0;t<yy;t++)
      {
          cout<<"2 ";
      }
      for(int j=0;j<xx;j++)
      {
          cout<<"1 ";
      }
        
        
    }
    return 0;
}

Codeforces Round #556 (Div. 2)-ABC(這次的題前三題真心水)