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

我在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. APACHE,NGINX 详细分析

    Apache是目前最流行的Web应用服务器,占据了互联网应用服务器70%以上的份额.Apache能取得如此成功并不足为奇:它免费.稳定且性能卓越:但Apache能取得如此佳绩的另一个原因是,当时互联网 ...

  2. java实现:将一个数逆序输出

    前面我们用C语言实现过这个程序,其实java也一样的,很多步骤跟C差不多,但是有些接口和特性可能不同: import java.util.Scanner;//要使用scanner这个类,就需要导入一个 ...

  3. μC/OS-II与RT-Thread对比——任务调度

           在任务调度器的实现上,μC/OS-II和RT-Thread都采用了位图调度(bitmap scheduling),任务优先级的值越小则代表具有越高的优先级,主要区别在于实现形式,是采用多 ...

  4. Python基础 语法特别注意笔记(和Java相比)

    Python变量和数据类型 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 ...

  5. css3学习之旅-css的基本语法(1)

    后面就将要介绍css的全面语法: 1.css介绍 2.css基本语法 3.css高级语法 4.css派生选择器 5.css的id选择器 6.css类选择器 7.css属性选择器 !!!!!css介绍 ...

  6. GDB 资料汇总

    很全的关于 GDB 调试的指导: GDB中应该知道的几个调试方法 用 GDB 调试程序 100个gdb调试小技巧 CGDB中文手册 Beej's Quick Guide to GDB

  7. 开源视频会议系统:OpenMeetings 安装方法

    OpenMeetings是一个多语言可定制的视频会议和协作系统.说到OpenMeetings就应该提一下red5因为OpenMeetings 的视频服务是加载red5上面的.Red5是一款基于JAVA ...

  8. Mahout canopy聚类

    Canopy 聚类 一.Canopy算法流程 Canopy 算法,流程简单,容易实现,一下是算法 (1)设样本集合为S,确定两个阈值t1和t2,且t1>t2. (2)任取一个样本点p,作为一个C ...

  9. Esper剖析

    Esper剖析 最近在看论文,发现文中有些语言自己未曾见过,经过一番搜索,才发觉是自己接触到了新知识. 官网: )esper的核心包包含了EPL语法解析引擎,事件监听机制,事件处理等核心模块. (2) ...

  10. 【Qt编程】基于Qt的词典开发系列<三>--开始菜单的设计

    这篇文章讲讲如何实现开始菜单(或者称为主菜单)的设计.什么是开始菜单呢?我们拿常用的软件来用图例说明,大多数软件的开始菜单在左下角,如下图: 1.window 7的开始菜单 2.有道词典的主菜单 3. ...