【2020.01.09】凉心的比赛

G - Fifa and Fafa are friends

Fifa and Fafa are sharing a flat. Fifa loves video games and wants to download a new soccer game. Unfortunately, Fafa heavily uses the internet which consumes the quota. Fifa can access the internet through his Wi-Fi access point. This access point can be accessed within a range of r meters (this range can be chosen by Fifa) from its position. Fifa must put the access point inside the flat which has a circular shape of radius R. Fifa wants to minimize the area that is not covered by the access point inside the flat without letting Fafa or anyone outside the flat to get access to the internet.

The world is represented as an infinite 2D plane. The flat is centered at (x1, y1) and has radius R and Fafa’s laptop is located at (x2, y2), not necessarily inside the flat. Find the position and the radius chosen by Fifa for his access point which minimizes the uncovered area.
Input

The single line of the input contains 5 space-separated integers
R, x1, y1, x2, y2 (1 ≤ R ≤ 105, |x1|, |y1|, |x2|, |y2| ≤ 105).
Input
The single line of the input contains 5 space-separated integers R, x1, y1, x2, y2 (1 ≤ R ≤ 105, |x1|, |y1|, |x2|, |y2| ≤ 105).

Output

Print three space-separated numbers xap, yap, r where (xap, yap) is
the position which Fifa chose for the access point and r is the radius
of its range.

Your answer will be considered correct if the radius does not differ
from optimal more than 10 - 6 absolutely or relatively, and also the
radius you printed can be changed by no more than 10 - 6 (absolutely
or relatively) in such a way that all points outside the flat and
Fafa’s laptop position are outside circle of the access point range.

Examples
Input

5 3 3 1 1

Output

3.7677669529663684 3.7677669529663684 3.914213562373095

Input

10 5 5 5 15

Output

5.0 5.0 10.0

#include <stdio.h>
#include <math.h>
int main()
{
	double R,x1,y1,x2,y2;
	double T;
	double result,temp;
	double r,X,Y;
	scanf("%lf%lf%lf%lf%lf",&R,&x1,&y1,&x2,&y2);
	if(((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2))>=R*R)
	printf("%lf %lf %lf\n",x1,y1,R);
	else if(x1==x2&&y1==y2)
	printf("%lf %lf %lf\n",x1,y1+R/2,R/2);
	else
	{
		result=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
	    temp=sqrt(result);
	    T=(R+temp)/2;
	    X=((x1-x2)*T)/temp+x2;
	    Y=((y1-y2)*T)/temp+y2;
     	printf("%lf %lf %lf\n",X,Y,T);
	}
	return 0;
}

**

F - Fafa want to through the gate

**Two neighboring kingdoms decided to build a wall between them with some gates to enable the citizens to go from one kingdom to another. Each time a citizen passes through a gate, he has to pay one silver coin.

The world can be represented by the first quadrant of a plane and the wall is built along the identity line (i.e. the line with the equation x = y). Any point below the wall belongs to the first kingdom while any point above the wall belongs to the second kingdom. There is a gate at any integer point on the line (i.e. at points (0, 0), (1, 1), (2, 2), …). The wall and the gates do not belong to any of the kingdoms.

Fafa is at the gate at position (0, 0) and he wants to walk around in the two kingdoms. He knows the sequence S of moves he will do. This sequence is a string where each character represents a move. The two possible moves Fafa will do are ‘U’ (move one step up, from (x, y) to (x, y + 1)) and ‘R’ (move one step right, from (x, y) to (x + 1, y)).

Fafa wants to know the number of silver coins he needs to pay to walk around the two kingdoms following the sequence S. Note that if Fafa visits a gate without moving from one kingdom to another, he pays no silver coins. Also assume that he doesn’t pay at the gate at point (0, 0), i. e. he is initially on the side he needs.

Input

The first line of the input contains single integer n (1 ≤ n ≤ 105) —
the number of moves in the walking sequence.

The second line contains a string S of length n consisting of the
characters ‘U’ and ‘R’ describing the required moves. Fafa will follow
the sequence S in order from left to right.

