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. python函数的传参模式

    python里的变量更像是一个名字.标签.而Python中一切又皆为对象. 当函数传参时,函数参数作为一个标签,指向某个对象,因此更贴切的说是"call by object". 但 ...

  2. 我去,还在这样读写 excel 这也太低效了吧!

    前言 博文地址:https://sourl.cn/SsD3AM 最近读者小 H 给小黑哥发来私信: 小黑哥,最近我在负责公司报表平台开发,需要导出报表到 excel 中.每次使用 POI 开发,都要写 ...

  3. Java工程中如何读取配置文件中参数信息

    Java中读取配置文件中参数: 方法一:通过JDK中Properties来实现对配置文件的读取. Properties主要用于读取Java的配置文件,不同的编程语言有自己所支持的配置文件,配置文件中很 ...

  4. Java线程通讯方法之wait()、nofity() 详解

    Java线程通讯方法之wait().nofity() 详解 本文将探讨以下问题: synchronized 代码块使用 notify()与notifyAll()的区别 Java wait(),noti ...

  5. java中的动手动脑

    1.关于构造函数的问题 为什么上面的代码不能通过编译? 因为当你没有定义构造函数时,java编译器在编译时会自动生成一个无参的构造函数,上面的代码就可以进行执行了.但是当你顶一个构造函数时,编译器将不 ...

  6. Java第二十二天,异常

    异常 程序在执行过程中,出现的非正常的情况,最终会导致JVM非正常停止. 注意: 在Java等面向对象编程语言当中,异常本身是一个类,产生异常的本质就是抛出一个异常对象.Java对异常采取中断处理方式 ...

  7. JavaScript实现简单的弹幕效果实例分析

    不知大家有没有感受到,弹幕又是另一出好戏!! 不过我个人还是比较排斥看电视的时候被出来的弹幕打扰.今天我们来写一个简单的弹幕.简单到什么程度呢?看下效果: 由图可以看出,我们的呆毛html结构确实是非 ...

  8. Python程序设计实验报告二:顺序结构程序设计(验证性实验)

      安徽工程大学 Python程序设计 实验报告 班级   物流191   姓名  崔攀  学号3190505136 成绩 日期     2020.3.22     指导老师       修宇 [实验 ...

  9. mysql中show status介绍一

    公司产品运用到mysql集群,集群遇到问题时,需要查看集群状态,使用到命令show status,今天趁机将show status中的各个变量的含义研究一下. 状态名 作用域 详细解释 Aborted ...

  10. Spring Data REST不完全指南(三)

    上一篇我们介绍了使用Spring Data REST时的一些高级特性,以及使用代码演示了如何使用这些高级的特性.本文将继续讲解前面我们列出来的七个高级特性中的后四个.至此,这些特性能满足我们大部分的接 ...