codeforces Round#350 Div.2

来源:互联网 发布:js老虎机抽奖 编辑:程序博客网 时间:2024/06/06 22:14

  打了一场实时cf。。事实证明本来就不聪明,打到3点真tmd够呛

 

A. Holidays
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

On the planet Mars a year lasts exactly n days (there are no leap years on Mars). But Martians have the same weeks as earthlings — 5 work days and then 2 days off. Your task is to determine the minimum possible and the maximum possible number of days off per year on Mars.

Input

The first line of the input contains a positive integer n (1 ≤ n ≤ 1 000 000) — the number of days in a year on Mars.

Output

Print two integers — the minimum possible and the maximum possible number of days off per year on Mars.

Examples
Input
14
Output
4 4
Input
2
Output
0 2
Note

In the first sample there are 14 days in a year on Mars, and therefore independently of the day a year starts with there will be exactly4 days off .

In the second sample there are only 2 days in a year on Mars, and they can both be either work days or days off.

题意: 意思是火星上一周7天(5个工作日,2天周末),给你一个n表示有n天,输出这n天里最少和最多的休息天数。

大水题不过我还wa了一发。。后来就交不了题了(可能是网不好也可能是刷网页的人太多了。。)n天对week取整除和取余,据此判断最少和最多的天数(注意余数是6或者1的情况)。

直接贴代码吧,没啥好说的。。

/* * A.cpp * *  Created on: 2016年5月5日 *      Author: Triose */#include<stdio.h>#include<iostream>#include<string>#include<string.h>#include<algorithm>#include<vector>#include<queue>#include<stack>#include<iterator>#include<math.h>#include<stdlib.h>#include<map>#include<set>using namespace std;//#define ONLINE_JUDGE#define eps 1e-8#define INF 0x7fffffff#define inf 0x3f3f3f3f#define rep(i,a) for((i)=0; i<(a);(i)++)#define mem(a,b) (memset((a),b,sizeof(a)))#define sf(a) scanf("%d",&a)#define sfI(a) scanf("%I64d",&a)#define sfd(a,b) scanf("%d%d",&a,&b)#define sft(a,b,c) scanf("%d%d%d",&a,&b,&c)#define sfs(a) scanf("%s",a)#define pf(a) printf("%d\n",a)#define pfd(a,b) printf("%d %d\n",a,b)#define pfs(a) printf("%s\n",a)#define pfI(a) printf("%I64d\n",a)#define enter putchar(10)#define LL __int64const double PI = acos(-1.0);const double E = exp(1.0);template<class T> T gcd(T a, T b) { return b ? gcd(b, a%b) : a; }template<class T> T lcm(T a, T b) { return a / gcd(a, b)*b; }template<class T> inline T Min(T a, T b) { return a<b ? a : b; }template<class T> inline T Max(T a, T b) { return a>b ? a : b; }int n, m;int main() {#ifndef ONLINE_JUDGEfreopen("in.txt","r",stdin);//freopen("Out.txt", "w", stdout);#endifwhile(~sf(n)) {int a = n / 7;int b = n % 7;pfd((a * 2 + (b > 5 ? b - 5 : 0)), (a * 2 + (b >= 2 ? 2 : b)));}return 0;}


B. Game of Robots
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

In late autumn evening n robots gathered in the cheerful company of friends. Each robot has a unique identifier — an integer from1 to109.

At some moment, robots decided to play the game "Snowball". Below there are the rules of this game. First, all robots stand in a row. Then the first robot says his identifier. After that the second robot says the identifier of the first robot and then says his own identifier. Then the third robot says the identifier of the first robot, then says the identifier of the second robot and after that says his own. This process continues from left to right until then-th robot says his identifier.

Your task is to determine the k-th identifier to be pronounced.

Input

