codeforces 8VC Venture Cup 2016 - Elimination Round C. Lieges of Legendre
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了codeforces 8VC Venture Cup 2016 - Elimination Round C. Lieges of Legendre相关的知识,希望对你有一定的参考价值。
题意:给n,m表示有n个为2的倍数,m个为3的倍数;问这n+m个数不重复时的最大值 最小为多少?
数据:(0 ≤ n, m ≤ 1 000 000, n + m > 0)
ps:很水的题,主要是策略;
思路:由于里面每隔6就会重复一次,不好直接模拟,并且模拟的效率很低,那就二分吧!二分即上界为2单独的最大倍数与3单独时的最大倍数之和,下界为前面二者的max;之后利用判断是否mid/2 >= n && mid/3 >= m && mid/2 + mid/3 - mid/6 >= n + m 即可二分;这样running 就是log(n)了;注意最后还要判断ans是否为2|3的积即可;
#include<bits/stdc++.h> using namespace std; int main() { int n,m; scanf("%d%d",&n,&m); int l = max(n*2,m*3),r = n*2 + m*3,ans = 0; while(l <= r){ int mid = l + r >> 1; if(mid/2 >= n && mid/3 >= m && mid/2 + mid/3 - mid/6 >= n + m) ans = mid,r = mid - 1; else l = mid + 1; } if(ans%2 != 0 && ans%3 != 0) ans++; printf("%d",ans); return 0; }
以上是关于codeforces 8VC Venture Cup 2016 - Elimination Round C. Lieges of Legendre的主要内容,如果未能解决你的问题,请参考以下文章
Codeforces Round #393 (Div. 2) (8VC Venture Cup 2017 - Final Round Div. 2 Edition) D - Travel Card(示
Codeforces Round #393 (Div. 2) (8VC Venture Cup 2017 - Final Round Div. 2 Edition) E - Nikita and st
8VC Venture Cup 2016 - Elimination Round
8VC Venture Cup 2016 - Elimination Round E. Simple Skewness(枚举+三分)