1 条题解
-
0
自动搬运
来自洛谷,原作者为

feicheng
State of Emergency搬运于
2025-08-24 22:29:37,当前版本为作者最后更新于2021-03-06 14:28:19,作者可能在搬运后再次修改,您可在原文处查看最新版自动搬运只会搬运当前题目点赞数最高的题解,您可前往洛谷题解查看更多
以下是正文
谷首A
话说十二生肖一开始不是鼠吗?Description
Solution
贪心
我们考虑将时间轴分成 块,然后计算有必须经过的年份之间的距离,贪心的选取最远的 个距离跳过。
为什么是 呢?因为我们要首先跳到最远的点上去。
细节见代码
Code
/*If you are full of hope,you will be invincible*/ #include <ctime> #include <cstdio> #include <random> #include <cstring> #include <iostream> #include <algorithm> #include<ext/pb_ds/assoc_container.hpp> #include<ext/pb_ds/hash_policy.hpp> #include<ext/pb_ds/priority_queue.hpp> #define ri register int typedef long long ll; std::mt19937 hpy(time(nullptr)+(unsigned long long)(new char)); using std::cin; using std::cout; constexpr int inf=0x3f3f3f3f,N=1e5+1; int a[N],tim[N],n,cnt,k; bool cmp(int tx,int ty){return tx>ty;} std::priority_queue<int> Q;//用优先队列来存储最远的k个距离 int main(int argc,const char *argv[]){ cin >> n >> k; k--; for(ri i=1;i<=n;++i) cin >> a[i]; std::sort(a+1,a+1+n);//对年份排序,方便计算差值 for(ri i=1;i<=n;++i) { if(!cnt) tim[++cnt] = a[i]/12+1;//计算哪些时间段有必须去的年份 else if(tim[cnt]!=a[i]/12+1) tim[++cnt]=a[i]/12+1; } for(ri i=1;i<=cnt;++i) { if(tim[i]-tim[i-1]!=1) Q.push(tim[i]-tim[i-1]-1);//计算时间差 } for(ri i=1;i<=k&&!Q.empty();++i) Q.pop();//选取k个点跳过 int res = cnt*12;//有cnt个时间段必须经过 while(!Q.empty()) { res += Q.top()*12;//这些时间差必须经过,所以要加12 Q.pop(); } cout << res; }
- 1
信息
- ID
- 6543
- 时间
- 1000ms
- 内存
- 250MiB
- 难度
- 3
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者