Codeforces Round #415 (Div. 2) A B C 暴力 sort 规律
1 second
256 megabytes
standard input
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. 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.
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.
Print a single integer — minimal number of additional marks, that Leha has to add in order to change Noora's final mark to k.
2 10
8 9
4
3 5
4 4 4
3
Consider the first example testcase.
Maximal mark is 10, Noora received two marks — 8 and 9, so current final mark is 9. To fix it, Leha can add marks [10, 10, 10, 10] (4 marks in total) to the registry, achieving Noora having average mark equal to . Consequently, new final mark is 10. Less number of marks won't fix the situation.
In the second example Leha can add [5, 5, 5] to the registry, so that making average mark equal to 4.5, which is enough to have 5 in the certificate.
题意:给你n个数 以及k 增加ans个k使得 n+ans个数的平均数四舍五入的值为k 输出最小的ans
题解:暴力ans
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<vector>
#include<algorithm>
#define ll __int64
using namespace std;
int n,k;
int exm=,sum=;
int main()
{
exm=;
scanf("%d %d",&n,&k);
for(int i=;i<=n;i++){
scanf("%d",&exm);
sum+=exm;
}
for(int i=;i<;i++)
{
double what;
what=(double)(sum+k*i)/(n+i);
if(what>=double(k-0.5))
{
printf("%d\n",i);
return ;
}
}
return ;
}
1 second
256 megabytes
standard input
standard 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.
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.
Print a single integer denoting the maximal number of products that shop can sell.
4 2
2 1
3 5
2 3
1 5
10
4 1
0 2
0 3
3 5
0 6
5
In the first example we can choose days with numbers 2 and 4 for sell-out. In this case new numbers of products for sale would be equal to [2, 6, 2, 2] respectively. So on the first day shop will sell 1 product, on the second — 5, on the third — 2, on the fourth — 2. In total 1 + 5 + 2 + 2 = 10 product units.
In the second example it is possible to sell 5 products, if you choose third day for sell-out.
题意:给你n,f 以及n天的在售物品和顾客的情况 现在可以选择f天 将在售物品的数量翻倍 问如何选择 使得能够卖出的物品数量最大 输出这个值
题解:sort
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<vector>
#include<algorithm>
#define ll __int64
using namespace std;
struct node
{
ll k,l,we;
}N[];
int n,f;
bool cmp(struct node aa,struct node bb)
{
return aa.we>bb.we;
}
int main()
{
scanf("%d %d",&n,&f);
ll a,b;
ll exm=;
for(int i=;i<=n;i++){
scanf("%I64d %I64d",&a,&b);
if(a>=b){
exm+=b;
N[i].k=*a-b;;
N[i].l=;
N[i].we=;
}
else{
exm+=a;
N[i].k=a;
N[i].l=b-a;
N[i].we=min(a,b-a);
}
}
sort(N+,N++n,cmp);
for(int i=;i<=f;i++)
exm+=N[i].we;
printf("%I64d\n",exm);
return ;
}
2 seconds
256 megabytes
standard input
standard 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.
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.
Print a single integer — the required sum modulo 109 + 7.
2
4 7
3
3
4 3 1
9
There are three non-empty subsets in the first sample test:,
and
. The first and the second subset increase the sum by 0 and the third subset increases the sum by 7 - 4 = 3. In total the answer is 0 + 0 + 3 = 3.
There are seven non-empty subsets in the second sample test. Among them only the following subsets increase the answer: ,
,
,
. In total the sum is (4 - 3) + (4 - 1) + (3 - 1) + (4 - 1) = 9.
题意:给你n个值 处理序列的所有子集 将所有子集的权值求和输出 权值的定义:当前集合中最大值与最小值的差值
题解:先将原序列排序 写出所有的子集 以及集合中对权值贡献的最大值以及最小值 统计每个数输出的次数 可以发现规律;
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<vector>
#include<algorithm>
#define ll __int64
#define mod 1000000007
using namespace std;
int n;
ll a[];
ll er[];
int main()
{
scanf("%d",&n);
for(int i=; i<=n; i++)
scanf("%I64d",&a[i]);
ll e=;
er[]=;
for(int i=; i<=n; i++){
e*=;
e%=mod;
er[i]=e;
}
sort(a+,a++n);
ll sum1=,sum2=;
for(int i=n; i>=; i--)
sum1=(sum1+(er[i-]-)*a[i]%mod)%mod;
for(int i=n; i>=; i--)
sum2=(sum2+(er[n-i]-)*a[i]%mod)%mod;
printf("%I64d\n",(sum1-sum2+mod)%mod);
return ;
}
Codeforces Round #415 (Div. 2) A B C 暴力 sort 规律的更多相关文章
- Codeforces Round #415 (Div. 2)(A,暴力,B,贪心,排序)
A. Straight «A» time limit per test:1 second memory limit per test:256 megabytes input:standard inpu ...
- Codeforces Round#415 Div.2
A. Straight «A» 题面 Noora is a student of one famous high school. It's her final year in school - she ...
- Codeforces Round #415(Div. 2)-810A.。。。 810B.。。。 810C.。。。不会
CodeForces - 810A A. Straight «A» time limit per test 1 second memory limit per test 256 megabytes i ...
- Codeforces Round #415 Div. 1
A:考虑每对最大值最小值的贡献即可. #include<iostream> #include<cstdio> #include<cmath> #include< ...
- Codeforces Round #415 (Div. 2)C
反正又是一个半小时没做出来... 先排序,然后求和,第i个和第j个,f(a)=a[j]-a[i]=a[i]*(2^(j-i-1))因为从j到i之间有j-i-1个数(存在或者不存在有两种情况) 又有a[ ...
- 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, ...
- Codeforces Round #415 (Div. 2) B. Summer sell-off
B. Summer sell-off time limit per test 1 second memory limit per test 256 megabytes Summer hol ...
- Codeforces Round #415 (Div. 2) 翻车啦
A. Straight «A» time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...
- Codeforces Round #415 (Div. 1) (CDE)
1. CF 809C Find a car 大意: 给定一个$1e9\times 1e9$的矩阵$a$, $a_{i,j}$为它正上方和正左方未出现过的最小数, 每个询问求一个矩形内的和. 可以发现$ ...
随机推荐
- Centos7下安装Seafile实现私有网盘
Seafile是一个开源.专业.可靠的云存储平台:解决文件集中存储.共享和跨平台访问等问题,由北京海文互知网络有限公司开发,发布于2012年10月:除了一般网盘所提供的云存储以及共享功能外,Seafi ...
- java运行时内存分类
主要有java栈(虚拟机栈), 堆 ,方法区. 线程私有: 栈: 每个方法执行的时候 都会同时创建一个栈桢 Stack Frame 用于存储 局部变量表, 操作数栈,动态链接, 方法出口等信息 线程 ...
- javascript提高篇
本章简介 本章内容比较少,有三个分享的知识.你可能都看过了,因为网上也有很多提问和解答,如果没看过或者没搞懂,你可以再看看这篇文章. 1. 数组去重方法的演变 -- 走向代码缩短化 2. [] ...
- 今目标登录时报网络错误E110
今目标登录的时候报错了,错误代码:E110不论怎么修改都修复不了,百度相关资料也没有,只能联系客服. 经过好久终于联系上了客服,客服给出的解决方案是修改:Enternet选项: 第一步:打开,控制面板 ...
- DB2 UDB V8.1 管理
在DB2中有关实例(Instance), 数据库(Database),表空间(TableSpace),容器(Container)等概念: 在一个操作系统中,DB2数据服务可以同时运行多个实例(有别于O ...
- 使用ssh公钥登陆
记录一下使用的具体命令,具体参考: Centos设置禁止密码登录而只使用密钥登录SSH方法 优先参考这个. ssh使用公钥授权不通过的问题解决 Xshell配置ssh免密码登录-密钥公钥(Publi ...
- 删除多余的自编译的内核、mysql连接不了的问题
1.删除多余的自编译的内核 每次Debian发布内核更新,总是有某些内核选项跟自己的硬件不配套,要自己编译内核.编译多了,多余的内核就占用了多余的硬盘空间.我就试过因为/boot分区满了,而导致编译内 ...
- jsonFormater之应用
html代码: <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> ...
- [历史百科]抗战时期兵团简介 From 百度知道
中央军委1948年11月1日和1949年1月15日两次关于统一全军组织和部队番号的训令,我军先后进行了整编.西北野战军改称第一野战军,司令员兼政治委员彭德怀,第一副司令员张宗逊,第二副司令员赵寿山,参 ...
- 这套C#编码规范写不错
自己总结的C#编码规范--1.命名约定篇:http://www.cnblogs.com/luzhihua55/p/CodingConventions1.html 自己总结的C#编码规范--2.命名选择 ...