HDU2108和HDU2036(叉乘)
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(叉乘)的更多相关文章
- [数据结构]——二叉树(Binary Tree)、二叉搜索树(Binary Search Tree)及其衍生算法
二叉树(Binary Tree)是最简单的树形数据结构,然而却十分精妙.其衍生出各种算法,以致于占据了数据结构的半壁江山.STL中大名顶顶的关联容器--集合(set).映射(map)便是使用二叉树实现 ...
- AC日记——二叉堆练习3 codevs 3110
3110 二叉堆练习3 时间限制: 3 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题解 题目描述 Description 给定N(N≤500,000)和N个整 ...
- codevs 3110 二叉堆练习3
3110 二叉堆练习3 http://codevs.cn/problem/3110/ 题目描述 Description 给定N(N≤500,000)和N个整数(较有序),将其排序后输出. 输入描述 I ...
- [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 ...
- [LeetCode] Serialize and Deserialize BST 二叉搜索树的序列化和去序列化
Serialization is the process of converting a data structure or object into a sequence of bits so tha ...
- [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 ...
- [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 ...
- [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 ...
- [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 ...
随机推荐
- 简单的C语言编译器--词法分析器
1. 定义词法单元Tag 首先要将可能出现的词进行分类,可以有不同的分类方式.如多符一类:将所有逗号.分号.括号等都归为一类,或者一符一类,将一个符号归为一类.我这里采用的是一符一类的方式.C代码 ...
- mvc架构模式概念
MVC模式是"Model-View-Controller"的缩写,中文翻译为"模式-视图-控制器".MVC应用程序总是由这三个部分组成.Event(事件)导致C ...
- 小草手把手教你 LabVIEW 串口仪器控制——VISA 串口配置
建议大家按我发帖子的顺序来看,方便大家理解.请不要跳跃式的阅读.很多人现在看书,都跳跃式的看,选择性的看,导致有些细节的部分没有掌握到,然后又因为某个细节耽误很多时间.以上只是个人建议,高手可以略过本 ...
- 个人技术博客(alpha)
APP的权限校验不同于web网页端,web一般使用session记录用户的状态信息,而app则使用token令牌来记录用户信息.有这样一个场景,系统的数据量达到千万级,需要几台服务器部署,当一个用户在 ...
- 前端面试题:JS中的let和var的区别
最近很多前端的朋友去面试被问到let和var的区别,其实阮一峰老师的ES6中已经很详细介绍了let的用法和var的区别.我简单总结一下,以便各位以后面试中使用. ES6 新增了let命令,用来声明局部 ...
- thinkphp中的常见静态常亮
thinkphp __PUBLIC__的定义 __ROOT__等常量的定义 1 2 3 4 5 6 7 8 9 '__TMPL__' => APP_TMPL_PATH, // 项目 ...
- 读论文系列:Object Detection ECCV2016 SSD
转载请注明作者:梦里茶 Single Shot MultiBox Detector Introduction 一句话概括:SSD就是关于类别的多尺度RPN网络 基本思路: 基础网络后接多层featur ...
- SpringBoot项目如何进行打包部署
springboot的打包方式有很多种.有打成war的,有打成jar的,也有直接提交到github,通过jekins进行打包部署的.这里主要介绍如何打成jar进行部署.不推荐用war,因为spring ...
- Mybatis入门程序
作为一个java的学习者,我相信JDBC是大家最早接触也是入门级别的数据库连接方式,所以我们先来回忆一下JDBC作为一种用于执行SQL语句的Java API是如何工作的.下面的一段代码就是最基本的JD ...
- API验证及AES加密
API验证 API验证: a. 发令牌: 静态 PS: 隐患 key被别人获取 b. 动态令牌 PS: (问题越严重)用户生成的每个令牌被黑客获取到,都会破解 c. 高级版本 PS: 黑客网速快,会窃 ...