集合
来源:互联网 发布:快乐十分选号软件 编辑:程序博客网 时间:2024/06/14 11:17
集合
【问题描述】
给定一个可重集合,一开始只有一个元素 0 。然后你可以操作若干轮,每一
轮,你需要对于集合中的每个元素 x 进行如下三种操作之一:
1 、将 x 变为 1 + x 。
2 、将 x 分裂为两个非负整数 z y,,且满足 x=y+z。
3 、什么都不做。
每一轮,集合中的每个元素都必须进行上面三个操作之一。
对于一个最终的集合,你的任务是判断至少进行了多少轮。
【输入文件】
第一行为一个正整数 n ,表示集合的最终大小。
第二行为 n 个非负整数,描述集合中的元素。
【输出文件】
输出一个非负整数,为最少的轮数。
【输入输出样例】
multiset.in multiset.out
5
0 0 0 3 3
5
【数据规模和约定】
设集合中最大的元素为 m 。
对于 % 10 的数据,满足 10 ≤ n , 10 ≤ m 。
对于 % 30 的数据,满足 50 ≤ n , 100 ≤ m 。
对于 % 50 的数据,满足 1000 ≤ n , 10000 ≤ m 。
对于 % 100 的数据,满足 1000000 1 ≤ ≤ n , 1000000 0 ≤ ≤ m 。
倒着搞,合并0,把大数减掉。
只考虑两种操作。但从前向后走的话,可能的情况很多你不确定应该向那些状态扩展。
那就从后往前缩回来,把这些数都变成0.
#include <cstdio>#include <iostream>#include <algorithm>using namespace std;int a[999999];bool comp(int x,int y){ return x>y;}int main(){ int n; scanf("%d",&n); for(int i=1;i<=n;i++) scanf("%d",&a[i]); sort(a+1,a+n+1,comp); int ans=0; int l=n; int r=n,ans=0; while(!a[l]) l--; int t=1; while(r>1) { r-=(r-l)>>1; while(a[l]==t) l--; ans++,t++; } printf("%d",ans);}
阅读全文
0 0
- 集合
- 集合
- 集合
- 集合
- 集合
- 集合
- 集合
- 集合
- 集合
- 集合
- 集合
- 集合
- 集合
- 集合
- 集合
- 集合
- 集合
- 集合
- Python实现图灵机器人交互
- html title 图标
- oracle笔记06
- android studio3.0(二)Cannot set the value of read-only property 'outputFile'
- GIT学习笔记(6)
- 集合
- 转载 springBoot与redis
- 高通modem侧新增AT命令
- java基础知识(三 数据类型)
- java
- WinDbg 命令
- JNI 实战全面解析,jni实战全面解析
- Spring Boot整合Redis
- JAVA学习笔记16——Spring框架第三章