美文网首页
第六次寒假集训

第六次寒假集训

作者: 李耳_9992 | 来源:发表于2019-01-29 20:35 被阅读0次

国庆期间,省城HZ刚刚举行了一场盛大的集体婚礼,为了使婚礼进行的丰富一些,司仪临时想出了有一个有意思的节目,叫做"考新郎",具体的操作是这样的:


image.png

首先,给每位新娘打扮得几乎一模一样,并盖上大大的红盖头随机坐成一排;
然后,让各位新郎寻找自己的新娘.每人只准找一个,并且不允许多人找一个.
最后,揭开盖头,如果找错了对象就要当众跪搓衣板...

看来做新郎也不是容易的事情...

假设一共有N对新婚夫妇,其中有M个新郎找错了新娘,求发生这种情况一共有多少种可能.
Input
输入数据的第一行是一个整数C,表示测试实例的个数,然后是C行数据,每行包含两个整数N和M(1<M<=N<=20)。
Output
对于每个测试实例,请输出一共有多少种发生这种情况的可能,每个实例的输出占一行。
Sample Input
2
2 2
3 2
Sample Output
1
3

如果有一个人选错,那就至少还有另一个人选错;
从N个新郎,挑M个错排,那么也就是说有 N-M 个 新郎选对了新娘。

#include <iostream>
using namespace std;
int main()
{
    int c,i,j;
    int m,n;
    long long sm[21];   
    long long a[21];
    sm[0]=1;
    sm[1]=0;
    a[0]=1;
    a[1]=1;
    for(j=2;j<21;j++){
        sm[j]=(j-1)*(sm[j-1]+sm[j-2]);
        a[j]=j*a[j-1];
    }
 
    cin>>c;
    for(i=0;i<c;i++){
        cin>>n>>m;
        cout<<sm[m]*(a[n]/a[m]/a[n-m])<<endl;
    }
    return 0;
}

The GeoSurvComp geologic survey company is responsible for detecting underground oil deposits. GeoSurvComp works with one large rectangular region of land at a time, and creates a grid that divides the land into numerous square plots. It then analyzes each plot separately, using sensing equipment to determine whether or not the plot contains oil. A plot containing oil is called a pocket. If two pockets are adjacent, then they are part of the same oil deposit. Oil deposits can be quite large and may contain numerous pockets. Your job is to determine how many different oil deposits are contained in a grid.
Input
The input file contains one or more grids. Each grid begins with a line containing m and n, the number of rows and columns in the grid, separated by a single space. If m = 0 it signals the end of the input; otherwise 1 <= m <= 100 and 1 <= n <= 100. Following this are m lines of n characters each (not counting the end-of-line characters). Each character corresponds to one plot, and is either *', representing the absence of oil, or@', representing an oil pocket.
Output
For each grid, output the number of distinct oil deposits. Two different pockets are part of the same oil deposit if they are adjacent horizontally, vertically, or diagonally. An oil deposit will not contain more than 100 pockets.
Sample Input
1 1

3 5
@@*
@
@@*
1 8
@@****@*
5 5
****@
@@@
@@
@@@
@
@@**@
0 0
Sample Output
0
1
2
2

油田问题:
油田的整体面积可以8个方向进行遍历,所以创建两个数组x,y进行坐标的获得。
BFS里面用二维数组进行遍历
广度优先搜索,
满足条件并且是油田且未遍历过的,就进入队列,并标记走过
不满足条件的话,则head++,直到head>tail
若标记过,直接对油田标记走过,并返回。
用一个visited数组来标记走过的油田。

#include<iostream>
#include<cstring>
using namespace std;
int M, N, total;
char map[110][110];
int visited[110][110];
int dx[8] = { -1, -1, 0, 1, 1, 1, 0, -1 };
int dy[8] = { 0,  1, 1, 1, 0,-1,-1, -1 };
struct queue {
    int xx;int yy;
}que[10100];
void find_oil(int x, int y)
{
    int x1, y1;
    int head, tail;
    if (!visited[x][y])
    {
        total++;//第一次遍历
        visited[x][y] = 1;
    }
    if (visited[x][y] == 1)
    {
        head = 0, tail = 1;
        que[0].xx = x; 
        que[0].yy = y;  
        while (tail > head)
        {
            x = que[head].xx;
            y = que[head].yy;
            for (int i = 0;i < 8;i++)
            {
                x1 = x + dx[i];y1 = y + dy[i];
                if (x1 >= 1 && x1 <= M && y1 >= 1 && y1 <= N)
                    if (map[x1][y1] == '@' && !visited[x1][y1])
                    {
                        que[tail].xx = x1;
                        que[tail].yy = y1;
                        visited[x1][y1] = 1;
                        tail += 1;
                    }
            }
            head++;
        }
    }
}
void BFS()
{
    for (int i = 1;i <= M;i++)
        for (int j = 1;j <= N;j++)
            if (map[i][j] == '@' && !visited[i][j])
                find_oil(i, j);
}
int main()
{
    ios::sync_with_stdio(false);
    while (cin >> M >> N)
    {
        cin.get();
        if (M <= 0 || N <= 0) break;
        total = 0;
        memset(map, 0, sizeof(map));
        memset(visited, 0, sizeof(visited));
        for (int i = 1;i <= M;i++)
            for (int j = 1;j <= N;j++)
                cin >> map[i][j];
        BFS();
        cout << total << endl;
    }
    return 0;
}

相关文章

  • 第六次寒假集训

    国庆期间,省城HZ刚刚举行了一场盛大的集体婚礼,为了使婚礼进行的丰富一些,司仪临时想出了有一个有意思的节目,叫做"...

  • 寒假集训

    这次寒假集训虽然只有十天,但训练强度很大。是真的很累,每天都需要压软度,真的要哭崩了。每个技巧要重复训练...

  • 寒假集训

    寒假集训报名最晚20日之前交给我,再晚的就睡大街去吧

  • 寒假集训1

    上午早起去瑛杰武道学习交流,先了解了学生住宿情况,然后看了他们早训,陈教练带业余武术培训还是很有水...

  • 寒假集训2

    今日早起,过早后去武馆学习交流,上午因陈总教练有事外出,经协调请了陈勇教练帮忙带课,我替岗维护初级...

  • 重磅 | 硕成20考研寒假集训营一营即将震撼开营,助你金榜题名!

    寒假集训营 2019年1月15日 硕成20考研【寒假集训营】 正式开营!!! 新起点,新征程 漫漫研路,硕成相伴 ...

  • 简年3:提线木偶

    每次快到寒假集训期,我都特别焦虑。 为什么呢?因为寒假集训期特别忙。 忙的什么呢?给孩子们匹配合适的各科老师。 老...

  • 刘世界:语料数据处理与实践应用

    翻译技术寒假集训营 第五讲 人工智能时代翻译技术寒假集训营第五讲开讲啦!为大家邀请到翻译技术界的青年才俊刘世...

  • 谈寒假武术集训

    为什么要谈这个话题呢?想通过回顾来总结认识,有助于更好的做好武术教育工作。 陈教练负责学生...

  • 寒假集训营的前奏集训

    今天和小伙伴一起进行了寒假集训营的课程培训,刚开始在燕子老师的谆谆教导下,熟悉了拓普独特的问好与团建相关的流...

网友评论

      本文标题:第六次寒假集训

      本文链接:https://www.haomeiwen.com/subject/qnlfsqtx.html