CF Round 415 Div.2解题报告

10 篇文章 0 订阅
7 篇文章 0 订阅

由于是晚上2点的比赛,打了一个小时就撑不住了,溜了。。。只做了3题,下面上题。
题目:A. Straight «A»
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard 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. However, she has to get an «A» graduation certificate in order to apply to a prestigious one.

In school, where Noora is studying, teachers are putting down marks to the online class register, which are integers from 1 to k. The worst mark is 1, the best is k. Mark that is going to the certificate, is calculated as an average of all the marks, rounded to the closest integer. If several answers are possible, rounding up is produced. For example, 7.3 is rounded to 7, but 7.5 and 7.8784 — to 8.

For instance, if Noora has marks [8, 9], then the mark to the certificate is 9, because the average is equal to 8.5 and rounded to 9, but if the marks are [8, 8, 9], Noora will have graduation certificate with 8.

To graduate with «A» certificate, Noora has to have mark k.

Noora got n marks in register this year. However, she is afraid that her marks are not enough to get final mark k. Noora decided to ask for help in the internet, where hacker Leha immediately responded to her request. He is ready to hack class register for Noora and to add Noora any number of additional marks from 1 to k. At the same time, Leha want his hack be unseen to everyone, so he decided to add as less as possible additional marks. Please help Leha to calculate the minimal number of marks he has to add, so that final Noora’s mark will become equal to k.

Input
The first line contains two integers n and k (1 ≤ n ≤ 100, 1 ≤ k ≤ 100) denoting the number of marks, received by Noora and the value of highest possible mark.

The second line contains n integers a1, a2, …, an (1 ≤ ai ≤ k) denoting marks received by Noora before Leha’s hack.

Output
Print a single integer — minimal number of additional marks, that Leha has to add in order to change Noora’s final mark to k.

Examples
input
2 10
8 9
output
4

题意:简单点来说就是问最少添几个k使得原来所有数和现在这添上的几个k,这些数的平均数是要>=k-1/2的.所以因为数据不大,直接暴力就可以了
代码:

#include<iostream>
#include<cstring>
#include<math.h>
#include<cstdio>
#include<algorithm>
#define N 6005
#define INF 0x3f3f3f3f
#include<map>
#include<string>
#include<queue>
#include<vector>
#include<set>
#define mod 1000000007
double pi=acos(-1.0);
typedef long long ll;
using namespace std;
int n,k;
int a[105];
int main(){
    cin>>n>>k;
    ll sum=0;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        sum+=a[i];
    }
    int ans;
    for(int j=0;;j++)
    {
        if((n+j)*(2*k-1)<=2*(sum+j*k))
        {
            ans=j;
            break;
        }
    }
    cout<<ans<<endl;
    return 0;
} 

B. Summer sell-off
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
Summer holidays! Someone is going on trips, someone is visiting grandparents, but someone is trying to get a part-time job. This summer Noora decided that she wants to earn some money, and took a job in a shop as an assistant.

Shop, where Noora is working, has a plan on the following n days. For each day sales manager knows exactly, that in i-th day ki products will be put up for sale and exactly li clients will come to the shop that day. Also, the manager is sure, that everyone, who comes to the shop, buys exactly one product or, if there aren’t any left, leaves the shop without buying anything. Moreover, due to the short shelf-life of the products, manager established the following rule: if some part of the products left on the shelves at the end of the day, that products aren’t kept on the next day and are sent to the dump.

For advertising purposes manager offered to start a sell-out in the shop. He asked Noora to choose any f days from n next for sell-outs. On each of f chosen days the number of products were put up for sale would be doubled. Thus, if on i-th day shop planned to put up for sale ki products and Noora has chosen this day for sell-out, shelves of the shop would keep 2·ki products. Consequently, there is an opportunity to sell two times more products on days of sell-out.

Noora’s task is to choose f days to maximize total number of sold products. She asks you to help her with such a difficult problem.

Input
The first line contains two integers n and f (1 ≤ n ≤ 105, 0 ≤ f ≤ n) denoting the number of days in shop’s plan and the number of days that Noora has to choose for sell-out.

Each line of the following n subsequent lines contains two integers ki, li (0 ≤ ki, li ≤ 109) denoting the number of products on the shelves of the shop on the i-th day and the number of clients that will come to the shop on i-th day.

Output
Print a single integer denoting the maximal number of products that shop can sell.

题意:给你n天的每天的物品数和顾客数,选f天每天的物品数量变成2倍,问n填最多可以卖出去多少物品。

