计算几何

练习题:

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. 新人成长之入门Vue.js弹窗Dialog介绍(二)

    前言 在上一篇博文中介绍了Vue.js的常用指令,今天总结归纳一下弹窗Dialog的使用,弹窗经常被使用在一些表单的增删改查啊,或者弹出一些提示信息等等,在保留当前页面状态的情况下,告知用户并承载相关 ...

  2. 【Spark】源码分析之spark-submit

    在客户端执行脚本sbin/spark-submit的时候,通过cat命令查看源码可以看出,实际上在源码中将会执行bin/spark-class org.apache.spark.deploy.Spar ...

  3. 集合之Map

    Map:存放键值对,根据键对象找对应的值对象.键不能重复!Map键不能重复,有唯一性,一般通过键找对应的的值Map集合的特点: 1.具有映射关系 2.两列 3.一列要唯一 一列可以重复 键类似于 Se ...

  4. rails应用使用carrierwave和mini_magick上传用户头像

    1. 在Gemfile添加 gem 'carrierwave' gem 'mini_magick' 执行 bundle install 2. 生成uploader rails generate upl ...

  5. FPGA软硬协同设计学习笔记及基础知识(一)

    一.FPGA软件硬件协同定义: 软件:一般以软件语言来描述,类似ARM处理器的嵌入式设计.硬件定义如FPGA,里面资源有限但可重配置性有许多优点,新的有动态可充配置技术. Xilinx开发了部分动态可 ...

  6. 为什么我要放弃javaScript数据结构与算法(第六章)—— 集合

    前面已经学习了数组(列表).栈.队列和链表等顺序数据结构.这一章,我们要学习集合,这是一种不允许值重复的顺序数据结构. 本章可以学习到,如何添加和移除值,如何搜索值是否存在,也可以学习如何进行并集.交 ...

  7. PHP.48-TP框架商城应用实例-后台23-权限管理-权限验证

    权限验证 1.登录控制器 2.通过tp验证码类生成验证码图片 3.在管理员模型增加登录验证规则 4.后台中所有的控制器必须先登录才能访问 思路:在访问任何一个控制器之前都判断一个session即可,= ...

  8. Spring Cloud 分布式事务管理

    Spring Cloud 分布式事务管理 在微服务如火如荼的情况下,越来越多的项目开始尝试改造成微服务架构,微服务即带来了项目开发的方便性,又提高了运维难度以及网络不可靠的概率. Spring Clo ...

  9. RTL8188EUS之MAC地址烧写(使用利尔达模组)

    1. 手上有几个RTL8188EUS的wifi模块,打算把台式机装个无线网卡,但是插上之后发现没有MAC,没办法只能自己去找个烧写MAC的软件.RTL8188内部有个eFuse,用来配置之类的.这个e ...

  10. MyBatis-SELECT基本查询

    1.返回一个LIST <!-- public List<Employee> getEmpsByLastNameLike(String lastName); --> <!- ...