Codeforces Round #349 (Div. 2)

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

A lot of people in Berland hates rain, but you do not. Rain pacifies, puts your thoughts in order. By these years you have developed a good tradition — when it rains, you go on the street and stay silent for a moment, contemplate all around you, enjoy freshness, think about big deeds you have to do.

Today everything had changed quietly. You went on the street with a cup contained water, your favorite drink. In a moment when you were drinking a water you noticed that the process became quite long: the cup still contained water because of rain. You decided to make a formal model of what was happening and to find if it was possible to drink all water in that situation.

Thus, your cup is a cylinder with diameter equals d centimeters. Initial level of water in cup equals h centimeters from the bottom.

You drink a water with a speed equals v milliliters per second. But rain goes with such speed that if you do not drink a water from the cup, the level of water increases on e centimeters per second. The process of drinking water from the cup and the addition of rain to the cup goes evenly and continuously.

Find the time needed to make the cup empty or find that it will never happen. It is guaranteed that if it is possible to drink all water, it will happen not later than after 104 seconds.

Note one milliliter equals to one cubic centimeter.

Input

The only line of the input contains four integer numbers d, h, v, e (1 ≤ d, h, v, e ≤ 104), where:

  • d — the diameter of your cylindrical cup,
  • h — the initial level of water in the cup,
  • v — the speed of drinking process from the cup in milliliters per second,
  • e — the growth of water because of rain if you do not drink from the cup.
Output

If it is impossible to make the cup empty, print "NO" (without quotes).

Otherwise print "YES" (without quotes) in the first line. In the second line print a real number — time in seconds needed the cup will be empty. The answer will be considered correct if its relative or absolute error doesn't exceed 10 - 4. It is guaranteed that if the answer exists, it doesn't exceed 104.

Examples
input
1 2 3 100
output
NO
input
1 1 1 1
output
YES
3.659792366325
Note

In the first example the water fills the cup faster than you can drink from it.

In the second example area of the cup's bottom equals to , thus we can conclude that you decrease the level of water by  centimeters per second. At the same time water level increases by 1 centimeter per second due to rain. Thus, cup will be empty in  seconds.

题意:有一个圆柱形容器。底圆直径为d, 容器中一开始含有h厘米高度的水,  你喝水的速度为v毫升/秒,   雨水滴进容器的速度为e厘米/秒。问能否喝完, 能的话输出喝完的时间。

思路:先判断能否喝完,当增加量大于减少量时候喝不完,否则二分时间。

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<string>
#include<cstring>
#include<map>
#include<vector>
#include<set>
#include<queue>
using namespace std;
const int MAXN=500000+5;
typedef long long int LL;
#define PI 3.1415926
double d,h,v,e,up,has;
bool check(double x){
	return x*v-(x*up+has)>=0;
}
int main()
{
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	while(scanf("%lf%lf%lf%lf",&d,&h,&v,&e)!=EOF){
		up=PI*(d/2.0)*(d/2.0)*e; //每秒增加的量 
		has=PI*(d/2.0)*(d/2.0)*h; //容器一开始拥有的量 
		if(up>v){   
			printf("NO\n");
		}
		else{ //二分 
			double L=0.0,R=1000000.0,mid;
			for(int i=0;i<=1000;i++){
				mid=(L+R)/2.0;
				if(check(mid)){
					R=mid;
				}
				else{
					L=mid;
				}
			}
			printf("YES\n");
			printf("%lf\n",L);
		}
	}
	return 0;
}



B. Coat of Anticubism
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

As some of you know, cubism is a trend in art, where the problem of constructing volumetrical shape on a plane with a combination of three-dimensional geometric shapes comes to the fore.

A famous sculptor Cicasso, whose self-portrait you can contemplate, hates cubism. He is more impressed by the idea to transmit two-dimensional objects through three-dimensional objects by using his magnificent sculptures. And his new project is connected with this. Cicasso wants to make a coat for the haters of anticubism. To do this, he wants to create a sculpture depicting a well-known geometric primitive — convex polygon.

Cicasso prepared for this a few blanks, which are rods with integer lengths, and now he wants to bring them together. The i-th rod is a segment of length li.

The sculptor plans to make a convex polygon with a nonzero area, using all rods he has as its sides. Each rod should be used as a side to its full length. It is forbidden to cut, break or bend rods. However, two sides may form a straight angle .

Cicasso knows that it is impossible to make a convex polygon with a nonzero area out of the rods with the lengths which he had chosen. Cicasso does not want to leave the unused rods, so the sculptor decides to make another rod-blank with an integer length so that his problem is solvable. Of course, he wants to make it as short as possible, because the materials are expensive, and it is improper deed to spend money for nothing.

Help sculptor!

Input

The first line contains an integer n (3 ≤ n ≤ 105) — a number of rod-blanks.

The second line contains n integers li (1 ≤ li ≤ 109) — lengths of rods, which Cicasso already has. It is guaranteed that it is impossible to make a polygon with n vertices and nonzero area using the rods Cicasso already has.

Output

Print the only integer z — the minimum length of the rod, so that after adding it it can be possible to construct convex polygon with (n + 1) vertices and nonzero area from all of the rods.

Examples
input
3
1 2 1
output
1
input
5
20 4 3 2 1
output
11
Note

In the first example triangle with sides {1 + 1 = 2, 2, 1} can be formed from a set of lengths {1, 1, 1, 2}.

In the second example you can make a triangle with lengths {20, 11, 4 + 3 + 2 + 1 = 10}.

题意:给定n个边长为l[i]的杆子,这n条杆子起初是不能组成凸多边形的。然后然你组合这些杆子,给另外找一条杆子是的新的杆子能够组成凸多边形。并且另外找的那条杆子长度要尽可能的小。

思路:可以发现组成三角形的情况最优,然后然这n条杆子组成2条长度尽量相等的新杆子,然后再根据3条变组成三角形的条件就可以求出另找的那条杆子的长度。 注意可能爆int.

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<string>
#include<cstring>
#include<map>
#include<vector>
#include<set>
#include<queue>
using namespace std;
const int MAXN=100000+5;
typedef long long int LL;
int Len[MAXN];
int main()
{
//	freopen("input.txt","r",stdin);
//	freopen("output.txt","w",stdout);
	int n;
	while(scanf("%d",&n)!=EOF){
		for(int i=1;i<=n;i++) scanf("%d",&Len[i]);
		sort(Len+1,Len+1+n);
		LL maxL=Len[n], tmpL=Len[n-1]; //组合成2条长度尽可能相等的新杆子。 
		int L=1,R=n-2;
		while(R>=L){
			if(tmpL<maxL){
				tmpL+=Len[R--];
			}
			else{
				maxL+=Len[L++];
			}
		}
		LL ans=max(tmpL,maxL)-min(tmpL,maxL)+1; //找第三条杆子。 
		cout<<ans<<endl;
	}
	return 0;
}




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值