ICPC North Central NA Contest 2017

https://www.jisuanke.com/contest/7331?view=challenges

G. Sheba‘s Amoebas

题意:给定一个图,求图里有几个封闭图形

思路:用DFS每次将一整块连通图标记,最后看标记了多少个

直接上代码:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//typedef pair<ll,ll> PAIR;
const int maxn = 110;

int n,m,ans;
char mp[maxn][maxn];
bool vis[maxn][maxn];
int dir[8][2]={1,0,1,1,0,1,-1,1,-1,0,-1,-1,0,-1,1,-1};

bool check(int x,int y)
{
    if(x>=0&&x<n&&y>=0&&y<m&&vis[x][y]==0&&mp[x][y]==‘#‘)
        return true;
    else return false;
}

void dfs(int x,int y)
{
    vis[x][y] = true;
    for(int i=0;i<8;i++)
    {
        int tx = x+dir[i][0];
        int ty = y+dir[i][1];
        if(check(tx,ty)) dfs(tx,ty);
    }
}
int main()
{
    cin>>n>>m;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {
            cin>>mp[i][j];
        }
    }
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {
            if(mp[i][j]==‘#‘&&vis[i][j]==0)
            {
                dfs(i,j);
                ans++;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

H. Zebras and Ocelots

题意:动物园有斑马和猎豹,他们自上向下排列,敲一次钟,最下面的猎豹就会变成斑马,并且该猎豹下面的斑马也会变成列表,问钟敲几次之后,就会全部变成斑马。

思路:找规律 发现猎豹所在层数和需要敲钟次数有一定关系    2的n-1次方

次数0  1   2     3      4

  Z  O  O  O  O

  O  Z  Z  O  O

  O  Z  O  Z  O

所有从下向上遍历,遇到猎豹加上相应次数即可

AC代码:

#include<iostream>
#include<string>
#include<cstring>
#include<bits/stdc++.h>
using namespace std;

int main()
{
    long long node[100];// 存2的n次方
    int n;
    scanf("%d",&n);
    //构造 2 的n次方
    node[1] = 1;
    for(int i=2;i<=n;i++)
    {
        node[i] = 2*node[i-1];
    }

    long long ans = 0;//答案
    char x [100];
    for(int i=1;i<=n;i++)
    {
        cin>>x[i];
    }

    for(int i=n;i>=1;i--) // 从下向上遍历
    {

        if(x[i]==‘O‘)
        {
            ans += node[n-i+1]; // 如果有O 则 相加
        }
    }
    cout<<ans<<endl;
    return 0;
}

I. Racing Around the Alphabet

题意:一个圆盘上有28个字符,给定一串文字,问一次走完需要多长时间,给定速度和长度

思路:其实这道题要求走的距离,圆盘周长可求,一周28个字符,所有求出他一共走过了几个字符即可 他会站在开头字符处,去下一个字符时有两种方式,逆时针或者顺时针,哪个方法走过的字符少就用哪个方法

AC代码:

#include<iostream>
#include<string>
#include<cstring>
#include<bits/stdc++.h>
using namespace std;
const double pi = 3.1415926535;
int main()
{
    int t;
    cin>>t;
    getchar();
    while(t--)
    {
        int ans = 0;
        string s;
        getline(cin,s);

        for(int i=1;i<s.length();i++)
        {
            int a = s[i-1]-‘A‘+1;
            int b = s[i] - ‘A‘+1;
            if(s[i-1]==‘ ‘)
            {a =  27;}
            else if (s[i-1]==‘\‘‘) a = 28;

            if(s[i]==‘ ‘) b =  27;
            else if(s[i]==‘\‘‘) b = 28;
            if(b<a)
            {
                int z = b;
                b = a;
                a = z;
            }
            int x1 = b-a;
            int x2 = 28-(b-a);
            ans+=min(x1,x2);
        }
        double zc = pi*60;
        double jd = 1.0*zc/28*ans;
        double sum = 1.0*jd/15+s.length();
        printf("%.10f\n",sum);
    }

    return 0;
}

J. Lost Map

各村庄之间建路,求最小成本,最小生成树

AC代码:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e7 + 100;
const int maxm = 4e3 + 100;

struct bian//存储边的信息
{
    int x,y,w;
}a[maxn];

int father[maxm];//每个点的最终父类
int n,m=1;
bool cmp(const bian& a,const bian& b)
{
    return a.w<b.w;
}

int getfather(int x)//递归找父类
{
    if(father[x]==x) return x;
    father[x] = getfather(father[x]);
    return father[x];
}
void unionm(int x,int y)//合并
{
    int fa,fb;
    fa = getfather(x);
    fb = getfather(y);
    if(fa!=fb) father[fa] = fb;
}
void Init()//父类初始化
{
    for(int i = 1;i <= n;i++)
        father[i] = i;
    return;
};

void Kruskal()
{
    int ans = 0;
    int k = 0;
    for(int i=1;i<=m;i++)
    {
        if(getfather(a[i].x)!=getfather(a[i].y))
        {
            unionm(a[i].x,a[i].y);
            ans+=a[i].w;
            k++;
            cout<<a[i].x<<" "<<a[i].y<<endl;
        }
        if(k==n-1) break;
    }
//    if(k==n-1) cout<<ans<<endl;
//    else cout<<"impossible"<<endl;
}
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=n;j++)
        {
            int w;
            cin>>w;
            if(i<j) a[m++]={i,j,w};
        }
    }
    m--;
    Init();
    sort(a+1,a+1+m,cmp);

    Kruskal();

    return 0;
}

原文地址:https://www.cnblogs.com/subject/p/12398142.html

时间: 2024-08-30 10:26:13

ICPC North Central NA Contest 2017的相关文章

ICPC North Central NA Contest 2017 部分题解

ICPC North Central NA Contest 2017 部分题解 B. Pokemon Go Go 大意:用最短路径来抓住所有的稀有精灵,DFS求最短路 #include <bits/stdc++.h> #define mem(a) memset(a,0,sizeof(a)) #define forn(i,n) for(int i=0;i<n;++i) #define for1(i,n) for(int i=1;i<=n;++i) #define IO std::io

Bumped! 2017 ICPC North American Qualifier Contest (分层建图+dijstra)

题目描述 Peter returned from the recently held ACM ICPC World finals only to find that his return flight was overbooked and he was bumped from the flight! Well, at least he wasn’t beat up by the airline and he’s received a voucher for one free flight bet

The North American Invitational Programming Contest 2017 题目

NAIPC 2017 Yin and Yang Stones 75.39% 1000ms 262144K A mysterious circular arrangement of black stones and white stones has appeared. Ming has been tasked with balancing the stones so that only one black and one white stone remain. Ming has two opera

2018-2019 ICPC, NEERC, Southern Subregional Contest

目录 2018-2019 ICPC, NEERC, Southern Subregional Contest (Codeforces 1070) A.Find a Number(BFS) C.Cloud Computing(线段树) D.Garbage Disposal(模拟) E.Getting Deals Done(二分) F.Debate(贪心) H.BerOS File Suggestion(后缀自动机) I.Privatization of Roads in Berland(网络流)

2018-2019, ICPC, Asia Yokohama Regional Contest 2018 (Gym - 102082)

2018-2019, ICPC, Asia Yokohama Regional Contest 2018 A - Digits Are Not Just Characters 签到. B - Arithmetic Progressions 题意:从给定的集合中选出最多的数构成等差数列. 题解:数字排序后,设\(dp[i][j]\)表示等差数列最后一个数字为\(a[i]\),倒数第二个数字为\(a[j]\)的最大个数.然后对于每一位枚举 \(i\),\(lower\_bound()\)找有无合法的

Gym-101673 :East Central North America Regional Contest (ECNA 2017)(寒假自训第8场)

A .Abstract Art 题意:求多个多边形的面积并. 思路:模板题. #include<bits/stdc++.h> using namespace std; typedef long long ll; const double inf=1e200; const double eps=1e-12; const double pi=4*atan(1.0); int dcmp(double x){ return fabs(x)<eps?0:(x<0?-1:1);} struct

[bfs,深度记录] East Central North America Regional Contest 2016 (ECNA 2016) D Lost in Translation

Problem D Lost in Translation The word is out that you’ve just finished writing a book entitled How to Ensure Victory at a Programming Contest and requests are flying in. Not surprisingly, many of these requests are from foreign countries, and while

April Fools Contest 2017 题解&amp;源码(A,数学 B,数学 C,数学 D,字符串 E,数字逻辑 F,排序,卡时间)

A. Numbers Joke time limit per test:2 seconds memory limit per test:64 megabytes input:standard input output:standard output Input The input contains a single integer a (1 ≤ a ≤ 30). Output Output a single integer. Example Input 3 Output 27 题目链接:http

2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror) 体验记

原文链接https://www.cnblogs.com/zhouzhendong/p/CF1070.html 比赛网址:http://codeforces.com/contest/1070 感受 本来只打算玩玩的. 结果玩的海星. 我做 A 题的时候可能比较浮躁吧,各种傻错误,爆了 7 个罚时. 我 A 还没过,cly 神仙已经把 CDK 切光了. 4点半过一会儿,各自回家.cly 要剃头,就咕咕咕了.我本来也要剃的,后来临时决定先打题. 然后过了 A ,顺手切掉了 H 和 F ,开了 E ,猜