hdu_1800

简单排一下序,从大开始把比他小的都访问一遍,ans++;

#include <iostream>
#include <stdio.h>
#include <algorithm> using namespace std; struct dat
{
int level;
int visit;
}data[]; bool cmp(dat a, dat b)
{
return a.level > b.level; } int main()
{
int n; while(scanf("%d", &n)!=-)
{
for(int i=; i<n; i++)
{
scanf("%d", &data[i].level);
data[i].visit=;
} sort(data, data+n, cmp); int ans=;
for(int i=; i<n; i++)
{
if(!data[i].visit)
{
data[i].visit=;
int temp=i;
ans++;
for(int j=; j<n; j++)
{
if(!data[j].visit && data[temp].level>data[j].level)
{
data[j].visit=;
temp=j; }
}
}
}
printf("%d\n", ans);
} return ;
}

hdu_2124

排个序,用 l 从大开始减去block的大小,记录用的block块数, 最后 l > 0 , 则输出impossible,否则输出块数。

#include <iostream>
#include <stdio.h>
#include <algorithm> using namespace std; bool cmp(int a, int b)
{
return a>b;
} int main()
{
int l, n, block[];
while(scanf("%d%d", &l, &n)!=-)
{
for(int i=; i<n; i++)
{
scanf("%d", &block[i]);
}
sort(block, block+n, cmp); int ans=;
for(int i=; i<n && l!=; i++)
{
if(l>=block[i])
{
l-=block[i];
ans++;
}
else
{
l=;
ans++;
break;
}
}
if(l!=)
printf("impossible\n");
else
printf("%d\n", ans);
}
return ;
}

hdu_2124 Flying to the Mars & hdu_1800 Repair the Wall 贪心水题的更多相关文章

  1. hdu---(1800)Flying to the Mars(trie树)

    Flying to the Mars Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Other ...

  2. hdu 1800 Flying to the Mars

    Flying to the Mars 题意:找出题给的最少的递增序列(严格递增)的个数,其中序列中每个数字不多于30位:序列长度不长于3000: input: 4 (n) 10 20 30 04 ou ...

  3. (贪心 map) Flying to the Mars hdu1800

    Flying to the Mars Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Other ...

  4. 杭电 1800 Flying to the Mars(贪心)

    http://acm.hdu.edu.cn/showproblem.php?pid=1800 Flying to the Mars Time Limit: 5000/1000 MS (Java/Oth ...

  5. Flying to the Mars

    D - Flying to the Mars Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I ...

  6. HDOJ.1800 Flying to the Mars(贪心+map)

    Flying to the Mars 点我挑战题目 题意分析 有n个人,每个人都有一定的等级,高等级的人可以教低等级的人骑扫帚,并且他们可以共用一个扫帚,问至少需要几个扫帚. 这道题与最少拦截系统有异 ...

  7. HDU 1800——Flying to the Mars——————【字符串哈希】

    Flying to the Mars Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Other ...

  8. HDU1800 Flying to the Mars 【贪心】

    Flying to the Mars Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Other ...

  9. HDU2124 Repair the Wall(贪心)

    Problem Description Long time ago , Kitty lived in a small village. The air was fresh and the scener ...

随机推荐

  1. 2020年Java多线程与并发系列22道高频面试题(附思维导图和答案解析)

    前言 现在不管是大公司还是小公司,去面试都会问到多线程与并发编程的知识,大家面试的时候这方面的知识一定要提前做好储备. 关于多线程与并发的知识总结了一个思维导图,分享给大家 1.Java中实现多线程有 ...

  2. 关于C#三层架构增删改查中的“登录”问题

    先来一个界面: DAO中的方法: 实现代码如下: 这里需要特别注意的是一个“安全性”的考虑: 当登入成功时,把登入时输入的用户名赋值到Session,然后在后面的页面进行判断--此时Session保留 ...

  3. Three.js 中的参数调试控制插件dat.GUI.JS - [Three.js] - [dat.GUI]

    不论是处于特殊功能的需要,还是处于效果调试方便,我们可能都需要修改模型中的参数值.在Three.js中,谷歌提供了一个js库,即dat.GUI.js用于处理这种需求. 通过该库,我们就不需要通过手动修 ...

  4. 计算机网络协议,IPV4数据报分析

    一.IP数据报结构分析 1.整体结构 一个IP数据报由首部和数据两部分组成. 首部的前一部分固定长20字节,这是所有IP数据报必须具有的:在首部的固定部分后面是一些可选字段,其长度是可变的. IP数据 ...

  5. Linux 压缩备分篇(一 备份数据)

    备份文件                dump dump: -S                    仅列出待备份数据需要多少磁盘空间才能够备份完毕 -u                    将 ...

  6. .net 垃圾回收

    垃圾回收器帮我们处理了内存中不在使用的对象,提高了机器的性能,让开发人员轻松了很多. 你真的了解垃圾回收吗? 或许你知道垃圾回收,听说过是通过标记回收,可是怎么标记回收呢就不是很清楚了,好吧,如果不清 ...

  7. System.out.println()的真实含义

    每一个人的Java学习之路上恐怕都是用以下代码开始的吧? public class Test { public static void main(String[] args) { System.out ...

  8. CH5501 环路运输(单调栈)

    传送门 思路: 遇到一个环,用正常人类的思想就先把环从中间截断然后将其补成2*n长度的链.环上的最小距离换到链上就是i以n/2为半径范围内的点(画图肉眼可见).由于两个点是等价的,所以我们考虑有序对( ...

  9. hadoop(十一)HDFS简介和常用命令介绍

    HDFS背景 随着数据量的增大,在一个操作系统中内存不了了,就需要分配到操作系统的的管理磁盘中,但是不方便管理者维护,迫切需要一种系统来管理多态机器上的文件,这就是分布式文件管理系统. HDFS的概念 ...

  10. 数据结构和算法(Golang实现)(13)常见数据结构-可变长数组

    可变长数组 因为数组大小是固定的,当数据元素特别多时,固定的数组无法储存这么多的值,所以可变长数组出现了,这也是一种数据结构.在Golang语言中,可变长数组被内置在语言里面:切片slice. sli ...