Output

On a single line, print one integer representing the number of silver
coins Fafa needs to pay at the gates to follow the sequence S.

Examples
Input

1
U

Output

0

Input

6

RURUUR

Output

1

Input

7

URRRUUU

Output

2

#include <stdio.h>
int main()
{
	long long int n,x=0,y=0,money=0,i;
	char a[100001];
	scanf("%lld",&n);
    scanf("%s",a);
	for(i=0;i<n;i++)
	{
		if(a[i]=='U')
	    y++;
	    if(a[i]=='R')
	    x++;
	    if((x==y)&&(a[i]==a[i+1]))
	    money++;
	} 
	printf("%lld\n",money);
	return 0;
}

**

E - Fafa in Distributing Work(签到题)

Fafa owns a company that works on huge projects. There are n employees in Fafa’s company. Whenever the company has a new project to start working on, Fafa has to divide the tasks of this project among all the employees.

Fafa finds doing this every time is very tiring for him. So, he decided to choose the best l employees in his company as team leaders. Whenever there is a new project, Fafa will divide the tasks among only the team leaders and each team leader will be responsible of some positive number of employees to give them the tasks. To make this process fair for the team leaders, each one of them should be responsible for the same number of employees. Moreover, every employee, who is not a team leader, has to be under the responsibility of exactly one team leader, and no team leader is responsible for another team leader.

Given the number of employees n, find in how many ways Fafa could choose the number of team leaders l in such a way that it is possible to divide employees between them evenly.

Input

The input consists of a single line containing a positive integer n
(2 ≤ n ≤ 105) — the number of employees in Fafa’s company.

Output

Print a single integer representing the answer to the problem.

Examples
Input

2

Output

1

Input

10

Output

3

Note

In the second sample Fafa has 3 ways:

choose only 1 employee as a team leader with 9 employees under his responsibility.
choose 2 employees as team leaders with 4 employees under the responsibility of each of them.
choose 5 employees as team leaders with 1 employee under the responsibility of each of them.

#include <stdio.h>
#include <stdlib.h>
int main()
{
	long long int n,i,count=0;
	scanf("%lld",&n);
	for(i=1;i<=n/2;i++)
	{
		if((n-i)%i==0)
		count++;
	}
	printf("%lld\n",count);
	return 0;
}

**

A - Minimum binary number(签到题)

String can be called correct if it consists of characters “0” and “1” and there are no redundant leading zeroes. Here are some examples: “0”, “10”, “1001”.

You are given a correct string s.

You can perform two different operations on this string:

①swap any pair of adjacent characters (for example, “101” “110”);
②replace “11” with “1” (for example, “110” “10”).
Let val(s) be such a number that s is its binary representation.

Correct string a is less than some other correct string b iff val(a) < val(b).

Your task is to find the minimum correct string that you can obtain from the given one using the operations described above. You can use these operations any number of times in any order (or even use no operations at all).

Input

The first line contains integer number n (1 ≤ n ≤ 100) — the length of
string s.

The second line contains the string s consisting of characters “0” and
“1”. It is guaranteed that the string s is correct.

Output

Print one string — the minimum correct string that you can obtain from
the given one.

Examples
Input

4
1001

Output

100

Input

1
1

Output

1

Note

In the first example you can obtain the answer by the following
sequence of operations: “1001” →"1010" → “1100” → “100”.

In the second example you can’t obtain smaller answer no matter what
operations you use.

#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int temp=0,i;
	for(i=1;i<=n;i++)
	{
		char a;
		cin>>a;
		if(a=='0') 
		temp++;
	}
	if(temp==1&&n==1)
	{
		cout<<"0"<<endl;
		return 0;
	}
	cout<<"1";
	while(temp--)
	cout<<"0";
	cout<<endl;
	return 0;	
}
发布了4 篇原创文章 · 获赞 0 · 访问量 125

猜你喜欢

转载自blog.csdn.net/Legend_666/article/details/103916720