POJ 1939 Diplomatic License(水~)
来源:互联网 发布:php正则获取a标签href 编辑:程序博客网 时间:2024/05/20 07:33
Description
给你n(n>=3且n为奇数)个点的坐标,这n(按构成多边形的顺序输入的)个点必然构成一个多边形,要你按输入顺序输出这个多边形各边的中点坐标.
Input
多组输入,每组用例占一行,第一个整数为点的个数n,然后是2*n个浮点数分别表示这n个点的坐标,以文件尾结束输入
Output
对于每组用例,按输入顺序输出由这n个点组成多边形各边中点的坐标
Sample Input
5 10 2 18 2 22 6 14 18 10 18
3 -4 6 -2 4 -2 6
3 -8 12 4 8 6 12
Sample Output
5 14.000000 2.000000 20.000000 4.000000 18.000000 12.000000 12.000000 18.000000 10.000000 10.000000
3 -3.000000 5.000000 -2.000000 5.000000 -3.000000 6.000000
3 -2.000000 10.000000 5.000000 10.000000 -1.000000 12.000000
Solution
水题,直接按输入顺序求出中点坐标,然后输出即可.注意最后一个中点是输入的起点和终点的中点.
Code
#include<stdio.h>int main(){ int n,i; double x[1000],y[1000],mx[1000],my[1000]; while(scanf("%d",&n)!=EOF) { for(i=0;i<n;i++) scanf("%lf%lf",&x[i],&y[i]); for(i=0;i<n-1;i++) { mx[i]=(x[i]+x[i+1])/2.0; my[i]=(y[i]+y[i+1])/2.0; } mx[n-1]=(x[0]+x[n-1])/2.0; my[n-1]=(y[0]+y[n-1])/2.0; printf("%d",n); for(i=0;i<n;i++) printf(" %.6lf %.6lf",mx[i],my[i]); printf("\n"); }}
0 0
- POJ 1939 Diplomatic License(水~)
- poj 1939 Diplomatic License
- POJ 1939 Diplomatic License G++
- zoj 1973 || poj 1939 Diplomatic License
- POJ 1939 Diplomatic License(求线段中点)
- 【坑】【水】poj1939 Diplomatic License
- 【POJ1939】:Diplomatic License
- BSD License(BSD)
- BSD License(BSD)
- License
- License
- license
- license
- Common license types(zz)
- 开源license总结(转贴)
- License系统设计(一)
- License系统设计(二)
- Microsoft License(简称MS-CL)
- nginx+php的配置
- hdu 1548 最短路||bfs
- 百度地图V3.5.0获取可视地图范围中心点、东北方、西南方(右上角、左下角)坐标
- Secure Delivery Center快速入门指南(二):交付软件包
- Android 硬件加速
- POJ 1939 Diplomatic License(水~)
- Object有哪些基本的方法
- 字符串格式化printf中“%%”的小坑
- android图标尺寸
- 互联网模式下我们更加应该“专注”
- 【Win 10应用开发】如何知道当前APP在哪个平台设备上运行
- EPOLL 边缘触发学习
- 【c语言】调整数组使奇数全部都位于偶数前面
- Unity IOS微信SDK接入