URAL 1942 Attack at the Orbit
来源:互联网 发布:python快速注释快捷键 编辑:程序博客网 时间:2024/04/29 09:38
一艘飞船,舰载大炮可以摧毁位于雷达坐标轴整点处(两坐标均为整数)的目标,坐标轴原点可以移动一次,求最多摧毁目标,如果有多种情况求原点移动距离较小的那一个
题目说坐标只有3位小数,且将坐标变成整数只需考虑小数部分,因此用a[1000][1000]的数组记录移动x,y后有多少个点移到了整数点上,由于x和y各有加和减两种情况,因此一个点有四种情况+1,为了方便区别将加处理+1000,开a[2000][2000]。计算时对1000取余。
#include <iostream>#include <cstring>#include <queue>#include <cmath>#include <cstdio>#include <algorithm>#define eps 1e-7using namespace std;int a[2200][2200];int dis(int a,int b){ return a*a+b*b;}int main(){ int n; double x,y; while(~scanf("%d",&n)) { memset(a,0,sizeof(a)); for(int i=1;i<=n;i++) { scanf("%lf%lf",&x,&y); int x1; x1=floor(x*1000+eps); int y1; y1=floor(y*1000+eps); int x2,y2; int x3,y3; x2=x1%1000; y2=y1%1000; if(x2<0) { x2+=1000; } x3=1000-x2; y2=y1%1000; if(y2<0) { y2+=1000; } y3=1000-y2; a[x2][y2]++; a[x2][y3+1000]++; a[x3+1000][y2]++; a[x3+1000][y3+1000]++; } int ans=0; int p,q; for(int i=0;i<1999;i++) { for(int j=0;j<1999;j++) { if(ans<a[i][j]||(ans==a[i][j]&&dis(p%1000,q%1000)>dis(i%1000,j%1000))) { ans=a[i][j]; p=i; q=j; } } } printf("%d ",ans); //printf("%d %d",p,q); printf("%.9lf\n",sqrt(dis(p%1000,q%1000))/1000.0); } return 0;}
0 0
- URAL 1942 Attack at the Orbit
- URAL 1942 Attack at the Orbit
- URAL 1942 Attack at the Orbit
- URAL 1942 Attack at the Orbit
- URAL 1942 Attack at the Orbit
- URAL 1942 Attack at the Orbit
- URAL 1942 Attack at the Orbit
- URAL 1942 Attack at the Orbit
- URAL 1942 Attack at the Orbit
- URAL 1942 Attack at the Orbit
- URAL 1942 Attack at the Orbit
- URAL 1942 Attack at the Orbit
- URAL 1942 Attack at the Orbit
- URAL 1942 Attack at the Orbit
- URAL 1942 Attack at the Orbit
- URAL 1942 Attack at the Orbit
- URAL 1942 Attack at the Orbit
- URAL 1942 Attack at the Orbit
- learning the shell
- 大数对小数的求余和商
- Spring中使用数据源
- 黑马程序员_C语言之复杂数据类型
- 掌握 Java 泛型类型(一)
- URAL 1942 Attack at the Orbit
- java RSA加密解密实现
- 万能营销软件8.508版本
- ExpandablePanel
- [MySQL版本差异] 丢失frm文件之后drop database的不同结果分析
- 简单的文件加密
- 如何在WIN7的64b的环境下安装Arduino Leonardo的驱动(傻瓜式教程)
- 关于获取Bitmap图片的大小的方法
- 关于中国科大的现状和未来