HDOJ 2036
错误代码:
#include<stdio.h>
#include<math.h>
int main()
{
int x[102],y[102];
int i,n;
float s,a,b,c,p;
while(scanf("%d",&n)!=EOF&&n)
{
for(i=0;i<n;i++)
scanf("%d%d",&x[i],&y[i]);
s=0;
for(i=2;i<n;i++)
{
a=sqrt((x[0]-x[i-1])*(x[0]-x[i-1])+(y[0]-y[i-1])*(y[0]-y[i-1]));
b=sqrt((x[i-1]-x[i])*(x[i-1]-x[i])+(y[i-1]-y[i])*(y[i-1]-y[i]));
c=sqrt((x[0]-x[i])*(x[0]-x[i])+(y[0]-y[i])*(y[0]-y[i]));
p=(a+b+c)/2;
s+=sqrt(p*(p-a)*(p-b)*(p-c));
}
printf("%.1f\n",s);
}
return 0;
}
未考虑凹多边形的情况 。
正确代码:
#include <stdio.h>
struct point
{
int x;
int y;
} p[101];
int main()
{
int n, i, k;
double area;
while (scanf("%d", &n) != EOF && n != 0)
{
area = 0.0;
k = n;
for (i = 0; i < n; i++)
{
scanf("%d%d", &p[i].x, &p[i].y);
}
for (i = 0; i < k-1; i++)
{
area = area + 0.5 * (p[i].x * p[i+1].y - p[i+1].x * p[i].y);
}
area = area + 0.5 * (p[k-1].x * p[0].y - p[0].x * p[k-1].y);
printf("%.1lf\n", area);
}
return 0;
}
|
HDOJ 2036的更多相关文章
- hdoj 2036 改革春风吹满地
改革春风吹满地 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Sub ...
- Hdoj 2036.改革春风吹满地 题解
Problem Description " 改革春风吹满地, 不会AC没关系; 实在不行回老家, 还有一亩三分地. 谢谢!(乐队奏乐)" 话说部分学生心态极好,每天就知道游戏,这次 ...
- hdoj:2036
#include <iostream> using namespace std; struct Point { int x, y; }; Point a[]; int main() { i ...
- HDOJ 1009. Fat Mouse' Trade 贪心 结构体排序
FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- HDOJ 2317. Nasty Hacks 模拟水题
Nasty Hacks Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Tota ...
- HDOJ 1326. Box of Bricks 纯水题
Box of Bricks Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To ...
- HDOJ 1004 Let the Balloon Rise
Problem Description Contest time again! How excited it is to see balloons floating around. But to te ...
- hdoj 1385Minimum Transport Cost
卧槽....最近刷的cf上有最短路,本来想拿这题复习一下.... 题意就是在输出最短路的情况下,经过每个节点会增加税收,另外要字典序输出,注意a到b和b到a的权值不同 然后就是处理字典序的问题,当松弛 ...
- HDOJ(2056)&HDOJ(1086)
Rectangles HDOJ(2056) http://acm.hdu.edu.cn/showproblem.php?pid=2056 题目描述:给2条线段,分别构成2个矩形,求2个矩形相交面 ...
随机推荐
- poj3580
区间操作的究极题,我们一个个来分析其实只有insert,delete,revolve三种没讲过insert 先把x旋到根,一开始我比较SB的,准备把新节点插入到右子树的最左节点,这显然很烦 好的方法是 ...
- VisualBox ubuntu14.04 64位 android4.4.4源码编译总结
转载请保留出处:http://www.cnblogs.com/wi100sh/p/4337907.html 折腾了好几天,今天终于编译通过,用了4个多小时,太不容易了.如下图所示: 软件环境 虚拟机: ...
- VGA IP核的制作
今天看了本<系统晶片设计-使用NIOS>这本书,看到VGA IP核的设计不错,特移植到Cyclone III上来,试验一下效果. 顶层代码:binary_VGA.v module bina ...
- 用xib文件,配置UITableViewCell
http://www.cnblogs.com/lixingle/p/3287499.html 在运行时候,如果出现“this class is not key value coding-complia ...
- mipi 调试经验
转载自http://blog.csdn.net/g_salamander/article/details/9163455 以下是最近几个月在调试 MIPI DSI / CSI 的一些经验总结,因为协议 ...
- Ubuntu 安装vim出错
在Ubuntu 12.10中安装vim时出现了如下提示: www.linuxidc.com @linuxidc:/etc/apt$ sudo apt-get install vim正在读取软件包列表. ...
- hdoj 3342 Legal or Not【拓扑排序】
Legal or Not Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tota ...
- IAP内购 返回的产品数量为0
上个月搞IAP,提交到appstore审核被拒,根据附件截图 可以知道是请求产品信息的时候,产品数量返回0了. 返回产品数量为0 要么是Itunes Connect 里面的Contracts Tax ...
- MFC编程小技巧——强制杀死进程
在某些应用场合下,我们可能需要在启动A进程启动时关闭进程B.MFC下该如何做呢?以下是我项目中用到的代码: int KillProcess(DWORD Pid) { //打开进程得到进程句柄 HAND ...
- MapReduce输出格式
针对前面介绍的输入格式,MapReduce也有相应的输出格式.默认情况下只有一个 Reduce,输出只有一个文件,默认文件名为 part-r-00000,输出文件的个数与 Reduce 的个数一致. ...