Codeforces Beta Round #72 (Div. 2 Only)——A,B,C

来源:互联网 发布:iphone6s蜂窝数据快捷 编辑:程序博客网 时间:2024/05/16 07:46
A. Toy Army
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

The hero of our story, Valera, and his best friend Arcady are still in school, and therefore they spend all the free time playing turn-based strategy "GAGA: Go And Go Again". The gameplay is as follows.

There are two armies on the playing field each of which consists of n men (n is always even). The current player specifies for each of her soldiers an enemy's soldier he will shoot (a target) and then all the player's soldiers shot simultaneously. This is a game world, and so each soldier shoots perfectly, that is he absolutely always hits the specified target. If an enemy soldier is hit, he will surely die. It may happen that several soldiers had been indicated the same target. Killed soldiers do not participate in the game anymore.

The game "GAGA" consists of three steps: first Valera makes a move, then Arcady, then Valera again and the game ends.

You are asked to calculate the maximum total number of soldiers that may be killed during the game.

Input

The input data consist of a single integer n (2 ≤ n ≤ 108n is even). Please note that before the game starts there are 2n soldiers on the fields.

Output

Print a single number — a maximum total number of soldiers that could be killed in the course of the game in three turns.

#include <cstdio>#include <iostream>#include <cstring>#include <algorithm>using namespace std;const int maxn=100+5;int main(){    int n;    cin>>n;    cout<<n+n/2<<endl;    return 0;}

B. Magical Array
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Valery is very interested in magic. Magic attracts him so much that he sees it everywhere. He explains any strange and weird phenomenon through intervention of supernatural forces. But who would have thought that even in a regular array of numbers Valera manages to see something beautiful and magical.

Valera absolutely accidentally got a piece of ancient parchment on which an array of numbers was written. He immediately thought that the numbers in this array were not random. As a result of extensive research Valera worked out a wonderful property that a magical array should have: an array is defined as magic if its minimum and maximum coincide.

He decided to share this outstanding discovery with you, but he asks you for help in return. Despite the tremendous intelligence and wit, Valera counts very badly and so you will have to complete his work. All you have to do is count the number of magical subarrays of the original array of numbers, written on the parchment. Subarray is defined as non-empty sequence of consecutive elements.

Input

The first line of the input data contains an integer n (1 ≤ n ≤ 105). The second line contains an array of original integers a1, a2, ..., an( - 109 ≤ ai ≤ 109).

Output

Print on the single line the answer to the problem: the amount of subarrays, which are magical.

Please do not use the %lld specificator to read or write 64-bit numbers in C++. It is recommended to use cincout streams (you can also use the %I64d specificator).

#include <cstdio>#include <iostream>#include <cstring>#include <algorithm>using namespace std;const int maxn=100000+5;int a[maxn];int main(){    int n,c=0;    cin>>n;    scanf("%d",&a[0]);    __int64 sum=1,cnt=1;//当前数与其前相邻的相等数有cnt个    for(int i=1;i<n;i++)    {        scanf("%d",&a[i]);        if(a[i]!=a[i-1]) sum++,cnt=1;        else sum+=1+cnt,cnt++;//每增加1个相同的数,总数目增加个数=前面与其相等的个数+1    }    cout<<sum<<endl;    return 0;}

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

Perhaps many have heard that the World Biathlon Championship has finished. Although our hero Valera was not present at this spectacular event himself and only watched it on TV, it excited him so much that he decided to enroll in a biathlon section.

Of course, biathlon as any sport, proved very difficult in practice. It takes much time and effort. Workouts, workouts, and workouts, — that's what awaited Valera on his way to great achievements in biathlon.

As for the workouts, you all probably know that every professional biathlete should ski fast and shoot precisely at the shooting range. Only in this case you can hope to be successful, because running and shooting are the two main components of biathlon. Valera has been diligent in his ski trainings, which is why he runs really fast, however, his shooting accuracy is nothing to write home about.

On a biathlon base where Valera is preparing for the competition, there is a huge rifle range with n targets. Each target have shape of a circle, and the center of each circle is located on the Ox axis. At the last training session Valera made the total of m shots. To make monitoring of his own results easier for him, one rather well-known programmer (of course it is you) was commissioned to write a program that would reveal how many and which targets Valera hit. More specifically, for each target the program must print the number ofthe first successful shot (in the target), or "-1" if this was not hit. The target is considered hit if the shot is inside the circle or on its boundary. Valera is counting on you and perhaps, thanks to you he will one day win international competitions.

Input

The first line of the input file contains the integer n (1 ≤ n ≤ 104), which is the number of targets. The next n lines contain descriptions of the targets. Each target is a circle whose center is located on the Ox axis. Each circle is given by its coordinate of the center x ( - 2·104 ≤ x ≤ 2·104) and its radius r (1 ≤ r ≤ 1000). It is guaranteed that no two targets coincide, intersect or are nested into each other, but they can touch each other.

The next line contains integer m (1 ≤ m ≤ 2·105), which is the number of shots. Next m lines contain descriptions of the shots, which are points on the plane, given by their coordinates x and y ( - 2·104 ≤ x, y ≤ 2·104).

All the numbers in the input are integers.

Targets and shots are numbered starting from one in the order of the input.

Output

Print on the first line a single number, the number of targets hit by Valera. Print on the second line for each of the targets the number of its first hit or "-1" (without quotes) if this number does not exist. Separate numbers with spaces.

#include <cstdio>#include <algorithm>#include <iostream>using namespace std;const int maxn=10000+5;struct node{    int x,r,res,id;}f[maxn];int n;bool judge(int x,int y,int p){    if(p<0||p>=n) return false;    if(f[p].res!=-1) return false;//已经被射中过    if((f[p].x-x)*(f[p].x-x)+y*y<=f[p].r*f[p].r)//判断是否在圆内        return true;    return false;}bool cmp1(node a,node b){    return a.x<b.x;}bool cmp2(node a,node b){    return a.id<b.id;}int Bin(int x){    int l=0,r=n-1;    while(l<=r)    {        int m=(l+r)>>1;        if(f[m].x>x) r=m-1;        else l=m+1;    }    return l;}int main(){    int m;    scanf("%d",&n);    for(int i=0;i<n;i++)    {        scanf("%d%d",&f[i].x,&f[i].r);        f[i].id=i;        f[i].res=-1;    }    sort(f,f+n,cmp1);    scanf("%d",&m);    int cnt=0;    for(int i=1;i<=m;i++)    {        int x,y;        scanf("%d%d",&x,&y);        int t=Bin(x);//二分查找x        for(int k=-1;k<=1;k++){//判断自身以及相邻的两个            int p=t+k;            if(judge(x,y,p)) f[p].res=i,cnt++;        }    }    sort(f,f+n,cmp2);    cout<<cnt<<endl;    for(int i=0;i<n;i++)        cout<<f[i].res<<" ";    cout<<endl;    return 0;}


原创粉丝点击