计算几何

练习题:

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. webpack 优化代码 让代码加载速度更快

    一,如何优化webpack构建 (1),缩小文件搜索范围, 优化Loader配置 module.exports = { module: { rules: [ { test:/\.js$/, use:[ ...

  2. 【Android】Android Studio真机调试的问题统整

    真机调试需要注意以下几个问题 [1]手机的USB调试需开启 [2]手机不能是仅充电模式,需要传输数据模式 [3]有些USB线会偷工减料,请拿一条没问题的线,例如买手机时原厂给的配线 [4]在PC端需要 ...

  3. 说一说MySQL的锁机制

    锁概述 MySQL的锁机制,就是数据库为了保证数据的一致性而设计的面对并发场景的一种规则. 最显著的特点是不同的存储引擎支持不同的锁机制,InnoDB支持行锁和表锁,MyISAM支持表锁. 表锁就是把 ...

  4. java 用户修改密码

    import java.util.Scanner; class Member { private String mima; private String name; public String get ...

  5. for循环删除列表中元素遇到的漏删的问题(python)

    问题描述:python中通过for循环来删除列表中的两个相邻的元素,存在漏删的问题 比如说下面的例子,准备删掉2和3,但是结果是2删掉了,3没删掉 是因为把2删掉后3的下标就变成了1,但是原本下标为1 ...

  6. 解决ssh连接中断程序终止的问题——tmux

    参考:http://www.cnblogs.com/kevingrace/p/6496899.html ssh连接有时候会异常中断,重连后原本运行的程序会中断,要解决这个问题,我们可以使用Linux终 ...

  7. Scala学习笔记(三)—— 方法和函数

    1. 方法 方法使用 def 定义: def 方法名(参数名:参数列表,…) :返回值类型 = { 方法结构体 } scala> def add(x : Int ,y : Int):Int = ...

  8. 分布式存储系统Kudu与HBase的简要分析与对比

    本文来自网易云社区 作者:闽涛 背景 Cloudera在2016年发布了新型的分布式存储系统——kudu,kudu目前也是apache下面的开源项目.Hadoop生态圈中的技术繁多,HDFS作为底层数 ...

  9. 【blockly教程】第四章 Blockly之选择结构

    今天,我们通过一个游戏来学习选择结构,游戏的地址如下:https://blockly-games.appspot.com/bird?lang=en本游戏分为10关:主要游戏规则如下:①主界面是游戏的运 ...

  10. 机房人民大团结(DP)

    最近,机房出了一个不团结分子:Dr.Weissman.他经常欺骗同学们吃一种“教授糖豆”,使同学们神志不清,殴打他人,砸烂计算机,破坏机房团结.幸运地,一个和谐家认清了Dr.Weissman的本质.机 ...