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