hdu_2124 Flying to the Mars & hdu_1800 Repair the Wall 贪心水题
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 贪心水题的更多相关文章
- 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 ...
- hdu 1800 Flying to the Mars
Flying to the Mars 题意:找出题给的最少的递增序列(严格递增)的个数,其中序列中每个数字不多于30位:序列长度不长于3000: input: 4 (n) 10 20 30 04 ou ...
- (贪心 map) Flying to the Mars hdu1800
Flying to the Mars Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
- 杭电 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 ...
- Flying to the Mars
D - Flying to the Mars Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I ...
- HDOJ.1800 Flying to the Mars(贪心+map)
Flying to the Mars 点我挑战题目 题意分析 有n个人,每个人都有一定的等级,高等级的人可以教低等级的人骑扫帚,并且他们可以共用一个扫帚,问至少需要几个扫帚. 这道题与最少拦截系统有异 ...
- HDU 1800——Flying to the Mars——————【字符串哈希】
Flying to the Mars Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
- HDU1800 Flying to the Mars 【贪心】
Flying to the Mars Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
- HDU2124 Repair the Wall(贪心)
Problem Description Long time ago , Kitty lived in a small village. The air was fresh and the scener ...
随机推荐
- 华为五年自动化测试工程详细解说:unittest单元测试框架
一.单元测试框架说明 单元测试是指在编程中,针对程序模块的最小单元(类中的方法)进行正确性检验的测试工作.python+selenium自动化测试中通常使用unittest或者pytest作为单元 ...
- Git创建本地仓库&把pycharm项目添加GitHub仓库上
一.创建本地仓库 1.1.下载Git地址:https://git-scm.com/downloads 下载完,一路next就可以 1.2.打开Git Bash输入: #创建一个learngit目录 $ ...
- 【php】php操作MySQL数据库
一.操作步骤: 1. 连接MySQL数据库并判断是否连接成功2. 选择数据库3. 设置字符集4. 准备SQL语句5. 向MySQL服务发送SQL语句6. 解析处理结果集7. 释放结果集,关闭数据库连接 ...
- 【php】面向过程的文件上传过程
//执行完整的文件上传 $path = "./uploads"; //文件上传的指定目录 $upfile = $_FILES['pic']; //文件的上传信息[一维数组] $ty ...
- 家庭记账本app进度之ui相关概念控制ui界面与布局管理
ui就是用户界面设计的意思. 首先是view,view相当于窗户上的玻璃. 1.android:id属性.android:id="@+id/user".他的id是user前面的@+ ...
- rest_framework-分页
分页 from django.shortcuts import render # Create your views here. from rest_framework import serializ ...
- python3(二十二) oop
""" 面向对象编程 """ __author__ = 'shaozhiqi' # 面向对象的程序设计把计算机程序视为一组对象的集合,而每个 ...
- Python 中如何查看进行反汇编
dis模块 Python 反汇编是通过 dis 这个模块来查看的,一般有两种方式可以用来查看 方式一: 在命令行中使用 dis 查看 >>> def test ...
- Java编程最差实践常见问题详细说明(2)转
Java编程最差实践常见问题详细说明(2)转 2012-12-13 13:57:20| 分类: JAVA | 标签:java |举报|字号 订阅 反射使用不当 错误的写法: Java代 ...
- 搭建vue2.0开发环境及手动安装vue-devtools工具
安装vue脚手架 1.安装node.js,如果安装成功输入 node -v ,查看node版本号,输入npm -v查看npm版本 https://nodejs.org/en/ 2.注册淘宝镜像,定制的 ...