错误代码:

#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的更多相关文章

  1. hdoj 2036 改革春风吹满地

    改革春风吹满地 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Sub ...

  2. Hdoj 2036.改革春风吹满地 题解

    Problem Description " 改革春风吹满地, 不会AC没关系; 实在不行回老家, 还有一亩三分地. 谢谢!(乐队奏乐)" 话说部分学生心态极好,每天就知道游戏,这次 ...

  3. hdoj:2036

    #include <iostream> using namespace std; struct Point { int x, y; }; Point a[]; int main() { i ...

  4. HDOJ 1009. Fat Mouse' Trade 贪心 结构体排序

    FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  5. HDOJ 2317. Nasty Hacks 模拟水题

    Nasty Hacks Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Tota ...

  6. HDOJ 1326. Box of Bricks 纯水题

    Box of Bricks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) To ...

  7. HDOJ 1004 Let the Balloon Rise

    Problem Description Contest time again! How excited it is to see balloons floating around. But to te ...

  8. hdoj 1385Minimum Transport Cost

    卧槽....最近刷的cf上有最短路,本来想拿这题复习一下.... 题意就是在输出最短路的情况下,经过每个节点会增加税收,另外要字典序输出,注意a到b和b到a的权值不同 然后就是处理字典序的问题,当松弛 ...

  9. HDOJ(2056)&HDOJ(1086)

    Rectangles    HDOJ(2056) http://acm.hdu.edu.cn/showproblem.php?pid=2056 题目描述:给2条线段,分别构成2个矩形,求2个矩形相交面 ...

随机推荐

  1. [LeetCode#12] Roman to Integer

    Problem: Given an integer, convert it to a roman numeral. Input is guaranteed to be within the range ...

  2. java 去掉字符串右侧空格

    public static String rightTrim(String str) {    String regex = "(.*\\S+)(\\s+$)";    Patte ...

  3. HDU-2149 Public Sale

    http://acm.hdu.edu.cn/showproblem.php?pid=2149 巴什博奕(Bash Game): Public Sale Time Limit: 1000/1000 MS ...

  4. MVC5 学习整理

    一.概述 MVC简介: •       模型(Model) “数据模型”(Model)用于封装与应用程序的业务逻辑相关的数据以及对数据的处理方法.“模型”有对数据直接访问的权力,例如对数据库的访问.“ ...

  5. leetcode 字符串分割对称

    public class Solution { public List<List<String>> partition(String s) { int len=s.length ...

  6. Poj 3580-SuperMemo Splay

    题目:http://poj.org/problem?id=3580   SuperMemo Time Limit: 5000MS   Memory Limit: 65536K Total Submis ...

  7. 最全面的 DNS 原理入门

    DNS 是互联网核心协议之一.不管是上网浏览,还是编程开发,都需要了解一点它的知识. 本文详细介绍DNS的原理,以及如何运用工具软件观察它的运作.我的目标是,读完此文后,你就能完全理解DNS. 一.D ...

  8. 武汉Uber优步司机奖励政策(1月25日~1月31日)

    滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...

  9. poj 3687 Labeling Balls【反向拓扑】

    Labeling Balls Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 12246   Accepted: 3508 D ...

  10. hdoj 1050 Moving Tables【贪心区间覆盖】

    Moving Tables Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...