https://codeforces.com/contest/1241/problem/C

You are an environmental activist at heart but the reality is harsh and you are just a cashier in a cinema. But you can still do something!

You have n tickets to sell. The price of the i-th ticket is pi. As a teller, you have a possibility to select the order in which the tickets will be sold (i.e. a permutation of the tickets). You know that the cinema participates in two ecological restoration programs applying them to the order you chose:

The x% of the price of each the a-th sold ticket (a-th, 2a-th, 3a-th and so on) in the order you chose is aimed for research and spreading of renewable energy sources.
The y% of the price of each the b-th sold ticket (b-th, 2b-th, 3b-th and so on) in the order you chose is aimed for pollution abatement.
If the ticket is in both programs then the (x+y)% are used for environmental activities. Also, it's known that all prices are multiples of 100, so there is no need in any rounding.

For example, if you'd like to sell tickets with prices [400,100,300,200] and the cinema pays 10% of each 2-nd sold ticket and 20% of each 3-rd sold ticket, then arranging them in order [100,200,300,400] will lead to contribution equal to 100⋅0+200⋅0.1+300⋅0.2+400⋅0.1=120. But arranging them in order [100,300,400,200] will lead to 100⋅0+300⋅0.1+400⋅0.2+200⋅0.1=130.

Nature can't wait, so you decided to change the order of tickets in such a way, so that the total contribution to programs will reach at least k in minimum number of sold tickets. Or say that it's impossible to do so. In other words, find the minimum number of tickets which are needed to be sold in order to earn at least k.

思路:从大到小排序,分块解决。直接对排序后的数组前缀和, 然后记录a, b, lcm(a, b)的个数

AC代码:

直接枚举判断是否符合

 #include<bits/stdc++.h>

 using namespace std;
#define N 210000
#define int long long
int sum[N];
int price[N];
bool cmp(int a,int b){
return a>b;
}
signed main(){
int _;
cin>>_;
while(_--){
int n;
scanf("%d",&n);
memset(price,,sizeof(price));
for(int i=;i<=n;i++){
scanf("%d",&price[i]);
sum[i]=;
}
sort(price+,price++n,cmp);
for(int i=;i<=n;i++){
sum[i]=sum[i-]+price[i];
}
int x,a,y,b,K;
scanf("%lld%lld%lld%lld%lld",&x,&a,&y,&b,&K);
int flag=;
int GCD=(a*b)/(__gcd(a,b));
for(int i=;i<=n;i++){
int numcom=i/GCD;
int numa=i/a-numcom;
int numb=i/b-numcom;
int ans1=((x+y)*sum[numcom]/)+(x*(sum[numcom+numa]-sum[numcom])/)+(y*(sum[numcom+numa+numb]-(sum[numcom+numa]))/);
int ans2=((x+y)*sum[numcom]/)+(y*(sum[numcom+numb]-sum[numcom])/)+(x*(sum[numcom+numa+numb]-(sum[numcom+numb]))/);
int maxn=max(ans1,ans2);
if(maxn>=K){
flag=;
printf("%d\n",i);
break;
}
}
if(flag){
continue;
}else{
printf("-1\n");
}
}
return ;
}

二分答案:

 #include<bits/stdc++.h>

 using namespace std;
#define int long long
#define N 250000
int price[N]; int sum[N];
int x,a,y,b,K;
bool cmp(int aa,int bb){
return aa>bb;
}
int ok(int m){
int vis[m+];
int GCD=(a*b)/(__gcd(a,b));
int numcom=m/GCD;
int numa=m/a-numcom;
int numb=m/b-numcom;
int ans1=((x+y)*sum[numcom]/)+(x*(sum[numcom+numa]-sum[numcom])/)+(y*(sum[numcom+numa+numb]-(sum[numcom+numa]))/);
int ans2=((x+y)*sum[numcom]/)+(y*(sum[numcom+numb]-sum[numcom])/)+(x*(sum[numcom+numa+numb]-(sum[numcom+numb]))/);
int maxn=max(ans1,ans2);
if(maxn>=K){
return ;
}else{
return ;
}
}
signed main(){
int _;
cin>>_;
while(_--){
int n;
scanf("%lld",&n);
for(int i=;i<=n;i++)
price[i]=;
for(int i=;i<=n;i++){
scanf("%lld",&price[i]);
}
sort(price+,price++n,cmp);
for(int i=;i<=n;i++)
sum[i]=sum[i-]+price[i]; scanf("%lld%lld%lld%lld%lld",&x,&a,&y,&b,&K);
int l=;
int r=n;
int ans=n+;
while(l<=r){
int mid=(l+r)/;
if(ok(mid)){
ans=min(ans,mid);
r=mid-;
}else{
l=mid+;
}
}
if(ans==n+){
printf("-1\n");
}else{
printf("%lld\n",ans);
}
}
return ;
}

