计算几何基础

练习题

C - Wasted Time

Mr. Scrooge, a very busy man, decided to count the time he wastes on all sorts of useless stuff to evaluate the lost profit. He has already counted the time he wastes sleeping and eating. And now Mr. Scrooge wants to count the time he has wasted signing papers.

Mr. Scrooge's signature can be represented as a polyline A1A2... An. Scrooge signs like that: first it places a pen at the point A1, then draws a segment from point A1 to point A2, then he draws a segment from point A2 to point A3 and so on to point An, where he stops signing and takes the pen off the paper. At that the resulting line can intersect with itself and partially repeat itself but Scrooge pays no attention to it and never changes his signing style. As Scrooge makes the signature, he never takes the pen off the paper and his writing speed is constant — 50 millimeters per second.

Scrooge signed exactly k papers throughout his life and all those signatures look the same.

Find the total time Scrooge wasted signing the papers.

Input

The first line contains two integers n and k (2 ≤ n ≤ 100, 1 ≤ k ≤ 1000). Each of the following n lines contains the coordinates of the polyline's endpoints. The i-th one contains coordinates of the point Ai — integers xi and yi, separated by a space.

All points Ai are different. The absolute value of all coordinates does not exceed 20. The coordinates are measured in millimeters.

Output

Print one real number — the total time Scrooges wastes on
signing the papers in seconds. The absolute or relative error should
not exceed 10 - 6.

Examples

Input
2 1
0 0
10 0
Output
0.200000000
Input
5 10
3 1
-5 6
-2 -1
3 2
10 0
Output
6.032163204
Input
6 10
5 0
4 0
6 0
3 0
7 0
2 0
Output
3.000000000
 #include <cstdio>
#include <cstring>
#include <iostream>
#include<algorithm>
#include<math.h>
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll; ld ans=;
int main()
{
int n,k;
ld x[],y[];
scanf("%d%d",&n,&k); for(int i=;i<n;i++)
{
cin>>x[i]>>y[i];
}
for(int i=;i<n-;i++)
{
ans+=sqrt((x[i+]-x[i])*(x[i+]-x[i])+(y[i+]-y[i])*(y[i+]-y[i]));
}
ans=ans*k/;
cout<<fixed<<setprecision()<<ans<<'\n';
return ;
}

D - Trace

One day, as Sherlock Holmes was tracking down one very important criminal, he found a wonderful painting on the wall. This wall could be represented as a plane. The painting had several concentric circles that divided the wall into several parts. Some parts were painted red and all the other were painted blue. Besides, any two neighboring parts were painted different colors, that is, the red and the blue color were alternating, i. e. followed one after the other. The outer area of the wall (the area that lied outside all circles) was painted blue. Help Sherlock Holmes determine the total area of red parts of the wall.

Let us remind you that two circles are called concentric if their centers coincide. Several circles are called concentric if any two of them are concentric.

Input

The first line contains the single integer n (1 ≤ n ≤ 100). The second line contains n space-separated integers ri (1 ≤ ri ≤ 1000) — the circles' radii. It is guaranteed that all circles are different.

Output

Print the single real number — total area of the part of
the wall that is painted red. The answer is accepted if absolute or
relative error doesn't exceed 10 - 4.

Examples

Input
1
1
Output
3.1415926536
Input
3
1 4 2
Output
40.8407044967

Note

In the first sample the picture is just one circle of radius 1. Inner part of the circle is painted red. The area of the red part equals π × 12 = π.

In the second sample there are three circles of radii 1, 4 and 2. Outside part of the second circle is painted blue. Part between the second and the third circles is painted red. Part between the first and the third is painted blue. And, finally, the inner part of the first circle is painted red. Overall there are two red parts: the ring between the second and the third circles and the inner part of the first circle. Total area of the red parts is equal (π × 42 - π × 22) + π × 12 = π × 12 + π = 13π

 #include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include<math.h> using namespace std;
