Codeforces Round #415 (Div. 2) B. Summer sell-off(贪心+结构体排序)

题目链接:http://codeforces.com/contest/810/problem/B

题意:给定天数和货物可以翻倍的天数,每天都有一定的货物量和顾客数,问怎么样货物才能卖得最多(前一天的货物不会留到下一天,每个顾客只能买一个货物)。

简单的贪心问题,贪心策略是:如果两倍的货物量卖出去的更多,就选两倍的,否则就选一倍的。

那一天能卖出去的货物量:min(货物量,顾客数)。然后根据结构体排序一下就ok了

 1 #include <iostream>
 2 #include <algorithm>
 3 using namespace std;
 4
 5 const int N=1e5+10;
 6
 7 struct TnT{
 8     long long k;
 9     long long l;
10 }T[N];
11
12 bool cmp(TnT a,TnT b){
13     return (min(2*a.k,a.l)-min(a.k,a.l))>(min(2*b.k,b.l)-min(b.k,b.l));
14 }
15
16 int main(){
17     long long n,f,res=0;
18     cin>>n>>f;
19     for(int i=0;i<n;i++){
20         cin>>T[i].k>>T[i].l;
21     }
22     sort(T,T+n,cmp);
23     for(int i=0;i<n;i++){
24         if(f>0) {res+=min(2*T[i].k,T[i].l);f--;}
25         else res+=min(T[i].k,T[i].l);
26     }
27     cout<<res<<endl;
28     return 0;
29 }
时间: 2024-11-01 12:25:32

Codeforces Round #415 (Div. 2) B. Summer sell-off(贪心+结构体排序)的相关文章

Codeforces Round #417 (Div. 2) C. Sagheer and Nubian Market 二分答案 +排序

Codeforces Round #417 (Div. 2) C. Sagheer and Nubian Market 二分答案 +排序 题意 有 a[ i ] 个数 要求选最多的数 使其和不超过 S ,且在此情况下,和最小选最多数情况下 和最小 且 每个数有加成 如果选了 k个数 那么加成后 就是 a[ i ] + k*i ; 题解 二分mid 表示选了个数 加成一下,将加成以后结果排序一下 , 若前 mid数 和大于 s 则此方案不可行 PS 要用 long long ..... 还有 co

Codeforces Round #415 (Div. 2)(A,暴力,B,贪心,排序)

A. Straight «A» time limit per test:1 second memory limit per test:256 megabytes input:standard input output:standard output Noora is a student of one famous high school. It's her final year in school — she is going to study in university next year.

Codeforces Round #415 (Div. 2)

Straight <<A>> 暴力模拟一下. #include <iostream> #include <algorithm> #include <cmath> using namespace std; int main() { int n,k; cin>>n>>k; double sum = 0; for(int i=0;i<n;i++) { int x; cin>>x; sum += x; } dou

Codeforces Round #415 (Div. 2) C. Do you want a date?

C. Do you want a date? 2 seconds 256 megabytes Leha decided to move to a quiet town Vi?kopolis, because he was tired by living in Bankopolis. Upon arrival he immediately began to expand his network of hacked computers. During the week Leha managed to

(二分)Codeforces Round #415 (Div. 2) D-Glad to see you!

This is an interactive problem. In the output section below you will see the information about flushing the output. On Sunday Leha the hacker took Nura from the house where she lives and went with her to one of the most luxurious restaurants in Vi?ko

Codeforces Round #329 (Div. 2)B. Anton and Lines 贪心

B. Anton and Lines The teacher gave Anton a large geometry homework, but he didn't do it (as usual) as he participated in a regular round on Codeforces. In the task he was given a set of n lines defined by the equations y = ki·x + bi. It was necessar

Codeforces Round #FF (Div. 2) D. DZY Loves Modification 贪心+优先队列

链接:http://codeforces.com/problemset/problem/447/D 题意:一个n*m的矩阵.能够进行k次操作,每次操作室对某一行或某一列的的数都减p,获得的得分是这一行或列原来的数字之和.求N次操作之后得到的最高得分是多少. 思路:首先分别统计每行和每列的数字和. 进行的k次操作中,有i次操作是对行进行操作,剩余k-i次操作是对列进行操作. 首先在操作中忽略每次操作中行对列的影响,然后计算列的时候,最后能够计算出,总共的影响是i*(k-i)*p. 找出对于每一个i

Codeforces Round #257 (Div. 2)449A - Jzzhu and Chocolate(贪心、数学)

题目链接:http://codeforces.com/problemset/problem/449/A ---------------------------------------------------------------------------------------------------------------------------------------------------------- 欢迎光临天资小屋:http://user.qzone.qq.com/593830943

Codeforces Round #629 (Div. 3) D. Carousel(思维/贪心?)

The round carousel consists of nn figures of animals. Figures are numbered from 11 to nn in order of the carousel moving. Thus, after the nn -th figure the figure with the number 11 follows. Each figure has its own type — the type of the animal corre