计算几何

练习题:

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. Linux中Kibana部署

    1.下载kibana安装包kibana-5.5.0-linux-x86_64.tar.gz tar –xzf kibana-5.5.0-linux-x86_64.tar.gz解压 把文件移动到 Mv ...

  2. CentOS7 宝塔搭配git 实时更新项目源码

    上一篇文章 介绍了如何在CentOS7上 搭建GIT环境 详见链接:https://www.cnblogs.com/mverting/p/10206532.html 本章主要介绍git如何和wdcp搭 ...

  3. vowels_双元音

    vowels(美式): 双元音:前长后短.前强后弱,流畅滑动. [e]:两个字母“e”和“I”的结合,单词cake.rain.blame.lack.make.later. [aɪ]:两个字母“a”和“ ...

  4. Jetson tx2 串口通信

    主要参考了这篇博客:https://blog.csdn.net/zomb1e0117/article/details/85157014 其中需要注意的是最后的时候cutecom端口需要把设备改为:/d ...

  5. JAVA8 Stream API的使用

    /** * @auther hhh * @date 2018/12/31 12:48 * @description Stream流:用来处理数组.集合的API * 1.不是数据结构,没有内部存储(只是 ...

  6. 笔记-django- HttpRequest/Response

    笔记-django- HttpRequest/Response 1.      HttpRequest/Response When a page is requested, Django create ...

  7. springboot 配置二级缓存

    springBoot中配置mybatis的二级缓存 2018年01月22日 11:45:37 Ting.Xue(Martin.Xue) 阅读数:5604更多 个人分类: SSM的Spring框架Myb ...

  8. Python-特殊变量

    from test import test ''' __mame__ __file__ __cache__ __package__ ''' # import os # 获取这个当前文件的绝对路径 # ...

  9. unity share current game screen

    using UnityEngine; using System.Collections; using UnityEngine.UI; using System.IO; public class Tak ...

  10. POSTMan 快速上手(一图带你玩 Postman )

    POSTMan 快速上手(一图带你玩 Postman ):