A. Straight «A»

题面

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.

题意

问加多少人能拉高平均分达到目标,可以二分,但是我直接暴力。

代码

#include<bits/stdc++.h>
using namespace std; int n,k,m;
double sum;
int cnt; int main()
{
ios::sync_with_stdio(false);
cin>>n>>k;
for (int i=1;i<=n;i++)
{
cin>>m;
sum+=m*1.0;
}
for (int i=0;;i++)
{
if (floor((sum+i*(double)k)/(i+n)+0.5)==k)
{
cout<<i;
return 0;
}
}
}

B. Summer sell-off

题面

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.

题意

问改变哪几天的货物储藏量,能够卖的最好

直接sort贪心。我们优先选择能多卖的那几天。

代码

#include<bits/stdc++.h>
using namespace std; using ll=long long;
int n;
int k;
pair<ll,ll> a[100010];
ll x,y;
ll ans; int cmp(pair<ll,ll> q,pair<ll,ll> w)
{
return (min(q.first*2,q.second)-q.first > min(w.first*2,w.second)-w.first);
} int main()
{
ios::sync_with_stdio(false);
cin>>n>>k;
for (int i=1;i<=n;i++)
{
cin>>x>>y;
a[i]=make_pair(x,y);
}
sort(a+1,a+n+1,cmp);
for (int i=1;i<=k;i++) ans+=min(a[i].first*2,a[i].second);
for (int i=k+1;i<=n;i++) ans+=min(a[i].first,a[i].second);
cout<<ans;
}

C - Do you want a date?

题面

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.

题意

求所有子集的极差之和。

我们先sort一遍,然后可以发现,我们可以枚举极差,这样做是O(N^2),显然不够

但是我们又发现,每个数加上去的次数,和减去的次数是可以求的。

直接做O(NlgN) (sort复杂度)

代码

#include<bits/stdc++.h>
using namespace std; using ll = long long;
int n;
ll a[300010];
ll er[300010];
const ll MOD=1e9+7; ll ans1;
ll ans2; int cmp(ll q,ll w)
{
return q<w;
} int main()
{
ios::sync_with_stdio(false);
cin>>n;
for (int i=1;i<=n;i++) cin>>a[i];
sort(a+1,a+n+1,cmp);
er[0]=1;
for (int i=1;i<=n;i++) er[i]=(er[i-1]*2)%MOD; for (int i=n;i>=2;i--) ans1=(ans1+a[i]*(er[i-1]-1))%MOD;
for (int i=1;i<n ;i++) ans2=(ans2+a[i]*(er[n-i]-1))%MOD; cout<<(ans1+MOD-ans2)%MOD;
}

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čkopolis. Upon arrival, they left the car in a huge parking lot near the restaurant and hurried inside the building.

In the restaurant a polite waiter immediately brought the menu to Leha and Noora, consisting of n dishes. It is interesting that all dishes in the menu are numbered with integers from 1 to n. After a little thought, the girl ordered exactly k different dishes from available in the menu. To pass the waiting time while the chefs prepare ordered dishes, the girl invited the hacker to play a game that will help them get to know each other better.

The game itself is very simple: Noora wants Leha to guess any two dishes among all ordered. At the same time, she is ready to answer only one type of questions. Leha can say two numbers x and y (1 ≤ x, y ≤ n). After that Noora chooses some dish a for the number x such that, at first, a is among the dishes Noora ordered (x can be equal to a), and, secondly, the value is the minimum possible. By the same rules the girl chooses dish b for y. After that Noora says «TAK» to Leha, if , and «NIE» otherwise. However, the restaurant is preparing quickly, so Leha has enough time to ask no more than 60 questions. After that he should name numbers of any two dishes Noora ordered.

Help Leha to solve this problem!

题意

第一次做交互题目,大概意思是你猜两个数字,他告诉你他想的数字跟你猜的数字的距离如何,定位任意两个数字。

考虑某个菜,我猜x,x+1,如果返回<=。显然离x+1更近,所以二分。

边界处理上需要细致。

代码

#include<bits/stdc++.h>
using namespace std; int n,k;
int ans1,ans2;
string d; int find(int l,int r)
{
if (l>r) return -1;
if (l==r)
return l;
int mid=(l+r)>>1;
cout<<1<<" "<<mid<<" "<<mid+1<<endl;
fflush(stdout);
cin>>d;
if (d=="NIE") l=mid+1;else r=mid;
find(l,r);
} int main()
{
ios::sync_with_stdio(false);
cin>>n>>k;
ans1=find(1,n); if (ans1 > 1) {
ans2 = find(1, ans1-1);
cout << "1 " << ans2 << " " << ans1 << endl;
fflush(stdout);
cin >> d;
if (d == "TAK") {
cout << "2 " << ans1 << " " << ans2 << endl;
return 0;
}
}
ans2 = find(ans1+1, n);
cout << "2 " << ans1 << " " << ans2 << endl;
return 0;
}

E. Find a car

题面

After a wonderful evening in the restaurant the time to go home came. Leha as a true gentlemen suggested Noora to give her a lift. Certainly the girl agreed with pleasure. Suddenly one problem appeared: Leha cannot find his car on a huge parking near the restaurant. So he decided to turn to the watchman for help.

