Szucoder Round #4 (div.2)

来源:互联网 发布:桂纶镁 戴立忍 知乎 编辑:程序博客网 时间:2024/05/29 06:50

地址:http://codeforces.com/problemset/problem/486/A

A. Calculating Function

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standardoutput

For apositive integer n let's define a function f:

f(n) =  - 1 + 2 - 3 + .. + ( - 1)nn

Your task isto calculate f(n) for a given integer n.

Input

The singleline contains the positive integer n (1 ≤ n ≤ 1015).

Output

Print f(n) in asingle line.

Sample test(s)

input

4

output

2

input

5

output

-3

Note

f(4) =  - 1 + 2 - 3 + 4 = 2

f(5) =  - 1 + 2 - 3 + 4 - 5 =  - 3

 

思路:一开始真的模拟加减法,导致因数据太大而超时。顿时反应过来错误。比赛时程序:#include <iostream>#include <cstdio>#include <cstring>#include <string>#include <map>#include <algorithm>using namespace std;int main(){__int64 n;scanf("%I64d",&n);if (n%2==0)printf("%I64d\n",n/2);else printf("%I64d\n",-1*n/2-1);return 0;}

地址:http://codeforces.com/problemset/problem/475/A

A. Bayan Bus

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standardoutput

The finalround of Bayan Programming Contest will be held in Tehran, and the participantswill be carried around with a yellow bus. The bus has 34 passenger seats: 4seats in the last row and 3 seats in remaining rows.

The eventcoordinator has a list of k participants who should be picked up atthe airport. When a participant gets on the bus, he will sit in the last rowwith an empty seat. If there is more than one empty seat in that row, he willtake the leftmost one.

In order tokeep track of the people who are on the bus, the event coordinator needs afigure showing which seats are going to be taken by k participants.Your task is to draw the figure representing occupied seats.

Input

The only lineof input contains integer k(0 ≤ k ≤ 34), denoting the number ofparticipants.

Output

Print thefigure of a bus with k passengers as described in sample tests.Character '#' denotes anempty seat, while 'O' denotes ataken seat. 'D' is the busdriver and other characters in the output are for the purpose of beautifyingthe figure. Strictly follow the sample test cases output format. Print exactlysix lines. Do not output extra space or other characters.

Sample test(s)

input

9

output

+------------------------+
|O.O.O.#.#.#.#.#.#.#.#.|D|)
|O.O.O.#.#.#.#.#.#.#.#.|.|
|O.......................|
|O.O.#.#.#.#.#.#.#.#.#.|.|)
+------------------------+

input

20

output

+------------------------+
|O.O.O.O.O.O.O.#.#.#.#.|D|)
|O.O.O.O.O.O.#.#.#.#.#.|.|
|O.......................|
|O.O.O.O.O.O.#.#.#.#.#.|.|)
+------------------------+

 

思路:找规律,排除特殊情况。比赛时程序:#include <iostream>#include <cstdio>#include <cstring>#include <string>#include <map>#include <algorithm>using namespace std;void pr(int);int main(){int n;scanf("%d",&n);printf("+------------------------+\n|");if (n>0)pr((n-2)/3+1);else pr(0);printf("|D|)\n|");if (n<3)pr((n+1)/3);else pr(n/3);printf("|.|\n");if (n<3) printf("|#.......................|\n|");else printf("|O.......................|\n|");pr((n-1)/3);printf("|.|)\n");printf("+------------------------+\n");return 0;}void pr(int n){int i;for (i=1;i<=n;i++)printf("O.");for (i=1;i<=11-n;i++)printf("#.");}

地址:http://codeforces.com/problemset/problem/492/B

B. Vanya and Lanterns

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standardoutput

Vanya walkslate at night along a straight street of length l, lit by n lanterns.Consider the coordinate system with the beginning of the street correspondingto the point 0, and its endcorresponding to the point l. Then the i-th lanternis at the point ai. The lantern lights allpoints of the street that are at the distance of at most d fromit, where d is somepositive number, common for all lanterns.