const int maxn = ;
const double pi=acos(-1.0);
int a[maxn];
int main()
{
int n;
double ans=;
scanf("%d",&n);
for(int i=; i<=n; i++)
scanf("%d",&a[i]);
sort(a+,a+n+);
int flag=;
for(int i=n; i>=; i--)
{
ans+=(double)pi*a[i]*a[i]*flag;
flag*=-;
}
printf("%.10f\n",ans);
return ;
}

H - A Problem about Polyline

There is a polyline going through points (0, 0) – (x, x) – (2x, 0) – (3x, x) – (4x, 0) – ... - (2kx, 0) – (2kx + x, x) – ....

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

Input

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

Output

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

Examples

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.

 #include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include<math.h>
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
//const int N=2e5+5;
ld a,b;
int main()
{
cin>>a>>b;
//y=x-2pc
//y=-x+2pc c=(y+x)/2p
if(a<b)
puts("-1");
else
{
ll l=,r=1e9;
ld res=1e15;
while(l<=r)
{
ll mid=l+r>>;
ld c=(a+b)/(2.0*mid);
if(c>=b)
l=mid+,res=c;
else
r=mid-;
}
l=,r=1e9;
while(l<=r)
{
//y=x-2pc
ll mid=l+r>>;
ld c=(a-b)/(2.0*mid);
if(c>=b)
l=mid+,res=min(res,c);
else
r=mid-;
}
cout<<fixed<<setprecision()<<res<<'\n';
}
return ;
}

I - Triangle

Johnny has a younger sister Anne, who is very clever and smart. As she came home from the kindergarten, she told his brother about the task that her kindergartener asked her to solve. The task was just to construct a triangle out of four sticks of different colours. Naturally, one of the sticks is extra. It is not allowed to break the sticks or use their partial length. Anne has perfectly solved this task, now she is asking Johnny to do the same.

The boy answered that he would cope with it without any difficulty. However, after a while he found out that different tricky things can occur. It can happen that it is impossible to construct a triangle of a positive area, but it is possible to construct a degenerate triangle. It can be so, that it is impossible to construct a degenerate triangle even. As Johnny is very lazy, he does not want to consider such a big amount of cases, he asks you to help him.

Input

The first line of the input contains four space-separated positive integer numbers not exceeding 100 — lengthes of the sticks.

Output

Output TRIANGLE if it is possible to construct a non-degenerate triangle. Output SEGMENT if the first case cannot take place and it is possible to construct a degenerate triangle. Output IMPOSSIBLE
if it is impossible to construct any triangle. Remember that you are to
use three sticks. It is not allowed to break the sticks or use their
partial length.

Examples

Input
4 2 1 3
Output
TRIANGLE
Input
7 2 2 4
Output
SEGMENT
Input
3 5 9 1
Output
IMPOSSIBLE
 #include <cstdio>
#include <cstring>
#include <iostream>
#include<algorithm>
#include<math.h>
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll; bool tri(int a,int b,int c)
{
if(a+b>c && a+c>b && b+c>a)
return true;
return false;
} int main()
{
int a,b,c,d;
scanf("%d%d%d%d",&a,&b,&c,&d);
if(tri(a,b,c)||tri(a,b,d) || tri(a,c,d) || tri(b,c,d))
{
printf("TRIANGLE\n");
}
else if(a+b==c || a+b==d || a+c==d || a+c==b ||a+d==b || a+d==c ||b+c==d || b+d==c || b+c==a || b+d==a || c+d==a || c+d==b)
{
printf("SEGMENT\n");
}
else
printf("IMPOSSIBLE\n");
return ;
}

K - Gerald's Hexagon

Gerald got a very curious hexagon for his birthday. The boy found out that all the angles of the hexagon are equal to . Then he measured the length of its sides, and found that each of them is equal to an integer number of centimeters. There the properties of the hexagon ended and Gerald decided to draw on it.

He painted a few lines, parallel to the sides of the hexagon. The lines split the hexagon into regular triangles with sides of 1 centimeter. Now Gerald wonders how many triangles he has got. But there were so many of them that Gerald lost the track of his counting. Help the boy count the triangles.

Input