思路:问题在于怎么去选f天最赚。那么我们只需要看哪f天变成2倍比不变成2倍卖出去更多。我是用了一个单调队列来实现的。这样存起来,扫一遍就可以了
代码:

#include<iostream>
#include<cstring>
#include<math.h>
#include<cstdio>
#include<algorithm>
#define N 6005
#define INF 0x3f3f3f3f
#include<map>
#include<string>
#include<queue>
#include<vector>
#include<set>
#define mod 1000000007
double pi=acos(-1.0);
typedef long long ll;
using namespace std;
int n,f;
ll k[100005],l[100005];
typedef pair<int,int> p;
priority_queue<p> q;
int vis[100005];
struct node{
    ll val,pos;
    node(){}
    node(ll x,ll y)
    {
        val=x,pos=y;
    }
}g[100005];

int main(){
    memset(vis,0,sizeof(vis));
    cin>>n>>f;
    ll sum=0;
    for(int i=0;i<n;i++)
    {
        cin>>k[i]>>l[i];
        g[i]=node(min(k[i],l[i]),i);
        q.push(make_pair(min(2*k[i],l[i])-min(k[i],l[i]),i));
    }
    while(f--)
    {
        sum+=(q.top().first+g[q.top().second].val);
        vis[q.top().second]=1;
        q.pop();
    }

    for(int i=0;i<n;i++)
    {
        if(!vis[i]) sum+=g[i].val;
    }
    cout<<sum<<endl;
    return 0;
} 

C. Do you want a date?
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
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 get access to n computers throughout the town. Incidentally all the computers, which were hacked by Leha, lie on the same straight line, due to the reason that there is the only one straight street in Vičkopolis.

Let’s denote the coordinate system on this street. Besides let’s number all the hacked computers with integers from 1 to n. So the i-th hacked computer is located at the point xi. Moreover the coordinates of all computers are distinct.

Leha is determined to have a little rest after a hard week. Therefore he is going to invite his friend Noora to a restaurant. However the girl agrees to go on a date with the only one condition: Leha have to solve a simple task.

Leha should calculate a sum of F(a) for all a, where a is a non-empty subset of the set, that consists of all hacked computers. Formally, let’s denote A the set of all integers from 1 to n. Noora asks the hacker to find value of the expression . Here F(a) is calculated as the maximum among the distances between all pairs of computers from the set a. Formally, . Since the required sum can be quite large Noora asks to find it modulo 109 + 7.

Though, Leha is too tired. Consequently he is not able to solve this task. Help the hacker to attend a date.

Input
The first line contains one integer n (1 ≤ n ≤ 3·105) denoting the number of hacked computers.

The second line contains n integers x1, x2, …, xn (1 ≤ xi ≤ 109) denoting the coordinates of hacked computers. It is guaranteed that all xi are distinct.

Output
Print a single integer — the required sum modulo 1e9 + 7.
题意:对于一个集合而言,如果设每个子集的最大数减最小数的值为d,求所有d的和是多少。

思路:我感觉我好像是做烦了,搞了个傻逼dp。我是设dp[i]为前i个数的所有子集得到的结果。那么dp[i]=dp[i-1]+2^(i-2)*(x[i]-x[0])+2^(i-3)(x[i]-x[1])……+2^0(x[i]-x[i-1]);然后设f[i]为dp[i-1]后面那个式子的值,则容易知道f[i]=2f[i-1]+(2^(i-1)-1)(x[i]-x[i-1]);
所以又因为dp[i]=dp[i-1]+f[i],结果就很容易出来了。
代码:

#include<iostream>
#include<cstring>
#include<math.h>
#include<cstdio>
#include<algorithm>
#define N 6005
#define INF 0x3f3f3f3f
#include<map>
#include<string>
#include<queue>
#include<vector>
#include<set>
#define mod 1000000007
double pi=acos(-1.0);
typedef long long ll;
using namespace std;
ll n,f[400005],dp[400005],x[400006],cun[400005];
int main(){
    cin>>n;
    cun[0]=1;
    for(int i=1;i<=400000;i++)
        cun[i]=(cun[i-1]*2)%mod;
    for(int i=1;i<=n;i++)
        scanf("%I64d",&x[i]);
    sort(x+1,x+n+1);
    dp[0]=dp[1]=0;
    f[1]=0;
    for(int i=2;i<=n;i++)
        f[i]=(2*f[i-1]%mod+(cun[i-1]-1)*(x[i]-x[i-1])%mod)%mod;
    for(int i=2;i<=n;i++)
        dp[i]=(dp[i-1]+f[i])%mod;
    cout<<dp[n]<<endl;
    return 0;
} 

下面两题已经没有力气看了,回头再补吧

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值