Vanyawonders: what is the minimum light radius d shouldthe lanterns have to light the whole street?

Input

The firstline contains two integers nl (1 ≤ n ≤ 10001 ≤ l ≤ 109) — thenumber of lanterns and the length of the street respectively.

The next linecontains n integers ai (0 ≤ ai ≤ l). Multiplelanterns can be located at the same point. The lanterns may be located at theends of the street.

Output

Print theminimum light radius d, needed to light the whole street. The answer will beconsidered correct if its absolute or relative error doesn't exceed 10 - 9.

Sample test(s)

input

7 15
15 5 3 7 9 14 0

output

2.5000000000

input

2 5
2 5

output

2.0000000000

Note

Consider thesecond sample. At d = 2 the first lantern will light the segment [0, 4] of thestreet, and the second lantern will light segment[3, 5]. Thus, thewhole street will be lit.

 

思路:输入时去重,然后排序,算出任意相邻两盏灯间的半径,路的两端特殊处理,最后找出最大值。比赛时程序:#include <iostream>#include <cstdio>#include <cstring>#include <string>#include <map>#include <algorithm>using namespace std;int main(){int n,l,a[1005],len,i,temp;double min,r;memset(a,0,sizeof(a));scanf("%d%d",&n,&l);map<int,int> point;len=1;a[0]=0;for (i=1;i<=n;i++){scanf("%d",&temp);if (!point[temp]++)a[len++]=temp;}if (!point[l])a[len++]=l;sort(a,a+len);if (!point[0])min=a[1]-a[0];else min=0;for (i=0;i<len-1;i++){r=(a[i+1]-a[i])/2.0;if (r>min) min=r;}if (!point[l] && a[len-1]-a[len-2]>min) min=a[len-1]-a[len-2];printf("%12.10lf\n",min);return 0;}


地址:http://codeforces.com/problemset/problem/489/B

B. BerSU Ball

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standardoutput

The BerlandState University is hosting a ballroom dance in celebration of its 100500-thanniversary! n boys and m girlsare already busy rehearsing waltz, minuet, polonaise and quadrille moves.

We know thatseveral boy&girl pairs are going to be invited to the ball. However, thepartners' dancing skill in each pair must differ by at most one.

For each boy,we know his dancing skills. Similarly, for each girl we know her dancingskills. Write a code that can determine the largest possible number of pairs thatcan be formed from n boys and m girls.

Input

The firstline contains an integer n (1 ≤ n ≤ 100) — the number of boys. Thesecond line contains sequence a1, a2, ..., an (1 ≤ ai ≤ 100), where ai is the i-th boy'sdancing skill.

Similarly,the third line contains an integer m (1 ≤ m ≤ 100) — thenumber of girls. The fourth line contains sequence b1, b2, ..., bm (1 ≤ bj ≤ 100), where bj is the j-th girl'sdancing skill.

Output

Print asingle number — the required maximum possible number of pairs.

Sample test(s)

input

4
1 4 6 2
5
5 1 5 7 9

output

3

input

4
1 2 3 4
4
10 11 12 13

output

0

input

5
1 1 1 1 1
3
1 2 3

output

2

 

思路:贪心,先把男女分别排序,从skill最小的两个开始尝试配对,配对不成功的时候skill小的下标加一。比赛时程序:#include <iostream>#include <cstdio>#include <cstring>#include <string>#include <map>#include <algorithm>using namespace std;int main(){int a[105],b[105];int n,i,j,m,sum;memset(a,0,sizeof(a));memset(b,0,sizeof(b));scanf("%d",&n);for (i=0;i<n;i++)scanf("%d",&a[i]);scanf("%d",&m);for (i=0;i<m;i++)scanf("%d",&b[i]);sort(a,a+n);sort(b,b+m);i=0;j=0;sum=0;while (i<n && j<m){if (abs(a[i]-b[j])<=1){sum++;i++;j++;}else{if (a[i]>b[j]) j++;else i++;}}printf("%d\n",sum);return 0;}



0 0
原创粉丝点击