The first and the single line of the input contains 6 space-separated integers a1, a2, a3, a4, a5 and a6 (1 ≤ ai ≤ 1000)
— the lengths of the sides of the hexagons in centimeters in the
clockwise order. It is guaranteed that the hexagon with the indicated
properties and the exactly such sides exists.

Output

Print a single integer — the number of triangles with the sides of one 1 centimeter, into which the hexagon is split.

Examples

Input
1 1 1 1 1 1
Output
6
Input
1 2 1 2 1 2
Output
13

Note

This is what Gerald's hexagon looks like in the first sample:

And that's what it looks like in the second sample:

 #include<stdio.h>
int s[];
using namespace std;
int main()
{
for(int i=;i<=;i++)
scanf("%d",&s[i]);
int a=(s[]+s[]+s[]);
printf("%d\n",a*a-s[]*s[]-s[]*s[]-s[]*s[]);
return ;
}

M - Gleb And Pizza

Gleb ordered pizza home. When the courier delivered the pizza, he was very upset, because several pieces of sausage lay on the crust, and he does not really like the crust.

The pizza is a circle of radius r and center at the origin. Pizza consists of the main part — circle of radius r - d with center at the origin, and crust around the main part of the width d. Pieces of sausage are also circles. The radius of the i -th piece of the sausage is ri, and the center is given as a pair (xi, yi).

Gleb asks you to help determine the number of pieces of sausage caught on the crust. A piece of sausage got on the crust, if it completely lies on the crust.

Input

First string contains two integer numbers r and d (0 ≤ d < r ≤ 500) — the radius of pizza and the width of crust.

Next line contains one integer number n — the number of pieces of sausage (1 ≤ n ≤ 105).

Each of next n lines contains three integer numbers xi, yi and ri ( - 500 ≤ xi, yi ≤ 500, 0 ≤ ri ≤ 500), where xi and yi are coordinates of the center of i-th peace of sausage, ri — radius of i-th peace of sausage.

Output

Output the number of pieces of sausage that lay on the crust.

Examples

Input
8 4
7
7 8 1
-7 3 2
0 2 1
0 -2 2
-3 -3 1
0 6 2
5 3 1
Output
2
Input
10 8
4
0 0 9
0 0 10
1 0 1
1 0 2
Output
0
 #include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include<math.h> using namespace std;
const int maxn = ;
const double pi=acos(-1.0); int main()
{
int R,d;
scanf("%d%d",&R,&d);
int n;
scanf("%d",&n);
int ans=;
int x,y,r;
while(n--)
{
scanf("%d%d%d",&x,&y,&r);
double distance=sqrt(x*x+y*y);
double xiao=distance-r;
double da=distance+r;
if(xiao>=R-d && da<=R)
{
ans++;
} }
printf("%d\n",ans);
return ;
}
Note

Below is a picture explaining the first example. Circles of green color denote pieces of sausage lying on the crust.