Codeforces Round #591 (Div. 2, based on Technocup 2020 Elimination Round 1) C. Save the Nature【枚举二分答案】的更多相关文章

  1. Codeforces Round #591 (Div. 2, based on Technocup 2020 Elimination Round 1) D. Sequence Sorting

    链接: https://codeforces.com/contest/1241/problem/D 题意: You are given a sequence a1,a2,-,an, consistin ...

  2. Codeforces Round #591 (Div. 2, based on Technocup 2020 Elimination Round 1) B. Strings Equalization

    链接: https://codeforces.com/contest/1241/problem/B 题意: You are given two strings of equal length s an ...

  3. Codeforces Round #591 (Div. 2, based on Technocup 2020 Elimination Round 1) C. Save the Nature

    链接: https://codeforces.com/contest/1241/problem/C 题意: You are an environmental activist at heart but ...

  4. Codeforces Round #591 (Div. 2, based on Technocup 2020 Elimination Round 1) A. CME

    链接: https://codeforces.com/contest/1241/problem/A 题意: Let's denote correct match equation (we will d ...

  5. Codeforces Round #591 (Div. 2, based on Technocup 2020 Elimination Round 1)

    Virtual participate 的,D题不会做,打了1:30就打不动了,过了ABCE. A - CME 题意:? 题解:? void test_case() { int n; scanf(&q ...

  6. Codeforces Round #591 (Div. 2, based on Technocup 2020 Elimination Round 1) 题解

    A..B略 C 对当前的值排序,再二分答案,然后对于(i%x==0 && i%y==0)放入大的,再放其他的贪心解决即可. #include<iostream> #incl ...

  7. Codeforces Round #596 (Div. 2, based on Technocup 2020 Elimination Round 2)

    A - Forgetting Things 题意:给 \(a,b\) 两个数字的开头数字(1~9),求使得等式 \(a=b-1\) 成立的一组 \(a,b\) ,无解输出-1. 题解:很显然只有 \( ...

  8. Codeforces Round #602 (Div. 2, based on Technocup 2020 Elimination Round 3

    A,有多个线段,求一条最短的线段长度,能过覆盖到所又线段,例如(2,4)和(5,6) 那么我们需要4 5连起来,长度为1,例如(2,10)(3,11),用(3,10) 思路:我们想一下如果题目说的是最 ...

  9. 【cf比赛记录】Codeforces Round #606 (Div. 2, based on Technocup 2020 Elimination Round 4)

    比赛传送门 只能说当晚状态不佳吧,有点头疼感冒的症状.也跟脑子没转过来有关系,A题最后一步爆搜没能立即想出来,B题搜索没有用好STL,C题也因为前面两题弄崩了心态,最后,果然掉分了. A:简单数学 B ...

随机推荐

  1. JAVA支持字符编码读取文件

    文件操作,在java中很常用,对于存在特定编码的文件,则需要根据字符编码进行读取,要不容易出现乱码 /** * 读取文件 * @param filePath 文件路径 */ public static ...

  2. Excel计算、统计函数

    Excel计算.统计函数 1.=SUMPRODUCT(array1,[array2]...) ​ 返回对应的区域或数组的乘积之和. 默认运算是乘法,但加.减和除也可能. 2.=COUNT 计数 3.= ...

  3. 《统计学习方法》极简笔记P4:朴素贝叶斯公式推导

    <统计学习方法>极简笔记P4:朴素贝叶斯公式推导 朴素贝叶斯基本方法 通过训练数据集 T={(x_1,y_1),(x_2,y_2),(x_N,y_N)...,(x_1,y_1)} 学习联合 ...

  4. Python中下划线的5种含义

    目录 单前导下划线 _var 当涉及到变量和方法名称时,单个下划线前缀有一个约定俗成的含义. 它是对程序员的一个提示 - 意味着Python社区一致认为它应该是什么意思,但程序的行为不受影响. 单末尾 ...

  5. scratch少儿编程第一季——07、人要衣装佛靠金装——外观模块

    各位小伙伴大家好: 上期我们学习了如何设置背景,和设计一个小项目总结了动作模块. 本期开始我们学习外观模块下的指令. 首先我们来看看前面两个指令 第一个指令是在角色对象上出现一个对话框,显示角色所说的 ...

  6. 关于scanf()读取与返回值和回车键的问题

    今天老师检查的时候说如果一个链表为空(简单的说就是while(scanf())一开始没输入数字就按回车的话会进入死循环)的情况, 我当时有点懵,因为文档里强调为空的情况.还好老师叫我自己现场实现一下, ...

  7. Maven项目上总有一个小红叉问题

    一.maven project facet dynamic web module错误解决方案 在Eclipse中使用maven创建web-app的过程中总会遇到一个问题,cannot change v ...

  8. LaTeX技巧96:LaTeX 图片控制命令,位置控制

    LaTeX技巧96:LaTeX 图片控制命令,位置控制 2012-04-05 17:25:44 zd0303 阅读数 28512更多 分类专栏: Latex   LaTeX 控制图片的位置,就是加感叹 ...

  9. java.lang.ClassCastException: com.sun.proxy.$Proxy4 cannot be cast

    解决方案 在配置文件中配置proxy-target-class="true" <aop:aspectj-autoproxy proxy-target-class=" ...

  10. Interlocked

    Interlocked MSDN 描述:为多个线程共享的变量提供原子操作.主要函数如下: Interlocked.Increment 原子操作,递增指定变量的值并存储结果.Interlocked.De ...