计算几何

练习题:

Bessie, Farmer John's prize cow, has just won first place in a bovine beauty contest, earning the title 'Miss Cow World'. As a result, Bessie will make a tour of N (2 <= N <= 50,000) farms around the world in order to spread goodwill between farmers and their cows. For simplicity, the world will be represented as a two-dimensional plane, where each farm is located at a pair of integer coordinates (x,y), each having a value in the range -10,000 ... 10,000. No two farms share the same pair of coordinates.

Even though Bessie travels directly in a straight line
between pairs of farms, the distance between some farms can be quite
large, so she wants to bring a suitcase full of hay with her so she has
enough food to eat on each leg of her journey. Since Bessie refills her
suitcase at every farm she visits, she wants to determine the maximum
possible distance she might need to travel so she knows the size of
suitcase she must bring.Help Bessie by computing the maximum distance
among all pairs of farms.

Input

* Line 1: A single integer, N

* Lines 2..N+1: Two space-separated integers x and y specifying coordinate of each farm

Output

* Line 1: A single integer that is the squared distance between
the pair of farms that are farthest apart from each other.

Sample Input

4
0 0
0 1
1 1
1 0

Sample Output

2

Hint

Farm 1 (0, 0) and farm 3 (1, 1) have the longest distance (square root of 2)
 #include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string.h> using namespace std; struct Point
{
int x,y;
Point(int _x=,int _y=)
{
x=_x;
y=_y;
}
Point operator -(const Point &b) const
{
return Point(x-b.x,y-b.y);
}
int operator ^(const Point &b) const
{
return x*b.y-y*b.x;
}
int operator *(const Point &b) const
{
return x*b.x+y*b.y;
}
void input()
{
scanf("%d%d",&x,&y);
}
}; int dist2(Point a,Point b)
{
return (a-b)*(a-b);
}
const int maxn=;
Point list[maxn];
int Stack[maxn],top;
bool _cmp(Point p1,Point p2)
{
int tmp=(p1-list[])^(p2-list[]);
if(tmp>) return true;
else if(tmp== && dist2(p1,list[])<= dist2(p2,list[]))
return true;
else return false;
}
void Graham(int n)
{
Point p0;
int k=;
p0=list[];
for(int i=;i<n;i++)
if(p0.y>list[i].y || (p0.y==list[i].y && p0.x>list[i].x))
{
p0=list[i];
k=i;
}
swap(list[],list[k]);
sort(list+,list+n,_cmp);
if(n==)
{
top=;
Stack[]=;
return ;
}
if(n==)
{
top=;
Stack[]=;
Stack[]=;
return ;
}
Stack[]=;
Stack[]=;
top=;
for(int i=;i<n;i++)
{
while(top> && ((list[Stack[top-]]-list[Stack[top-]])^(list[i]-list[Stack[top-]]))<=)
top--;
Stack[top++]=i;
}
}
//旋转卡壳,求两点间距离平方的最大值
int rotating_calipers(Point p[],int n)
{
int ans=;
Point v;
int cur=;
for(int i=;i<n;i++)
{
v=p[i]-p[(i+)%n];
while((v^(p[(cur+)%n]-p[cur]))<)
cur=(cur+)%n;
ans=max(ans,max(dist2(p[i],p[cur]),dist2(p[(i+)%n],p[(cur+)%n])));
}
return ans;
}
Point p[maxn];
int main()
{
int n;
while(scanf("%d",&n)==)
{
for(int i=;i<n;i++)
list[i].input();
Graham(n);
for(int i=;i<top;i++)
p[i]=list[Stack[i]];
printf("%d\n",rotating_calipers(p,top));
}
return ;
}

Arcade mall is a new modern mall. It has a new hammer game called "Arcade Game". In this game you're presented with a number n which is hanged on a wall on top of a long vertical tube, at the bottom of the tube there is a button that you should hit with your hammer.

When you hit the button with all your force (as you always do), a ball is pushed all over the tube and hit the number n. The number n flies in the air and it's digits fall back in any random permutation with uniform probability.

If the new number formed is less than or equal to the previous number, the game ends and you lose what ever the new number is. Otherwise (if the number is greater than the previous number), you are still in the game and you should hit the button again.

You win if the new number formed is greater than the previous number and it is equal to the greatest possible permutation number.

Can you compute the probability of winning?

Input

The first line of the input contains the number of test cases T. Following that there are T lines represents T test cases. In each line, there is a single integer (1 ≤ n ≤ 109) the target number. The digits of n are all unique, which means that any 2 digits of n are different.

Output

For each test case, print one line containing the answer. Print the answer rounded to exactly 9 decimal digits.