ACM 第十五天的更多相关文章

  1. Minieye杯第十五届华中科技大学程序设计邀请赛现场同步赛 I Matrix Again

    Minieye杯第十五届华中科技大学程序设计邀请赛现场同步赛 I Matrix Again https://ac.nowcoder.com/acm/contest/700/I 时间限制:C/C++ 1 ...

  2. 我的MYSQL学习心得(十五) 日志

    我的MYSQL学习心得(十五) 日志 我的MYSQL学习心得(一) 简单语法 我的MYSQL学习心得(二) 数据类型宽度 我的MYSQL学习心得(三) 查看字段长度 我的MYSQL学习心得(四) 数据 ...

  3. Bootstrap <基础二十五>警告(Alerts)

    警告(Alerts)以及 Bootstrap 所提供的用于警告的 class.警告(Alerts)向用户提供了一种定义消息样式的方式.它们为典型的用户操作提供了上下文信息反馈. 您可以为警告框添加一个 ...

  4. Bootstrap<基础十五> 输入框组

    Bootstrap 支持的另一个特性,输入框组.输入框组扩展自 表单控件.使用输入框组,可以很容易地向基于文本的输入框添加作为前缀和后缀的文本或按钮. 通过向输入域添加前缀和后缀的内容,您可以向用户输 ...

  5. 解剖SQLSERVER 第十五篇 SQLSERVER存储过程的源文本存放在哪里?(译)

    解剖SQLSERVER 第十五篇  SQLSERVER存储过程的源文本存放在哪里?(译) http://improve.dk/where-does-sql-server-store-the-sourc ...

  6. Senparc.Weixin.MP SDK 微信公众平台开发教程(十五):消息加密

    前不久,微信的企业号使用了强制的消息加密方式,随后公众号也加入了可选的消息加密选项.目前企业号和公众号的加密方式是一致的(格式会有少许差别). 加密设置 进入公众号后台的“开发者中心”,我们可以看到U ...

  7. 十五个常用的jquery代码段【转】

    好的文章顶一个 回到顶部按钮 通过使用 jQuery 中的 animate 和 scrollTop 方法,你无需插件便可创建一个简单地回到顶部动画: 1 // Back to top 2 $('a.t ...

  8. 十五个常用的jquery代码段

    十五个常用的jquery代码段 回到顶部按钮 通过使用 jQuery 中的 animate 和 scrollTop 方法,你无需插件便可创建一个简单地回到顶部动画: 1 // Back to top ...

  9. 淘宝(阿里百川)手机客户端开发日记第十五篇 JSON解析(四)

    解析一个从淘宝传递的JSON (大家如有兴趣可以测试下):{ "tae_item_detail_get_response": { "data": { " ...

随机推荐

  1. Android简单的编写一个txt阅读器(没有处理字符编码),适用于新手学习

    本程序只是使用了一些基本的知识点编写了一个比较简单粗陋的txt文本阅读器,效率不高,只适合新手练习.所以大神勿喷. 其实想到编写这种程序源自本人之前喜欢看小说,而很多小说更新太慢,所以本人就只能找一个 ...

  2. jdk11新特性

    JDK 11主要特性一览 jdk11即将在9月25号发布正式版.确定的新特性包括以下17个 181 嵌套类可见性控制 309 动态文件常量 315 改进 Aarch64 Intrinsics 318 ...

  3. 中国软件大会上大快搜索入选中国数字化转型TOP100服务商

    大快搜索自荣获“2018中国大数据企业50强”殊荣,12月20日在由工信部指导,中国电子信息产业化发展研究院主办的2018中国软件大会上,大快搜索获评“2018中国大数据基础软件领域领军企业”称号,入 ...

  4. jetty 服务器配置无项目名

    运行命令:java -jar start.jar jetty.http.port=8080,建议写成bat文件来运行. 部署无项目名的项目,将war包改成root,复制到webapps, 然后在jet ...

  5. express with bower in websotrm

    0. To install bower , run the following command in webstorm terminal(alt+f12) npm install bower bowe ...

  6. 成都优步uber司机第三组奖励政策

    今天成都优步又推出了优步司机第三组,第一二组的奖励大家都晓得,但是第三组的奖励怎么样呢?还是先看看官方给出的消息. 滴滴快车单单2.5倍,注册地址:http://www.udache.com/如何注册 ...

  7. C#学习第一阶段——语法基础

    C#是一门面向对象的编程语言.在面向对象的程序设计方法中,程序由各种相互交互的对象组成.相同种类的对象具有相同的属性,或者说是在相同的class 中的.       例如,以矩形为例,它具有高(len ...

  8. L010 linux命令及基础手把手实战总结

    一转眼都快两周没更新了,最近实在太忙了,这两周的时间断断续续的把L010学完了,短短的15节课,确是把前10节的课程全部的运用一遍,从笔记到整理,再到重新理解,最后发布到微博,也确实提升了一些综合性能 ...

  9. nodejs HTTP服务

    nodejs中的HTTP服务   nodejs最重要的方面之一是具有非常迅速的实现HTTP和HTTPS服务器和服务的能力.http服务是相当低层次的,你可能要用到不同的模块,如express来实现完整 ...

  10. pg mysql 比较

    PostgreSQL 与 MySQL比较: 一.pg优势: MySQL 不支持 OVER 子句, 而 Pg 支持 它可以存储 array 和 json, 可以在 array 和 json 上建索引, ...