(补题)CF 467 div2

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/gtuif/article/details/79458845

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

The recent All-Berland Olympiad in Informatics featured n participants with each scoring a certain amount of points.

As the head of the programming committee, you are to determine the set of participants to be awarded with diplomas with respect to the following criteria:

  • At least one participant should get a diploma.
  • None of those with score equal to zero should get awarded.
  • When someone is awarded, all participants with score not less than his score should also be awarded.

Determine the number of ways to choose a subset of participants that will receive the diplomas.

Input

The first line contains a single integer n (1 ≤ n ≤ 100) — the number of participants.

The next line contains a sequence of n integers a1, a2, ..., an (0 ≤ ai ≤ 600) — participants' scores.

It's guaranteed that at least one participant has non-zero score.

Output

Print a single integer — the desired number of ways.

Examples
input
Copy
4
1 3 3 2
output
3
input
Copy
3
1 1 1
output
1
input
Copy
4
42 0 0 42
output
1
Note

There are three ways to choose a subset in sample case one.

  1. Only participants with 3 points will get diplomas.
  2. Participants with 2 or 3 points will get diplomas.
  3. Everyone will get a diploma!

The only option in sample case two is to award everyone.

Note that in sample case three participants with zero scores cannot get anything.


题意:有n个人,每个人都有一个分数,在给他们发文凭的时候要遵守下面的规则,1

1:至少有一个人得到文凭;

2:得零分的不得到文凭;

3:如果一个人得到了文凭,那么比他分高的人都要得到文凭;

问有多少种发放文凭的方法;

思路:用set去重就好了;

下面附上我的代码:

#include<bits/stdc++.h>
#include<set>
using namespace std;
set<int> sk;
int main()
{
	int n,a;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		scanf("%d",&a);
		if(a)
			sk.insert(a); 
	}
	printf("%d\n",sk.size());
	return 0;
 } 

B. Vile Grasshoppers
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

The weather is fine today and hence it's high time to climb the nearby pine and enjoy the landscape.

The pine's trunk includes several branches, located one above another and numbered from 2 to y. Some of them (more precise, from 2 to p) are occupied by tiny vile grasshoppers which you're at war with. These grasshoppers are known for their awesome jumping skills: the grasshopper at branch x can jump to branches .

Keeping this in mind, you wisely decided to choose such a branch that none of the grasshoppers could interrupt you. At the same time you wanna settle as high as possible since the view from up there is simply breathtaking.

In other words, your goal is to find the highest branch that cannot be reached by any of the grasshoppers or report that it's impossible.

Input

The only line contains two integers p and y (2 ≤ p ≤ y ≤ 109).

Output

Output the number of the highest suitable branch. If there are none, print -1 instead.

Examples
input
Copy
3 6
output
5
input
Copy
3 4
output
-1
Note

In the first sample case grasshopper from branch 2 reaches branches 2, 4 and 6 while branch 3 is initially settled by another grasshopper. Therefore the answer is 5.

It immediately follows that there are no valid branches in second sample case.


题意:找出一个尽量大的数,不能大于y,使其不被2-p中的数整除;(大概这个意思。。。)

思路:从y开始找,判定一下是不是素数即可;

下面附上我的代码:

#include<bits/stdc++.h>
using namespace std;
int p,y;
bool f(int k)
{
	for(int i=2;i*i<=k&&i<=p;i++)
	{
		if(k%i==0)
			return false;
	}
	return true;
}
int main()
{	
	cin>>p>>y;
	for(int i=y;i>p;i--)
		if(f(i))
		{
			printf("%d\n",i);
			return 0;
		}		
	printf("-1\n");
	return 0;
}

C. Save Energy!
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Julia is going to cook a chicken in the kitchen of her dormitory. To save energy, the stove in the kitchen automatically turns off after kminutes after turning on.

During cooking, Julia goes to the kitchen every d minutes and turns on the stove if it is turned off. While the cooker is turned off, it stays warm. The stove switches on and off instantly.

It is known that the chicken needs t minutes to be cooked on the stove, if it is turned on, and 2t minutes, if it is turned off. You need to find out, how much time will Julia have to cook the chicken, if it is considered that the chicken is cooked evenly, with constant speed when the stove is turned on and at a constant speed when it is turned off.

Input

The single line contains three integers k, d and t (1 ≤ k, d, t ≤ 1018).

Output

Print a single number, the total time of cooking in minutes. The relative or absolute error must not exceed 10 - 9.

Namely, let's assume that your answer is x and the answer of the jury is y. The checker program will consider your answer correct if .

Examples
input
Copy
3 2 6
output
6.5
input
Copy
4 2 20
output
20.0
Note

In the first example, the chicken will be cooked for 3 minutes on the turned on stove, after this it will be cooked for . Then the chicken will be cooked for one minute on a turned off stove, it will be cooked for . Thus, after four minutes the chicken will be cooked for . Before the fifth minute Julia will turn on the stove and after 2.5 minutes the chicken will be ready .

In the second example, when the stove is turned off, Julia will immediately turn it on, so the stove will always be turned on and the chicken will be cooked in 20 minutes.


题意:一个人要做火鸡,他家厨房的炉子每隔k分钟,温度就变成原来的一半,他每隔d分钟去一趟厨房修复,做好一只火鸡要t分钟,问最少要多长时间才能做好;

思路:找出周期,和周期内的实际烧的时间,模拟一下就好了

#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cmath>
using namespace std;
typedef long long LL;
LL k,d;
double t;
int main()
{
	cin>>k>>d>>t;
	LL l=k/d*d;
	if(l<k)
		l+=d;//判断周期 
	double x=(double)(l-k)/2+k;//实际烧的时间 
	LL i=0;
	double h=0.0;
	i=(LL)t/x;
	h=i*x;
	double p=t-h;	
	//printf("%lf %d %lf\n",h,i,p);
	if(p<=k)
		printf("%.1lf\n",l*i+p);//判断最后周期内剩余时间是在正常时间内还是在关闭的时间内 
	else
		printf("%.1f\n",l*i+k+(p-k)*2);//在k分钟外的话要用两倍的时间 
	return 0;
} 






没有更多推荐了,返回首页