Codeforces Round #251 (Div. 2) A/B/D
A。水題。
Devu is a renowned classical singer. He is invited to many big functions/festivals. Recently he was invited to "All World Classical Singing Festival". Other than Devu, comedian Churu was also invited.
Devu has provided organizers a list of the songs and required time for singing them. He will sing n songs, ith song will take ti minutes exactly.
The Comedian, Churu will crack jokes. All his jokes are of 5 minutes exactly.
People have mainly come to listen Devu. But you know that he needs rest of 10 minutes after each song. On the other hand, Churu being a very active person, doesn't need any rest.
You as one of the organizers should make an optimal sсhedule for the event. For some reasons you must follow the conditions:
- The duration of the event must be no more than d minutes;
- Devu must complete all his songs;
- With satisfying the two previous conditions the number of jokes cracked by Churu should be as many as possible.
If it is not possible to find a way to conduct all the songs of the Devu, output -1. Otherwise find out maximum number of jokes that Churu can crack in the grand event.
The first line contains two space separated integers n, d (1 ≤ n ≤ 100; 1 ≤ d ≤ 10000). The second line contains n space-separated integers: t1, t2, ..., tn (1 ≤ ti ≤ 100).
If there is no way to conduct all the songs of Devu, output -1. Otherwise output the maximum number of jokes that Churu can crack in the grand event.
3 30 2 2 1
5
3 20 2 1 1
-1
#include <algorithm>
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <iomanip>
#include <stdio.h>
#include <string>
#include <queue>
#include <cmath>
#include <stack>
#include <map>
#include <set>
#define eps 1e-8
#define M 1000100
//#define LL __int64
#define LL long long
#define INF 0x7f3f3ff
#define PI 3.1415926535898
const int maxn = 10010;
using namespace std;
int main()
{
int n, d;
while(cin >>n>>d)
{
int sum = 0;
int x;
for(int i = 1; i <= n; i++)
{
cin >>x;
sum += x;
}
sum += (n-1)*10;
if(sum <= d)
{
int t = (n-1)*2+(d-sum)/5;
cout<<t<<endl;
}
else
cout<<"-1"<<endl;
}
return 0;
}
B.注意資料型別啊,int*int即使你用long long 存,也是int、、然後就悲劇了啊、、細節啊
Devu is a dumb guy, his learning curve is very slow. You are supposed to teach him n subjects, the ith subject has ci chapters. When you teach him, you are supposed to teach all the chapters of a subject continuously.
Let us say that his initial per chapter learning power of a subject is x hours. In other words he can learn a chapter of a particular subject in x hours.
Well Devu is not complete dumb, there is a good thing about him too. If you teach him a subject, then time required to teach any chapter of the next subject will require exactly 1 hour less than previously required (see the examples to understand it more clearly). Note that his per chapter learning power can not be less than 1 hour.
You can teach him the n subjects in any possible order. Find out minimum amount of time (in hours) Devu will take to understand all the subjects and you will be free to do some enjoying task rather than teaching a dumb guy.
Please be careful that answer might not fit in 32 bit data type.
The first line will contain two space separated integers n, x (1 ≤ n, x ≤ 105). The next line will contain n space separated integers:c1, c2, ..., cn (1 ≤ ci ≤ 105).
Output a single integer representing the answer to the problem.
2 3 4 1
11
4 2 5 1 2 1
10
3 3 1 1 1
6
#include <algorithm>
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <iomanip>
#include <stdio.h>
#include <string>
#include <queue>
#include <cmath>
#include <stack>
#include <map>
#include <set>
#define eps 1e-8
#define M 1000100
//#define LL __int64
#define LL long long
#define INF 0x7f3f3ff
#define PI 3.1415926535898
const int maxn = 1000010;
using namespace std;
LL num[maxn];
int main()
{
LL n, m;
while(cin >>n>>m)
{
for(int i = 0; i < n; i++)
cin >>num[i];
sort(num, num+n);
LL cnt = 0;
for(int i = 0; i < n; i++)
{
cnt += num[i]*m;
if(m > 1)
m--;
}
cout<<cnt<<endl;
}
return 0;
}
D。這隻能說是太年輕啊、、、終於遇見了會的題目了啊,感覺什麼都沒問題,無奈三分怎麼寫都不對,後來發現要牽扯到實數的列舉啊、、發現了兩個函式:
floor 功 能: 返回小於或者等於指定表示式的最大整數 用 法: double floor(double x)
ceil 功 能: 返回大於或者等於指定表示式的最小整數 用法: double ceil(double x);
Devu and his brother love each other a lot. As they are super geeks, they only like to play with arrays. They are given two arrays a and bby their father. The array a is given to Devu and b to his brother.
As Devu is really a naughty kid, he wants the minimum value of his array a should be at least as much as the maximum value of his brother's array b.
Now you have to help Devu in achieving this condition. You can perform multiple operations on the arrays. In a single operation, you are allowed to decrease or increase any element of any of the arrays by 1. Note that you are allowed to apply the operation on any index of the array multiple times.
You need to find minimum number of operations required to satisfy Devu's condition so that the brothers can play peacefully without fighting.
The first line contains two space-separated integers n, m (1 ≤ n, m ≤ 105). The second line will contain n space-separated integers representing content of the array a (1 ≤ ai ≤ 109). The third line will contain m space-separated integers representing content of the array b (1 ≤ bi ≤ 109).
You need to output a single integer representing the minimum number of operations needed to satisfy Devu's condition.
2 2 2 3 3 5
3
3 2 1 2 3 3 4
4
3 2 4 5 6 1 2
0
#include <algorithm>
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <iomanip>
#include <stdio.h>
#include <string>
#include <queue>
#include <cmath>
#include <stack>
#include <map>
#include <set>
#define eps 1e-4
#define M 1000100
//#define LL __int64
#define LL long long
#define INF 0x7ffffff
#define PI 3.1415926535898
const int maxn = 1000010;
using namespace std;
int f[maxn];
int p[maxn];
int n, m;
LL Count(int x)
{
LL cnt = 0;
for(int i = 0; i < n; i++)
if(f[i] < x)
cnt += x-f[i];
for(int i = 0; i < m; i++)
if(p[i] > x)
cnt += p[i]-x;
return cnt;
}
int main()
{
while(cin >>n>>m)
{
for(int i = 0; i < n; i++)
cin >>f[i];
for(int i = 0; i < m; i++)
cin >>p[i];
LL sum = 1e18;
LL cnt, cnt1;
double l = 1;
double r = 1e9;
while(l < r-eps)
{
double lmid = l+(r-l)/3;
double rmid = r-(r-l)/3;
cnt = Count(floor(lmid));// 返回小於或者等於指定表示式的最大整數
cnt1 = Count(ceil(rmid));//返回大於或者等於指定表示式的最小整數
if(cnt < cnt1)
r = rmid;
else
l = lmid;
sum = min(cnt, min(sum, cnt1));
}
cout<<sum<<endl;
}
return 0;
}
相關文章
- Codeforces Round #251 (Div. 2) B. Devu, the Dumb Guydev
- Codeforces Round #290 (Div. 2) A,B,C,D
- Codeforces Round #288 (Div. 2) A,B,C,D,E
- Codeforces Round #287 (Div. 2)A,B,C,D,E
- Codeforces Round #280 (Div. 2 A,B,C,D,E)
- Codeforces Round #251 (Div. 2) A - Devu, the Singer and Churu, the Jokerdev
- Codeforces Round #448 (Div. 2)B
- Codeforces Round #450 (Div. 2) B
- Codeforces Round #452 (Div. 2) D
- Codeforces Round 941 (Div. 2) D
- Codeforces Round 960 (Div. 2)(A - D)
- Codeforces Round #251 (Div. 2) C. Devu and Partitioning of the Arraydev
- Codeforces Round #325 (Div. 2) D bfs
- Codeforces Round #250 (Div. 2) A-D
- Codeforces Round #283 (Div. 2) D,E
- Codeforces Round #256 (Div. 2)A-D
- codeforces Educational Codeforces Round 33 (Rated for Div. 2)B
- Codeforces Round #362 (Div. 2) B 模擬
- Codeforces Round #336 (Div. 2) B 暴力
- Codeforces Round #325 (Div. 2) B 遞推
- Codeforces Round #245 (Div. 2) B - Balls GameGAM
- Codeforces Round #358 (Div. 2) D dp
- Codeforces Round #359 (Div. 2) D DFS
- Educational Codeforces Round 34 (Rated for Div. 2) D
- Codeforces Round #263 (Div. 2) A-D
- Codeforces Round 720 (Div. 2) A-D
- Codeforces Round 977 (Div. 2)(B-C2)
- Codeforces Round 965 (Div. 2) 補題記錄(A,B,D,E1)
- Codeforces Round #491 (Div. 2) B. Getting an A
- Codeforces Round #361 (Div. 2) B BFS最短路
- Codeforces Round #323 (Div. 2) B 模擬
- Codeforces Round #321 (Div. 2) B 二分
- Codeforces Round #242 (Div. 2) B. Megacity
- Codeforces Round #249 (Div. 2) B. Pasha Maximizes
- Codeforces Round #247 (Div. 2) B - Shower Line
- Codeforces Round #253 (Div. 2) B - Kolya and Tandem Repeat
- Codeforces Round #252 (Div. 2) B. Valera and FruitsUI
- Codeforces Round #246 (Div. 2) B. Football Kit