Formally the parking can be represented as a matrix 109 × 109. There is exactly one car in every cell of the matrix. All cars have their own machine numbers represented as a positive integer. Let's index the columns of the matrix by integers from 1 to 109 from left to right and the rows by integers from 1 to 109 from top to bottom. By coincidence it turned out, that for every cell (x, y) the number of the car, which stands in this cell, is equal to the minimum positive integer, which can't be found in the cells (i, y) and (x, j), 1 ≤ i < x, 1 ≤ j < y.

The upper left fragment 5 × 5 of the parking

Leha wants to ask the watchman q requests, which can help him to find his car. Every request is represented as five integers x1, y1, x2, y2, k. The watchman have to consider all cells (x, y) of the matrix, such that x1 ≤ x ≤ x2 and y1 ≤ y ≤ y2, and if the number of the car in cell (x, y) does not exceed k, increase the answer to the request by the number of the car in cell (x, y). For each request Leha asks the watchman to tell him the resulting sum. Due to the fact that the sum can turn out to be quite large, hacker asks to calculate it modulo 109 + 7.

However the requests seem to be impracticable for the watchman. Help the watchman to answer all Leha's requests.

题意

给出一个区间,求区间内不大于k的数的总和。

由于该广场极其自相似。该广场还炒鸡大。

在做题的时候把时间都浪费在这个上面了。如果能细致地处理一下D,可能就上天辣哈哈哈~

代码

//

比赛总结

如果D题能处理更好一点的话,我就能上第一页辣QWQ

比赛链接

http://codeforces.com/contest/810

Codeforces Round#415 Div.2的更多相关文章

  1. 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 ...

  2. 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 ...

  3. Codeforces Round #415 Div. 1

    A:考虑每对最大值最小值的贡献即可. #include<iostream> #include<cstdio> #include<cmath> #include< ...

  4. 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[ ...

  5. Codeforces Round #415 (Div. 2) A B C 暴力 sort 规律

    A. Straight «A» time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...

  6. 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, ...

  7. 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 ...

  8. Codeforces Round #415 (Div. 2) 翻车啦

    A. Straight «A» time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...

  9. Codeforces Round #415 (Div. 1) (CDE)

    1. CF 809C Find a car 大意: 给定一个$1e9\times 1e9$的矩阵$a$, $a_{i,j}$为它正上方和正左方未出现过的最小数, 每个询问求一个矩形内的和. 可以发现$ ...

随机推荐

  1. Mac下JDK、Maven、Tomcat、Git开发安装及环境变量配置

    本文主要内容: - 1.Mac OS 10.11.6 [OS X EL Captain] - 2.Mac OS 安装Java 设置环境变量 - 3.Mac OS 安装Maven设置环境变量 - 4.M ...

  2. jquery过滤class为aa的div

    三种方式 $(".aa").filter("div").each(function(){ alert($(this).html()); }); $(" ...

  3. .net如何处理高并发socket,建立高性能健壮的socket服务

    看到一个问题,说如何保持5000-10000+的健壮的socket服务. 初学者肯定是会把每个连接都开一个线程来监听.这很浪费资源 通常只会(动态地)占用几个线程就能保持3000个长连接会话了.“为每 ...

  4. C# 一个数组未赋值引发的错误

    在电脑前又是一天,后来脑子也糊里糊涂,可能是基础还不牢固,设置断点,找了找问题才发现数组定义出了问题, 我是这样定义数组的,string[] auths ; string auths=new stri ...

  5. hdu 1686 & poj 2406 & poj 2752 (KMP入门三弹连发)

    首先第一题 戳我穿越;http://acm.hdu.edu.cn/showproblem.php?pid=1686 题目大意好理解,每组输入一个子串和一个母串,问在母串中有多少个子串? 文明人不要暴力 ...

  6. [都是原创]Php simplexml 添加节点

    Php simplexml 添加节点 原始代码如下 //================<? //创建xml对象$xml = new SimpleXMLElement('<Messages ...

  7. 解决linux ubuntu不能识别华为手机的问题--升级内核

    敝人手中有一个华为mate8,但是debian, ubuntu及一系列衍生版均不能识别.只能识别出一个华为手机助手,但是无法使用华为的内置存贮. 在fedora上是可以完美使用的. 归根到底的原因,是 ...

  8. ListView嵌套 EditText的光标不显示

    ListView嵌套EditView,有可能会出现了下面现象: 点击EditView,EditView获取焦点后,有可能光标不显示,也有可能光标不闪烁.点击多次后,光标才正常显示. 获取焦点后,edi ...

  9. 提升HTML5的性能体验系列之四 使用原生UI

    原生UI的设计目的 HTML和css有一个优势就是灵活的样式设计.在大多数情况下,我们都应该使用HTML+css来负责UI.但是有些情况下,我们发现HTML+css的UI不满足需求.1. 绝对置顶HT ...

  10. mybatis不报错,但是查询结果为0

    [转载]https://blog.csdn.net/shenzhenNBA/article/details/46673327 在用MyBatis操作数据库的时候相信很多人都用到,当在判断null, 大 ...