Examples

Input
3
952
925
592
Output
0.000000000
0.166666667
0.194444444

Note

In the first test case, the answer is 0 because 952 is greater than all 2,5 and 9 permutations so you can't win, whatever you do.

In the second test case, the answer is 0.166666667 because you may win by getting number 952 with probability 1/6.

In the third test case the answer is 0.194444444 because you may win by getting number 952 in round1 with probability 1/6 or you can win by getting number 925 in round 1 and then 952 in round 2 with probability 1/6 * 1/6.

原博客:https://blog.csdn.net/why850901938/article/details/51204620
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
int n[]={,};
int a[];
double p,q;
int main()
{
for(int i=;i<;i++)
{
n[i]=n[i-]*i;
}
int T;
cin>>T;
while(T--)
{
char s[];
int cnt=;
scanf("%s",s);
int l=strlen(s);
for(int i=;i<l;i++)
{
a[i]=s[i]-'';
}
while(next_permutation(a,a+l))
{
cnt++;
}
if(cnt==)
{
printf("0.000000000\n");
}
else
{
double temp=1.0/n[l];
q=p=temp;
for(int i=;i<cnt;i++)
{
q=p+p*temp;
p=q;
}
printf("%.9lf\n",p);
}
}
return ;
}

Geometry is a very important field in mathematics, Squares and rectangles are essential shapes in geometry, both of them have 4 right angles, but a square is a special case of a rectangle where width and height are the same.

The figure below shows a square on the left and a rectangle on the right:

If you have the width and the height of a 4 right angled shape, can you figure out if it is a square or a rectangle?

Input

The first line contains T, the number of test cases, for each test case there is a line with two integers (1 ≤ w, h ≤ 1, 000, 000) representing width and height, respectively.

Output

For each test case, print one line consists of 'Square'
if the shape is a square, otherwise print 'Rectangle' if it is a
rectangle.

Examples

Input
3
10 10
13 200
300 300
Output
Square
Rectangle
Square
 #include<stdio.h>
int main()
{
int n,a,b;
scanf("%d",&n);
while(n--)
{
scanf("%d %d",&a,&b);
if(a==b)
printf("Square\n");
else
printf("Rectangle\n");
}
return ;
}

Salem is known to be one of the best competitive programmers in the region. However, he always finds a hard time understanding the concept of the hamming distance. The hamming distance of two numbers is defined as the number of different digits in their binary representations (leading zeros are used if necessary to make the binary representations have the same length). For example the hamming distance between 12 and 5 is 2 since their binary representations are 1100 and 0101 respectively and they differ in the first and fourth positions.

Recently, Salem got a problem that he needs your help to solve. He is given N integers and asked to get the maximum among the hamming distances of all possible pairs of the given integers.

Input

The first line of the input will be a single integer T representing the number of test cases. Followed by T test cases. Each test case will start with a line with single integer (2 ≤ N ≤ 100) representing the number of the integers. Each of the following N lines contains one of the integers (1 ≤ Ai ≤ 10, 000) from the list of the integers.

Output

For each test case print one line consists of one integer
representing the maximum hamming distance between all possible pairs
from the given integers.

Examples

Input
2
2
12
5
3
1
2
3
Output
2
2
 #include<iostream>
