Opening Ceremony

Problem E: Opening Ceremony

Time Limit: 1 Sec  Memory Limit: 128 MB

Submit: 137  Solved: 30

[Submit][Status][Web
Board
]

Description

Input

Output

Sample Input

6
2 1 8 8 2 3

Sample Output

5

HINT

题意:有一堆砖块,每一次操作可以选择消去任意一行,也可以选择消去任意一列。求要消去所有的砖块需要最小的操作数。

思路:贪心。每次进行消一行操作时,显然消最底层的一行比消高层更优(这样可以消掉更多的砖块)。每次进行消一列操作时,显然消最高的一列比消更矮的一列更优。

那么只要从小到大排序,然后遍历一次就可以了。

#include<stdio.h>
#include<algorithm>
using namespace std;
int a[100005];
int main()
{
    int n;
    while(scanf("%d",&n)!=EOF)
    {
        for(int i=1;i<=n;i++)
            scanf("%d",&a[i]);
        sort(a+1,a+n+1);
        int mmin=n;
        for(int i=1;i<=n;i++)
        {
            mmin=min(mmin,(n-i+a[i]));//i+1之后消列,i前除行。
        }
        printf("%d\n",mmin);
    }
    return 0;
}

/**************************************************************
    Problem: 1578
    User: aking2015
    Language: C++
    Result: Accepted
    Time:56 ms
    Memory:1356 kb
****************************************************************/
时间: 2024-07-29 10:08:29

Opening Ceremony的相关文章

CodeForcesGym 100502E Opening Ceremony

Opening Ceremony Time Limit: 5000ms Memory Limit: 524288KB This problem will be judged on CodeForcesGym. Original ID: 100502E64-bit integer IO format: %I64d      Java class name: (Any) For the grand opening of the algorithmic games in NlogNsglow, a r

SOJ.Opening Ceremony

1003. Opening Ceremony     总提交数量: 123 通过数量: 34                 时间限制:1秒    内存限制:256兆 题目描述 For the grand opening of the algorithmic games in NlogNsglow, a row of tower blocks is set to be demolished in a grand demonstration of renewal. Originally the p

csu 1578 Opening Ceremony (递推 )

题意:有一个排n个建筑 每个高不定 现在要消去全部建筑 方法有两种 1 消去高度为某值的全部方块 2 消去一整个建筑 问 如何通过最少步骤消去 思路:首先将数组从大到小排序 if(i+a[i]<ans) ans=i+a[i]; #include<cstdio> #include<cstring> #include<algorithm> using namespace std; int a[1000000+100]; int cmp(int a,int b) { r

csu 1578: Opening Ceremony(DP)

#include<cstdio> #include<cstring> #include<algorithm> using namespace std; int a[100005]; int dp[100005]; int main() { int n; while(scanf("%d",&n)==1) { for(int i=1;i<=n;i++) scanf("%d",&a[i]); sort(a+1,a+

SOJ - 11512

11512. Big Circle Constraints Time Limit: 2 secs, Memory Limit: 256 MB Description On the opening ceremony of World Cup there was a part where many kids from around the world was trying to make a big circle on the field which symbolized tolerance and

可穿戴设备的发展与挑战

可穿戴设备的发展和挑战 “可穿戴设备”已经不是新鲜词汇了,即直接穿在身上或整合到衣服或配件里的一种便携式设备.几十年的发展中,它已不仅仅是一种硬件设备,更是通过软件支持,数据交互,云端交互等高科技来实现强大的功能.它并非只是移动互联网时代产生的衍生品,在很久以前这种思想便已萌生在上世纪70年代的赌场里.经过平稳的发展后,现代社会里可穿戴设备已经对我们的生活和感知带来了比较大的转变. 关于它的发展史已经没有回顾的必要,总体是随着最新的科技前沿和智能手机的更迭在稳步发展.通过研讨,我们总结出了在现阶

【英语魔法俱乐部——读书笔记】 3 高级句型-简化从句&amp;倒装句(Reduced Clauses、Inverted Sentences) 【完结】

[英语魔法俱乐部——读书笔记] 3 高级句型-简化从句&倒装句(Reduced Clauses.Inverted Sentences):(3.1)从属从句简化的通则.(3.2)形容词从句简化.(3.3)名词从句简化.(3.4)副词从句简化.(3.5)简化从句练习.(3.6)倒装句 3.1 从属从句简化的通则(Generally Reduction Rules of Dependent Clause) 3.1.1 简化从句:英语语法以句子为研究对象,而其句型也分为简单句.复句和合句之分,其中简单句

可穿戴设备还能怎么玩?

根据市场研究公司Juniper近日发表的报告预测,2018年全球可穿戴设备出货量将达到1.3亿台,10倍于2013年,许多 业内人士无疑将可穿戴设备视为继智能手机之后的下一个互联网浪潮制高点.就在刚刚结束的CES年度大展上,从硬件创业公司Razer到索尼等大型消费电子 制造商,再到英特尔.爱普生等芯片商和耗材商,几乎所有与硬件沾边的公司都在谋划这个潜在市场.这种情况下,你不得不承认,"可穿戴设备"的热潮已经被点 燃了.   听上去很酷,这或许是当前可穿戴设备普及的最大障碍之一.普通消费

The Plaza Beauty also are ghd cheap australia

The Plaza Beauty also are ghd cheap australia raffling off free refurbishments every hour. Some moat people that have long hair be needing being extra careful since the extra pressure while curling the sides, Can certainly break fairly and cause spli