本文是博主原创文章,未经允许不得转载。

我在csdn上也同步发布了此文,链接 https://blog.csdn.net/umbrellalalalala/article/details/79891552

题目链接 http://codeforces.com/problemset/problem/961/A
【题目】
You are given a following process.

There is a platform with n columns. 1×1 squares are appearing one after another in some columns on this platform. If there are no squares in the column, a square will occupy the bottom row. Otherwise a square will appear at the top of the highest square of this column.

When all of the n columns have at least one square in them, the bottom row is being removed. You will receive 1 point for this, and all the squares left will fall down one row.

You task is to calculate the amount of points you will receive.

Input

The first line of input contain 2 integer numbers n and m (1≤n,m≤1000) — the length of the platform and the number of the squares.

The next line contain mm integer numbers c1,c2,…,cm (1≤ci≤n) — column in which i-th square will appear.

Output

Print one integer — the amount of points you will receive.

Example
Input

 
3 9
1 1 2 2 2 3 1 2 3
Output

 
2
Note

In the sample case the answer will be equal to 2 because after the appearing of 6-th square will be removed one row (counts of the squares on the platform will look like [2 3 1], and after removing one row will be [1 2 0]).

After the appearing of 9-th square counts will be [2 3 1], and after removing one row it will look like [1 2 0].

So the answer will be equal to 2.
 
【大意及分析】
有点像俄罗斯方块,大意就是在n列的区域中,随机在给定的若干列依次出现m个小方块,每个小方块都会占据本列空闲位置的最下方,当每一列的最后一行都有小方块时,这一行就会被删掉,分数加一,然后上面的方块下落一行。
我们只需要利用数组表示每一列的方块个数即可(注意不要用二维数组表示每一列的方块的情况,我们并不需要知晓方块的具体位置,那样算法复杂度会变大)。
 
【示例代码】
 #include<stdio.h>
#include<stdlib.h>
#define MAX_N 1005
int a[MAX_N]; int main() {
int score = ;
int n, m, temp, bottom_score = ;
bool judge;
scanf("%d %d", &n, &m);
for (int i = ; i < n; i++)
a[i] = ;
for (int i = ; i < m; i++) {
scanf("%d", &temp);
a[temp - ]++;
judge = true;
for (int k = ; k < n; k++) {
if (a[k] == bottom_score) {
judge = false;
break;
}
}
if (judge) {
score++;
bottom_score++;
}
}
printf("%d\n", score);
return ;
}

codeforces——961A Tetris的更多相关文章

  1. Codeforces Round #627 (Div. 3) A - Yet Another Tetris Problem(逻辑)

    题意 : 有n个高度,可以使任一高度加二任意次,问最终n个高度可否相同. 思路: 因为添加的2x1的方块不可旋转,只需考虑所有高度是否为同一奇偶性即可. #include <bits/stdc+ ...

  2. x01.Tetris: 俄罗斯方块

    最强大脑有个小孩玩俄罗斯方块游戏神乎其技,那么,就写一个吧,玩玩而已. 由于逻辑简单,又作了一些简化,所以代码并不多. using System; using System.Collections.G ...

  3. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

  4. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  5. 【Codeforces 738C】Road to Cinema

    http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...

  6. 【Codeforces 738A】Interview with Oleg

    http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...

  7. CodeForces - 662A Gambling Nim

    http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...

  8. CodeForces - 274B Zero Tree

    http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...

  9. CodeForces - 261B Maxim and Restaurant

    http://codeforces.com/problemset/problem/261/B 题目大意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a ...

随机推荐

  1. UNIX环境高级编程——创建与打开IPC通道

    创建或打开一个IPC对象的三个getXXX函数的第一个参数key是类型为key_t的IPC键,返回值identifier是一个整数标识符.该标识符不同于ftok函数的id参数.对于key值,应用程序有 ...

  2. android:padding和android:margin的区别 详解

    转载请说明博客地址:http://blog.csdn.net/qq_32059827/article/details/51487997 看了网上的类似博客,并没有给出确定的区别.现在具体分析一下pad ...

  3. java的制作"时间账本"

    一直以来我都感觉自己的时间过得好荒废啊,貌似只是打开了一个网页链接的时间,一个下午便过去了:仿佛就是看了看空间,刷了刷微信,一天就过去了.哈,当然这是夸张的说法.但是我仔细地算了一下,大概我们每个人每 ...

  4. Java异常处理示例

    翻译人员: 铁锚 翻译日期: 2013年11月22日 原文链接: Java Exception Handling Example 本文中有两个示例, 第一个演示了所有调用其他方法的地方,都必须处理被调 ...

  5. 9.8、Libgdx的返回键和菜单键捕获

    (官网:www.libgdx.cn) 当用户在Android设备中点击返回键是,通常关闭当前运行的activity.游戏可能会给出一个确认对话框让用户选择退出或继续.要这样的话需要捕获返回键: Gdx ...

  6. linux:你不知道的echo

    linux的echo命令功能是在显示器上显示一段文字.一般格式为: echo [ -n ] 字符串.参数n是指行尾不换行 echo会将输入的字符串送往标准输出.输出的字符串间以空白字符隔开, 并在最后 ...

  7. 手把手带你画一个 时尚仪表盘 Android 自定义View

    拿到美工效果图,咱们程序员就得画得一模一样. 为了不被老板喷,只能多练啊. 听说你觉得前面几篇都so easy,那今天就带你做个相对比较复杂的. 转载请注明出处:http://blog.csdn.ne ...

  8. Django应用部署 - 上线指南

    http://blog.csdn.net/pipisorry/article/details/46957613 python manage.py runserver已经很接近于服务器的形式,但是并不能 ...

  9. linux下用gtk+写比赛赌博GUI小游戏

    游戏界面全部由gtk的GUI完成,没有使用openGL之类的高端货. 游戏玩法就是8位选手比赛跑步,你可以在赛前赌哪位选手会赢,如果输了cash会被扣除,反之cash会增加. 无聊写了3个选项:小数时 ...

  10. 一个类搞定UIScrollView那些事儿

    前言 UIScrollView可以说是我们在日常编程中使用频率最多.扩展性最好的一个类,根据不同的需求和设计,我们都能玩出花来,当然有一些需求是大部分应用通用的,今天就聊一下以下需求,在一个categ ...