#include<cstdio>
using namespace std;
int check(int n)
{
int c=;
while(n)
{
n=n&(n-);
c++;
}
return c;
}
int main()
{
int n;
int a[];
cin>>n;
while(n--)
{
int n1;
cin>>n1;
int maxx=;
for(int i=;i<=n1;i++)
{
cin>>a[i];
}
for(int i=;i<=n1;i++)
{
for(int j=i+;j<=n1;j++)
{
int m=check(a[i]^a[j]);
// cout<<"m: "<<m<<endl;
if(m>maxx)
maxx=m;
}
}
cout<<maxx<<endl;
}
}
 

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

  1. javaSE第二十六天

    第二十六天    414 1:网络编程(理解)    414 (1)网络编程:用Java语言实现计算机间数据的信息传递和资源共享    414 (2)网络编程模型    414 (3)网络编程的三要素 ...

  2. javaSE第十六天

    第十六天    140 1:List的子类(掌握)    140 (1)List的子类特点    140 (2)ArrayList    141 A:没有特有功能需要学习    141 B:案例    ...

  3. 第三百五十六天 how can I 坚持

    一年了,三百五十六天.写个算法算下对不对. 今天突然想买辆自行车了.云马智行车,还是捷安特,好想买一辆. 网好卡.貌似少记了一天呢,357了.好快. 睡觉了,还没锻炼呢,太晚了. 1458748800 ...

  4. IT第二十六天 - Swing、上周总结

    IT第二十六天 上午 Swing 1.对于方法的参数如果是int数值类型,应该直接调用该类中的常量属性,而不应该直接填入数字 2.Toolkit类中定义的方法是可以直接访问本地计算机(操作系统)信息的 ...

  5. Python第二十六天 python装饰器

    Python第二十六天 python装饰器 装饰器Python 2.4 开始提供了装饰器( decorator ),装饰器作为修改函数的一种便捷方式,为工程师编写程序提供了便利性和灵活性装饰器本质上就 ...

  6. OCM_第十六天课程:Section7 —》GI 及 ASM 安装配置 _安装 GRID 软件/创建和管理 ASM 磁盘组/创建和管理 ASM 实例

    注:本文为原著(其内容来自 腾科教育培训课堂).阅读本文注意事项如下: 1:所有文章的转载请标注本文出处. 2:本文非本人不得用于商业用途.违者将承当相应法律责任. 3:该系列文章目录列表: 一:&l ...

  7. 孤荷凌寒自学python第八十六天对selenium模块进行较详细的了解

    孤荷凌寒自学python第八十六天对selenium模块进行较详细的了解 (今天由于文中所阐述的原因没有进行屏幕录屏,见谅) 为了能够使用selenium模块进行真正的操作,今天主要大范围搜索资料进行 ...

  8. 孤荷凌寒自学python第七十六天开始写Python的第一个爬虫6

    孤荷凌寒自学python第七十六天开始写Python的第一个爬虫6 (完整学习过程屏幕记录视频地址在文末) 今天在上一天的基础上继续完成对我的第一个代码程序的书写. 不过由于对python-docx模 ...

  9. 孤荷凌寒自学python第六十六天学习mongoDB的基本操作并进行简单封装5

    孤荷凌寒自学python第六十六天学习mongoDB的基本操作并进行简单封装5并学习权限设置 (完整学习过程屏幕记录视频地址在文末) 今天是学习mongoDB数据库的第十二天. 今天继续学习mongo ...

随机推荐

  1. 利用ascii码生成26个英文字母

    <script> let a = ""; for (var i = 65; i < 91; i++) { a += String.fromCharCode(i); ...

  2. Spring异常重试框架Spring Retry

    Spring Retry支持集成到Spring或者Spring Boot项目中,而它支持AOP的切面注入写法,所以在引入时必须引入aspectjweaver.jar包. 快速集成的代码样例: @Con ...

  3. Debian中CodeIgniter+nginx+MariaDB+phpMyAdmin配置

    本文不讲述软件安装过程,记述本人在Debia中配置CodeIgniter时遇到的问题及解决方法,希望能够为有需要的人提供帮助. 一.Debian版本及所需的软件 Debian 9.8 stretch ...

  4. Oracle之基础操作

    sqlplus常用命令: 进入sqlplus模式:sqlplus /nolog 管理员登录: conn / as sysdba 登录本机的数据库 conn sys/123456 as sysdba 普 ...

  5. 用Python生成词云

    词云以词语为基本单元,根据词语在文本中出现的频率设计不同大小的形状以形成视觉上的不同效果,从而使读者只要“一瞥“即可领略文本的主旨.以下是一个词云的简单示例: import jieba from wo ...

  6. Python3 urllib 与 Python2 urllib的变化

    Infi-chu: http://www.cnblogs.com/Infi-chu/ Py2.x: Urllib库 Urllin2库 Py3.x: Urllib库 变化: 在Pytho2.x中使用im ...

  7. Android APP架构设计——MVC、MVP和MVVM介绍

    )对于过大的项目,数据绑定需要花费更多的内存. 关于APP的架构设计就介绍到这吧,转载请注明出处:http://blog.csdn.net/seu_calvin/article/details/529 ...

  8. Uber优步北京第四组奖励政策

    优步北京第四组: 定义为2015年7月20日至今激活的司机(以优步后台数据显示为准) 滴滴快车单单2.5倍,注册地址:http://www.udache.com/如何注册Uber司机(全国版最新最详细 ...

  9. c++继承详解:共有(public)继承,私有继承(private)继承,保护(protected)继承

    公有继承(public)继承.私有继承(private).保护继承(protected)是常用的三种继承方式. 1.公有继承(public) 公有继承的特点是基类的公有成员和保护成员作为派生类的成员时 ...

  10. iOS SSL Pinning 保护你的 API

    随着互联网的发展,网站全面 https 化已经越来越被重视,做为 App 开发人员,从一开始就让 API 都走 SSL 也是十分必要的.但是光这样就足够了吗? SSL 可以保护线上 API 数据不被篡 ...