【1-n】区间覆盖 TOJ4168+BZOJ1192
Xiao Ming is very interesting for array. He given a sorted positive integer array and an integer n.
We need add elements to the array such that the sum of subset of array cover the range [1, n]. You must return the minimum number of add elements.
Xiao Ming worry about you can't understand this problem. Now, he gives you an example:
There is an array [1, 3], n = 6, the answer is 1. Because we only need to add 2 into array. After add operator, the array is [1,2,3]. The subsets are: [1], [2], [3], [1,2], [1,3], [2,3], [1,2,3]. Possible sums are 1, 2, 3, 4, 5, 6, which now covers the range [1, 6].
Input
The input consists of multiple test cases. The first line contains an integer TT
, indicating the number of test cases.
Each case contains two integers m,nm,n
, mm
means the number of elements in array, nn
means the cover range.(1≤m≤105,1≤n≤2147483647)(1≤m≤105,1≤n≤2147483647)
.
Then comes a line with mm
integers.
Output
Return the minimum number of add elements.
Sample Input
1
3 20
1 5 10
Sample Output
2
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
long long num[100861];
int main()
{
int T;
for(scanf("%d",&T);T--;){
long long n,m;
scanf("%lld%lld",&n,&m);
for(int i=1;i<=n;++i) scanf("%lld",num+i);
sort(num+1,num+1+n);
long long sum=0;
int ct=0,pos=1;
for(long long i=1;i<=m;++i)
{
if(num[pos]<=i&&pos<=n) {
sum+=num[pos];
++pos;
i=sum;
}
else {
++ct;
sum+=i;
i=sum;
}
}
printf("%d\n",ct);
}
}
1192: [HNOI2006]鬼谷子的钱袋
Time Limit: 10 Sec Memory Limit: 162 MB
Submit: 3752 Solved: 2705
[Submit][Status][Discuss]
Description
鬼谷子非常聪明,正因为这样,他非常繁忙,经常有各诸侯车的特派员前来向他咨询时政。有一天,他在咸阳游历的时候,朋友告诉他在咸阳最大的拍卖行(聚宝商行)将要举行一场拍卖会,其中有一件宝物引起了他极大的兴趣,那就是无字天书。但是,他的行程安排得很满,他他已经买好了去邯郸的长途马车标,不巧的是出发时间是在拍卖会快要结束的时候。于是,他决定事先做好准备,将自己的金币数好并用一个个的小钱袋装好,以便在他现有金币的支付能力下,任何数目的金币他都能用这些封闭好的小钱的组合来付账。鬼谷子也是一个非常节俭的人,他想方设法使自己在满足上述要求的前提下,所用的钱袋数最少,并且不有两个钱袋装有相同的大于1的金币数。假设他有m个金币,你能猜到他会用多少个钱袋,并且每个钱袋装多少个金币吗?
Input
包含一个整数,表示鬼谷子现有的总的金币数目m。其中,1≤m ≤1000000000。
Output
只有一个整数h,表示所用钱袋个数
Sample Input
Sample Output
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
int main()
{
long long sum=0,m,ans=1,ct,tt=0;
scanf("%lld",&m);
while(1)
{
if(sum+ans>m) break;
sum+=ans;
ans<<=1;
++tt;
}
ct=m-sum;
if(!ct) printf("%lld\n",tt);
else printf("%lld\n",tt+1);
}
【1-n】区间覆盖 TOJ4168+BZOJ1192的更多相关文章
- HDU 4509 湫湫系列故事——减肥记II(线段树-区间覆盖 或者 暴力技巧)
http://acm.hdu.edu.cn/showproblem.php?pid=4509 题目大意: 中文意义,应该能懂. 解题思路: 因为题目给的时间是一天24小时,而且还有分钟.为了解题方便, ...
- UVa 10020 (最小区间覆盖) Minimal coverage
题意: 数轴上有n个闭区间[ai, bi],选择尽量少的区间覆盖一条指定线段[0, m] 算法: [start, end]为已经覆盖到的区间 这是一道贪心 把各个区间先按照左端点从小到大排序,更新st ...
- codeforces Gym 100187F F - Doomsday 区间覆盖贪心
F. Doomsday Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100187/problem/F ...
- 【区间覆盖问题】uva 10020 - Minimal coverage
可以说是区间覆盖问题的例题... Note: 区间包含+排序扫描: 要求覆盖区间[s, t]; 1.把各区间按照Left从小到大排序,如果区间1的起点大于s,则无解(因为其他区间的左起点更大):否则选 ...
- uvalive 2326 - Moving Tables(区间覆盖问题)
题目连接:2326 - Moving Tables 题目大意:在一个走廊上有400个教室, 先在有一些桌子要移动, 每次移动需要十分钟, 但是不同房间的桌子可以在同一个十分钟内移动,只要走廊没有被占用 ...
- 高效算法——E - 贪心-- 区间覆盖
E - 贪心-- 区间覆盖 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=85904#problem/E 解题思路: 贪心思想, ...
- 外星人的供给站 (区间覆盖 t贪心)
/** 区间覆盖问题 分析: 每个点可以确定两个圆心 圆心的范围形成 一个区间 在这个区间上以任意一点画圆便可将此点 包含在内 如果有两个点所确定的区间相交了 说明这两个点可以用一个圆包含在内 即用一 ...
- Cleaning Shifts(区间覆盖)
/* http://acm.hdu.edu.cn/webcontest/contest_showproblem.php?pid=1019&ojid=1&cid=10 题目: 给定一个时 ...
- UVA 10382 - Watering Grass【贪心+区间覆盖问题+高精度】
UVa 10382 - Watering Grass n sprinklers are installed in a horizontal strip of grass l meters long a ...
随机推荐
- Linux硬盘分区知识
前言 硬盘使用前,一般要分区,格式化(创建文件系统)<== 存放数据 类比,房子使用前,一般要隔断,装修,买家具,再住人. 分区 一块硬盘: 主分区.扩展分区.逻辑分区 主分区+扩展分区的数量& ...
- 图论--2-SAT--HDU/HDOJ 1814 Peaceful Commission
Peaceful Commission Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- 数据库SQL---实体-联系模型(E-R模型)
1.E-R模型的基本概念与表示 1)实体与实体集 (1)实体:可以是有形的.实在的事物(如每个员工),可以是抽象的.概念上存在的事物(如一个部门). (2)实体的特征:独立存在.可区别于其他实体. ( ...
- Gitlab常规操作
一.Git和SVN的区别 和SVN类似,Git是一个版本控制系统(Version Control System,VCS),不同的是SVN为集中式版本控制系统,为单一的集中管理的服务器,保存所有文件的修 ...
- DataHub——实时数据治理平台
DataHub 首先,阿里云也有一款名为DataHub的产品,是一个流式处理平台,本文所述DataHub与其无关. 数据治理是大佬们最近谈的一个火热的话题.不管国家层面,还是企业层面现在对这个问题是越 ...
- mybatis与hibernate运行流程比较
hibernate长时间没用,感觉生疏了,正好借这篇文章整合下知识,顺便复习比较下两种框架. 概述: Mybatis和hibernate不同,它不完全是一个ORM框架,因为MyBatis需要程序员自己 ...
- 一分钟html页面倒计时可精确到秒
<!doctype html> <html> <head> <meta charset="utf-8"> </head> ...
- 自定义IDOC
目录 1需求场景 4 2配置发送端IDOC 4 2.1定义段(WE31) 4 2.2定义基本类型(WE30) 4 2.3定义消息类型(WE81) 5 2.4定义传输结构 ...
- .NETcore中使用jwt来对api进行身份验证
对于 登陆,身份,授权这之类的操作,我们最常用的几种方法无非就是 cookie session token 这三者的差别 https://www.cnblogs.com/moyand/p/904797 ...
- python语法学习第七天--文件
打开文件:open() 使用 open() 方法一定要保证关闭文件对象,即调用 close() 方法. open(file, mode='r', buffering=-1, encoding=None ...