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 ...
随机推荐
- Three.js中的动画实现02-[Three.js]-[Object3D属性.onAfterRender/.onBeforeRender]
Table Of Content Object3D简介以及两个属性的介绍 一个示例 Object3D简介以及两个属性的介绍 这是Three.js中大部分对象的基类,提供了一系列的属性和方法来对三维空间 ...
- WeixinJSBridge API使用实例
<span style="color: rgb(51, 51, 51); font-family: tahoma, arial, 宋体; font-size: 14px; line-h ...
- 分治与递归-Starssen矩阵乘法
代码实现: /** * 矩阵乘法求解 * @author Administrator * */ public class Strassen { public static final int NUMB ...
- 【电商】性能测试网站搭建:XAMPP1.8+DBShop1.3
1.安装准备 1.1软件版本 XAMPP的版本:XAMPP 1.8.2 DBShop的版本:DBShop 1.3 1.2.安装环境 我的环境:win10 win7,win10都可以运行的,安装步骤 ...
- vue技术栈进阶(01.使用vue-cli3创建项目)
使用vue-cli3创建一个项目 1) 使用Vue UI创建.管理项目 1.安装依赖的脚手架包. 2.命令行中输入vue ui 即可以打开可视化界面 可视化界面: 2)项目结构目录整理 3)基本配置 ...
- NumPy学习2:基本运算
数组相减: a = array([20, 30, 40, 50])print ab = arange(4)print bc = a-bprint c 结果: [20 30 40 50][0 1 2 3 ...
- 三、CentOS 7.X系统安装配置超祥细图解教程
一.CentOS7.7下载 官网下载地址:http://mirrors.163.com/centos 1.进入CentOS下载官网,找到CentOS7.4版本 2.在CentOS7.7版本页面中,找到 ...
- git撤销已经push到远端的commit
在使用git时,push到远端后发现commit了多余的文件,或者希望能够回退到以前的版本. 先在本地回退到相应的版本: git reset --hard <版本号> // 注意使用 -- ...
- 正整数的二进制表示中1的个数计算(使用移位或者n&(n-1))
第一种:使用n&(n-1)表示来计算有多少个1 int n=127; int count=0; while (n!=0){ count++; n=n&(n-1); } 第二种:使用移位 ...
- AJ学IOS(48)多线程网络之多线程简单了解
AJ分享,必须精品 一:进程和线程 1:什么是进程 进程是指在系统中正在运行的一个应用程序 每个进程之间是独立的,每个进程均运行在其专用且受保护的内存空间内. 比如同时打开QQ.Xcode,系统就会分 ...