[Codeforces] Round #320 (Div.2)

Source: Internet
Author: User
Tags polyline

1. Preface

Although this time I still did not participate in the official competition, but afterwards still looked at the question goal ... Generally do not brush codeforces.

A, raising bacteria

You are a lover of bacteria. You want to raise some bacteria in a box.

Initially, the box is empty. Each morning, you can put any number of bacteria into the box. And each night, every bacterium in the box would split into the bacteria. You hope to see exactly x bacteria in the box at some moment.

What's the minimum number of bacteria you need-put into the box across those days?

>input

The only line containing one integer x (1≤ x ≤109).

>output

The only line containing one integer:the answer.

>sample Test (s) input
5
Output
2
input
8
Output
1
>note

For the first sample, we can add one bacterium in the "The first day Morning" and at the third morning there would be 4 bacteria in the box. Now we put one more resulting 5 in the box. We added 2 bacteria in the process so that the answer is 2.

For the second sample, we can put a one in the first morning and in the 4-th morning there would be a 8 in the box. So the answer is 1.


A puzzle: Find out how many 2^k (k∈[1,30]) are included in the given number.

-------------------------------------------------------------------------------------------

#include <cstdio>

int N,tot;

int main ()
{
scanf ("%d", &n);
for (int i=1<<30;i>=1;i>>=1) if (n>=i) n-=i,tot++;
printf ("%d", tot);
return 0;
}

-------------------------------------------------------------------------------------------

B, Finding Team Member

there is a programing contest named Snakeup,2 N people want to compete for it. In order to attend the contest, people need to form teams of exactly, people. You is given the strength of each possible combination of the people. All the values of the strengths isdistinct.

Every contestant hopes that he can find a teammate so that their team's strength is as high as possible. That is, a contestant would form a team with highest strength possible by choosing a teammate from ones who was willing to Be a teammate with him/her. More formally, both people a and B may form a team if each of the them are the best possible teammate (among the contestants that remain unpaired) for the other one.

Can you determine who would be are each person ' s teammate?

>input

There is 2n lines in the input.

The first line contains a integer n (1≤ n ≤400)-the number of teams to be formed.

TheI-th Line ( I > 1) contains  i -1 numbers < Span class= "Tex-span" > a i 1,  a Span class= "Lower-index" > i 2, ...,   a I ( i -1). Here  a ij   ( 1 ≤ a ij ≤106, all  a ij  are distinct) denotes the strength of a Team consisting of Person  i  and person  J   (People is numbered starting From 1.)

>output

Output a line containing 2n numbers. The i-th number should represent the number of teammate of I-th person.

>sample Test (s)input
2
6
1 2
3 4 5
Output
2 1 4 3
input
3
487060
3831 161856
845957 794650 976977
83847 50566 691206 498447
698377 156232 59015) 382455 626960
Output
6 5 4 3 2 1

>note

In the first sample, contestant 1 and 2 would be teammates and so does contestant 3 and 4, so the teammate of Contestant 1, 2, 3, 4 would be2, 1, 4, 3 respectively.

Solver: Get all pairs of tacit values, ranging from big to small, then pairing each other and skipping if paired.

-------------------------------------------------------------------------------------------

#include <cstdio>
#include <algorithm>
#define MAXN 320005
using namespace Std;

struct Num
{
int val,x,y;
};
Num A[MAXN];

struct CMP
{
BOOL Operator () (Num A,num B)
{
return (A.val>b.val);
}
};
CMP x;

int n,tot,ans[810];

int main ()
{
scanf ("%d", &n);
for (int i=2;i<=2*n;i++)
for (int j=1;j<=i-1;j++) scanf ("%d", &a[++tot].val), a[tot].x=i,a[tot].y=j;
sort (a+1,a+tot+1,x);
for (int i=1;i<=tot;i++)
{
if (ans[a[i].x] | | ans[a[i].y]) continue;
ans[a[i].x]=a[i].y,ans[a[i].y]=a[i].x;
}
for (int i=1;i<=2*n;i++) printf ("%d", ans[i]);
return 0;
}

-------------------------------------------------------------------------------------------



C. A problem about Polyline there is a polyline going through points(0, 0) – ( x, x) – (2 x, 0) – (3 x, x) – (4 x, 0) – ...-(2 kx , 0) – (2kx + x, x) – ....

We know the polyline passes through the point (a, b). Find minimum positive value x such that it's true or determine that there is no such x.

>input

Only one line containing positive integers a and b (1≤ a, b ≤109 ).

>output

Output the only line containing the answer. Your answer would be a considered correct if its relative or absolute error doesn ' t exceed -9. If There is no such x then output -1 as the answer.

>sample Test (s)input
3 1
Output
1.000000000000
input
1 3
Output
-1
input
4 1
Output
1.250000000000

>note

You can see following graphs for Sample 1 and sample 3.

The first thing to be sure is that the function is extended by y=x. Because the point in the straight line, obviously b<a no solution, otherwise there are two cases, one is the point (A, B) on the line with a slope of 1, then this segment over (a-b,0) this point, similarly if the slope is 1 of the line, then this segment over (a+b,0) this point.

-------------------------------------------------------------------------------------------

#include <cstdio>

int A, B;

int main ()
{
scanf ("%d%d", &a,&b);
if (a<b) printf ("-1");
else printf ("%.12f\n", (a+b)/(2.0* ((a+b)/(2*B)));
return 0;
}

-------------------------------------------------------------------------------------------

[Codeforces] Round #320 (Div.2)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.