The first line contains two positive integers n andk (1 ≤ n ≤ 100 000,1 ≤ k ≤ min(2·109, n·(n + 1) / 2).

The second line contains the sequence id1, id2, ..., idn (1 ≤ idi ≤ 109) — identifiers of roborts. It is guaranteed that all identifiers are different.

Output

Print the k-th pronounced identifier (assume that the numeration starts from1).

Examples
Input
2 21 2
Output
1
Input
4 510 4 18 3
Output
4
Note

In the first sample identifiers of robots will be pronounced in the following order:1,1, 2. As k = 2, the answer equals to 1.

In the second test case identifiers of robots will be pronounced in the following order:10,10, 4, 10, 4, 18, 10, 4, 18, 3. As k = 5, the answer equals to4.

这道题简直就是脑子不清醒就不要推公式的典范!

意思是给你n个数,按照一定的顺序(第i次报前i个)排列,输出第m个数。。。

   1

  1 2

 1 2 3                              =>  1 12 123 1234(数字代表a[i])

1 2 3 4

.....

别想着推公式了,即使是O(n)也能过!不要追求O(1)

/* * B.cpp * *  Created on: 2016年5月5日 *      Author: Triose */#include<stdio.h>#include<iostream>#include<string>#include<string.h>#include<algorithm>#include<vector>#include<queue>#include<stack>#include<iterator>#include<math.h>#include<stdlib.h>#include<map>#include<set>using namespace std;//#define ONLINE_JUDGE#define eps 1e-8#define INF 0x7fffffff#define inf 0x3f3f3f3f#define rep(i,a) for((i)=0; i<(a);(i)++)#define mem(a,b) (memset((a),b,sizeof(a)))#define sf(a) scanf("%d",&a)#define sfI(a) scanf("%I64d",&a)#define sfd(a,b) scanf("%d%d",&a,&b)#define sft(a,b,c) scanf("%d%d%d",&a,&b,&c)#define sfs(a) scanf("%s",a)#define pf(a) printf("%d\n",a)#define pfd(a,b) printf("%d %d\n",a,b)#define pfs(a) printf("%s\n",a)#define pfI(a) printf("%I64d\n",a)#define enter putchar(10)#define LL __int64const double PI = acos(-1.0);const double E = exp(1.0);template<class T> T gcd(T a, T b) { return b ? gcd(b, a%b) : a; }template<class T> T lcm(T a, T b) { return a / gcd(a, b)*b; }template<class T> inline T Min(T a, T b) { return a<b ? a : b; }template<class T> inline T Max(T a, T b) { return a>b ? a : b; }int n, m;int main() {#ifndef ONLINE_JUDGEfreopen("in.txt","r",stdin);//freopen("Out.txt", "w", stdout);#endifwhile(~sfd(n,m)) {int i = 1;while(m > i) {m -= i;i++;}int tmp, ans;for(i = 1; i <= n; i++) {sf(tmp);if(i == m) {ans = tmp;}}pf(ans);}return 0;}

C. Cinema
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Moscow is hosting a major international conference, which is attended by n scientists from different countries. Each of the scientists knows exactly one language. For convenience, we enumerate all languages of the world with integers from1 to109.

In the evening after the conference, all n scientists decided to go to the cinema. There arem movies in the cinema they came to. Each of the movies is characterized by twodistinct numbers — the index of audio language and the index of subtitles language. The scientist, who came to the movie, will bevery pleased if he knows the audio language of the movie, will bealmost satisfied if he knows the language of subtitles and will benot satisfied if he does not know neither one nor the other (note that the audio language and the subtitles language for each movie are always different).

Scientists decided to go together to the same movie. You have to help them choose the movie, such that the number of very pleased scientists is maximum possible. If there are several such movies, select among them one that will maximize the number of almost satisfied scientists.

Input

The first line of the input contains a positive integer n (1 ≤ n ≤ 200 000) — the number of scientists.

The second line contains n positive integersa1, a2, ..., an (1 ≤ ai ≤ 109), whereai is the index of a language, which thei-th scientist knows.

The third line contains a positive integer m (1 ≤ m ≤ 200 000) — the number of movies in the cinema.

The fourth line contains m positive integersb1, b2, ..., bm (1 ≤ bj ≤ 109), wherebj is the index of the audio language of thej-th movie.

The fifth line contains m positive integersc1, c2, ..., cm (1 ≤ cj ≤ 109), wherecj is the index of subtitles language of thej-th movie.

It is guaranteed that audio languages and subtitles language are different for each movie, that isbj ≠ cj.

Output

Print the single integer — the index of a movie to which scientists should go. After viewing this movie the number of very pleased scientists should be maximum possible. If in the cinema there are several such movies, you need to choose among them one, after viewing which there will be the maximum possible number of almost satisfied scientists.

If there are several possible answers print any of them.

Examples
Input
32 3 223 22 3
Output
2
Input
66 3 1 1 3 751 2 3 4 52 3 4 5 1
Output
1
Note

In the first sample, scientists must go to the movie with the index 2, as in such case the 1-th and the 3-rd scientists will be very pleased and the 2-nd scientist will be almost satisfied.

In the second test case scientists can go either to the movie with the index 1 or the index 3. After viewing any of these movies exactlytwo scientists will be very pleased and all the others will be not satisfied.


题意:有三个数列a,b,c,分别表示科学家们会的语言的编号, 电影声音的语言编号, 电影字幕的语言编号。 输出电影序号使得能听懂语言的数目最大,如果有多个这样的电影,那就输出(其中)使得能看懂字幕的科学家数目最大的电影序号。。(好吧我知道我说的很含糊不过就大概是这个意思了吧。。)

因为n的数据范围是1 ~ 2*10^5, 语言的范围是:1 ~ 10^9。  这时候肯定是离散分布的,不可能每种语言都有! 所以自然而然想到用map统计每种语言的人数。然后设法求出最大值(可以排序,也可以便利)。

傻逼就傻逼在我们两个人都选择了nlogn的排序!却没想到O(n)的便利!!!(两傻逼住一寝室久了就tm犯蠢的方式都一样了!)

看到那日本选手代码的时候我们下巴都快掉下来了!是这么写的啊!为什么人家没超时?后来一看才发现,人家可没排序。。。

贴代码吧。。。

/* * C.cpp * *  Created on: 2016年5月5日 *      Author: Triose */#include<stdio.h>#include<iostream>#include<string>#include<string.h>#include<algorithm>#include<vector>#include<queue>#include<stack>#include<iterator>#include<math.h>#include<stdlib.h>#include<map>#include<set>using namespace std;//#define ONLINE_JUDGE#define eps 1e-8#define INF 0x7fffffff#define inf 0x3f3f3f3f#define rep(i,a) for((i)=0; i<(a);(i)++)#define mem(a,b) (memset((a),b,sizeof(a)))#define sf(a) scanf("%d",&a)#define sfI(a) scanf("%I64d",&a)#define sfd(a,b) scanf("%d%d",&a,&b)#define sft(a,b,c) scanf("%d%d%d",&a,&b,&c)#define sfs(a) scanf("%s",a)#define pf(a) printf("%d\n",a)#define pfd(a,b) printf("%d %d\n",a,b)#define pfs(a) printf("%s\n",a)#define pfI(a) printf("%I64d\n",a)#define enter putchar(10)#define LL __int64const double PI = acos(-1.0);const double E = exp(1.0);template<class T> T gcd(T a, T b) { return b ? gcd(b, a%b) : a; }template<class T> T lcm(T a, T b) { return a / gcd(a, b)*b; }template<class T> inline T Min(T a, T b) { return a<b ? a : b; }template<class T> inline T Max(T a, T b) { return a>b ? a : b; }int n, m;#define N 200010int a[N];int b[N];int c[N];map<int, int>mp;bool cmp(int u, int v) {if(mp[b[u]] != mp[b[v]])return mp[b[u]] > mp[b[v]];return mp[c[u]] > mp[c[v]];}int main() {#ifndef ONLINE_JUDGEfreopen("in.txt","r",stdin);//freopen("Out.txt", "w", stdout);#endifwhile(~sf(n)) {mp.clear();for(int i = 0; i < n; i++) {sf(a[i]);mp[a[i]]++;}sf(m);for(int i = 0; i < m; i++) {sf(b[i]);}for(int i = 0; i < m; i++) {sf(c[i]);}int ans = 0;for(int i = 1; i < m; i++) {if(cmp(i, ans)) {ans = i;}}pf(ans + 1);}return 0;}

输入的时候就统计,便利输出就ok。。

D1. Magic Powder - 1
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

This problem is given in two versions that differ only by constraints. If you can solve this problem in large constraints, then you can just write a single solution to the both versions. If you find the problem too difficult in large constraints, you can write solution to the simplified version only.

Waking up in the morning, Apollinaria decided to bake cookies. To bake one cookie, she needsn ingredients, and for each ingredient she knows the valueai — how many grams of this ingredient one needs to bake a cookie. To prepare one cookie Apollinaria needs to use alln ingredients.

Apollinaria has bi gram of thei-th ingredient. Also she hask grams of a magic powder. Each gram of magic powder can be turned to exactly1 gram of any of then ingredients and can be used for baking cookies.

Your task is to determine the maximum number of cookies, which Apollinaria is able to bake using the ingredients that she has and the magic powder.

Input

The first line of the input contains two positive integers n and k (1 ≤ n, k ≤ 1000) — the number of ingredients and the number of grams of the magic powder.

The second line contains the sequence a1, a2, ..., an (1 ≤ ai ≤ 1000), where the i-th number is equal to the number of grams of thei-th ingredient, needed to bake one cookie.

The third line contains the sequence b1, b2, ..., bn (1 ≤ bi ≤ 1000), where the i-th number is equal to the number of grams of thei-th ingredient, which Apollinaria has.

Output

Print the maximum number of cookies, which Apollinaria will be able to bake using the ingredients that she has and the magic powder.

Examples
Input
3 12 1 411 3 16
Output
4
Input
4 34 3 5 611 12 14 20
Output
3
Note

In the first sample it is profitably for Apollinaria to make the existing 1 gram of her magic powder to ingredient with the index 2, then Apollinaria will be able to bake 4 cookies.

In the second sample Apollinaria should turn 1 gram of magic powder to ingredient with the index1 and1 gram of magic powder to ingredient with the index3. Then Apollinaria will be able to bake3 cookies. The remaining 1 gram of the magic powder can be left, because it can't be used to increase the answer.


题意: 大水题。。 数据范围大概就1000, 意思是:要做饼干需要n种材料,做成一个饼干需要若干个i材料(a[i]), 你现在有这n种材料各若干个( b[i] ),你还有k个万能替代品(可以替代任何一种材料)。现在问你,用上这些替代品你最多能做出多少个饼干?


对于这种小数据,当然是怎么暴力怎么来。。输入的时候求得最少能做多少个饼干(min_ans = Min(min_ans, b[i] / a[i])),然后在这个最小值的基础上每次多加1,直到k小于0就能得出最大值。。(当然这是小数据的做法)O(k * n)

#include<iostream>#include<stdlib.h>#include<stdio.h>using namespace std;#define N 1010template<class T> T Min(T a, T b) {return a > b ? b : a;}int n,k;int a[N];int b[N];int main() {    while(cin >> n >> k) {int ans = 100000;for(int i = 0; i < n; i++)    cin >> a[i];for(int i = 0; i < n; i++) {    cin >> b[i];    ans = Min(ans, b[i] / a[i]);}int tmp = ans + 1;while(k >= 0) {    for(int i = 0; i < n; i++) {if(b[i] >= tmp * a[i])    continue;k -= (a[i] * tmp - b[i]);b[i] = a[i] * tmp;    }    if(k >= 0)ans = tmp;    tmp++;}    cout << ans << endl;    }    return 0;}

D2, 题目意思完全没变,只不过换成了大数据。既然故意换数据,那么肯定卡了你的O(k * n), 你至少得优化到O(n * log k)才行吧?这时一个很自然的想法就是二分。实际上也就是这么做的。。最小值min_ans 如D1所述,那么max_ans 等于多少呢? max_ans = Max(max_ans ,  ((b[i] + k) / a[i]) + 1),反正二分嘛,多加个1也无所谓。然后找一个mid使得现有替代品数量能做mid个饼干,但是不能做mid + 1块饼干。此时mid就是最终答案。贴代码吧, 这题也巨简单。。

#include<iostream>#include<cstdio>#include<cstdlib>using namespace std;#define INF 0x7fffffff#define inf 0x3f3f3f3ftemplate<class T>T Min(T a, T b) {    return a > b ? b : a;}template<class T>T Max(T a, T b) {    return a > b ? a : b;}#define N 100010#define LL long longLL a[N];LL b[N];int n,k;int check(LL mid, int tmpk) {    int tmp = tmpk;    for(int i = 0; i < n; i++) {if(b[i] >= a[i] * mid) continue;tmp -= (a[i] * mid - b[i]);if(tmp < 0)    return -1;    }    tmp = tmpk; mid++;    for(int i = 0; i < n; i++) {if(b[i] >= a[i] * mid) continue;tmp -= (a[i] * mid - b[i]);if(tmp < 0)    return 0;    }    return 1;}int main() {#ifndef ONLINE_JUDGE    freopen("in.txt","r", stdin);#endif    while(cin >> n >> k) {//cout << n << " " << k << endl;LL min_ans = INF;LL max_ans = -1;for(int i = 0; i < n; i++)    cin >> a[i];for(int i = 0; i < n; i++) {    cin >> b[i];    min_ans = Min(min_ans, b[i] / a[i]);    max_ans = Max(max_ans, ((b[i] + k) / a[i]) + 1);}//cout << check(132, k) << endl;//cout << max_ans << endl;if(check(max_ans, k) >= 0) {    cout << max_ans << endl;    continue;}LL mid_ans = (max_ans + min_ans) >> 1;while(min_ans < max_ans) {    mid_ans = (max_ans + min_ans) >> 1;    //cout << mid_ans << endl;    switch (check(mid_ans, k)) {case -1: max_ans = mid_ans; break;case 0: min_ans = max_ans; break;case 1: min_ans = mid_ans; break;    }}cout << mid_ans << endl;    }    return 0;}


因为是用vim写的所以有很多注释,那是调试的时候用的。。




总结:比赛的时候就做出了前两题,无奈。可能也是能力不足。。但是这种难度做出5个也完全没有问题啊!后面两题我还会找时间再做做。。今天就先写到这吧

1.晚上不要打代码

2.能tm便利就不要tmd排序

3.从O(n)到O(log n)最常用的一个办法就是二分!


0 0