hdu2108

判断是否为凸边形

判断连续三点的叉乘

若为凸,内角<180;若为凹,内角>180

所以通过正负来判断

#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <cmath>
#include <algorithm>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
const int N=100050;
struct node
{
int x,y;
}pnode[N]; int judge(int x,int y,int z)
{
return (pnode[y].x - pnode[x].x)*(pnode[z].y - pnode[y].y)-(pnode[z].x - pnode[y].x)*(pnode[y].y - pnode[x].y);
} int main()
{
int n; while(scanf("%d",&n) && n)
{
for(int i = 1;i <= n;i++)
scanf("%d%d",&pnode[i].x,&pnode[i].y);
pnode[n+1].x = pnode[1].x;
pnode[n+1].y = pnode[1].y;
pnode[n+2].x = pnode[2].x;
pnode[n+2].y = pnode[2].y;
int flag = 0;
for(int i = 1;i <= n;i++)
{
if(judge(i,i+1,i+2)<0)
{
flag = 1;
break;
}
}
if(flag )
printf("concave\n");
else
printf("convex\n"); }
return 0;
} hdu2036 求一个多边形的面积 分成许多个三角形来计算。 S△ = 向量AB 与 向量AC的叉乘/2 #include <stdio.h>
#include <math.h>
int main()
{
int n,i,j;
double S,x[101],y[101];
while(scanf("%d",&n) && n != 0)
{
for(i = 0;i < n;i++)
scanf("%lf%lf",&x[i],&y[i]);
x[i] = x[0];
y[i] = y[0];
S = 0;
for(j = 0;j < i;j++)
S += x[j] * y[j+1] - x[j+1] * y[j];
S = fabs(S / 2);
printf("%.1lf\n",S);
}
return 0;
}

  

HDU2108和HDU2036(叉乘)的更多相关文章

  1. [数据结构]——二叉树(Binary Tree)、二叉搜索树(Binary Search Tree)及其衍生算法

    二叉树(Binary Tree)是最简单的树形数据结构,然而却十分精妙.其衍生出各种算法,以致于占据了数据结构的半壁江山.STL中大名顶顶的关联容器--集合(set).映射(map)便是使用二叉树实现 ...

  2. AC日记——二叉堆练习3 codevs 3110

    3110 二叉堆练习3  时间限制: 3 s  空间限制: 128000 KB  题目等级 : 黄金 Gold 题解       题目描述 Description 给定N(N≤500,000)和N个整 ...

  3. codevs 3110 二叉堆练习3

    3110 二叉堆练习3 http://codevs.cn/problem/3110/ 题目描述 Description 给定N(N≤500,000)和N个整数(较有序),将其排序后输出. 输入描述 I ...

  4. [LeetCode] Delete Node in a BST 删除二叉搜索树中的节点

    Given a root node reference of a BST and a key, delete the node with the given key in the BST. Retur ...

  5. [LeetCode] Serialize and Deserialize BST 二叉搜索树的序列化和去序列化

    Serialization is the process of converting a data structure or object into a sequence of bits so tha ...

  6. [LeetCode] Inorder Successor in BST 二叉搜索树中的中序后继节点

    Given a binary search tree and a node in it, find the in-order successor of that node in the BST. No ...

  7. [LeetCode] Verify Preorder Sequence in Binary Search Tree 验证二叉搜索树的先序序列

    Given an array of numbers, verify whether it is the correct preorder traversal sequence of a binary ...

  8. [LeetCode] Lowest Common Ancestor of a Binary Search Tree 二叉搜索树的最小共同父节点

    Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BS ...

  9. [LeetCode] Kth Smallest Element in a BST 二叉搜索树中的第K小的元素

    Given a binary search tree, write a function kthSmallest to find the kth smallest element in it. Not ...

随机推荐

  1. B-day5

    1.昨天的困难,今天解决的进度,以及明天要做的事情 昨天的困难:昨天虽然完成了风险数据的图表统计,但是界面风格仍然不太满意,还在抓紧调试中:还有登录页的背景图,在想应该如何设计, 什么样的风格才好. ...

  2. Flask 学习 五 电子邮件

    pip install mail from flask_mail import Mail # 邮件配置 app.config['MAIL_SERVER']='smtp.qq.com' app.conf ...

  3. Linux 磁盘和文件管理系统 文件打包解压备份 VIM、VI编辑器

  4. 如何使用ILAsm与ILDasm修改.Net exe(dll)文件

    一.背景 最近项目组新上项目,交付的时间比较急迫,原本好的分支管理习惯没有遵守好,于是出现下面状况: 多个小伙伴在不同的分支上开发. 原本QA环境也存在一个阻碍性的bug A 一位同事在QA环境发布了 ...

  5. ctf变量覆盖漏洞:

    1.变量覆盖: ①:针对extract函数的变量覆盖漏洞: <?php @error_reporting(E_ALL^E_NOTICE); require('config.php'); if($ ...

  6. 分布式系统之消息中间件rabbitmq

    分布式系统之消息中间件rabbitmq 博客分类: 感谢:  一般php 用rabbitmq  java 用activemq  http://spartan1.iteye.com/blog/11802 ...

  7. 记一次oracle crs无法重启事故

    今天在修改了数据库参数后,关闭数据库及crs,然后重新启动了服务器,服务器启动完成之后,发现数据库无法启动,过程如下: step1:重启数据库 $ su - grid $ srvctl stop da ...

  8. 深度爬取之rules

    深度爬取之rules CrawlSpider使用rules来决定爬虫的爬取规则,并将匹配后的url请求提交给引擎.所以在正常情况下,CrawlSpider不需要单独手动返回请求了. 在rules中包含 ...

  9. Leetcode:Two Sum

    原题:https://leetcode.com/problems/two-sum/ 尝试了两种方法: 方法一: var twoSum = function(nums, target) { for(va ...

  10. JavaScript 原型中的哲学思想

    学习JavaScript过程中,原型问题一直让我疑惑许久,那时候捧着那本著名的红皮书,看到有关原型的讲解时,总是心存疑虑.当在JavaScript世界中走过不少旅程之后,再次萌发起研究这部分知识的欲望 ...