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 ...
随机推荐
- python 进程复习
import os import time ret = os.fork() # 创建子线程 if ret ==0: # 子进程中返回值为0,父进程>0 while True: print('.. ...
- Flask jinja2 全局函数,宏
内置全局函数 dict()函数,方便生成字典型变量 {% set user = dict(name='Mike',age=15) %} <p>{{ user | tojson | safe ...
- caffe使用ctrl-c不能保存模型
caffe使用Ctrl-c 不能保存模型: 是因为使用的是 tee输出日志 解决方法:kill -s SIGINT <proc_id> 或者使用 GLOG_log_dir=/path/to ...
- 教你在不使用框架的情况下也能写出现代化 PHP 代码
我为你们准备了一个富有挑战性的事情.接下来你们将以 无 框架的方式开启一个项目之旅. 首先声明, 这篇并非又臭又长的反框架裹脚布文章.也不是推销 非原创 思想 .毕竟, 我们还将在接下来的开发之旅中使 ...
- Nginx配置小结
前两天区听了一堂Nginx的课,然后翻了一下自己之前的Nginx的笔记,做了一个简单的小结. 全局变量 $args : 这个变量等于请求行中的参数,同$query_string $content_le ...
- vue+mint-ui的微博页面(支持评论@添加表情等)
github地址 https://github.com/KyrieZbw/Sneakers (如果觉得不错就给个小星星) 预览地址 页面展示 技术栈 vue2 + vuex + vue-router ...
- 创建帧动画1 - xml方式
废话不多说,先看东西 创建帧动画1 - xml方式 帧动画的创建方式主要以下2种: * 用xml创建动画: * 用代码创建动画: 本文内容主要关注 xml文件 创建帧动画的方式 xml文件 ...
- http缓存浅谈
我们在访问百度首页的时候,会发现不管怎么刷新页面,静态资源基本都是返回 200(from cache): 随便点开一个静态资源是酱的: 哎哟有Response报头数据呢,看来服务器也正常返回了etag ...
- SpringCloud的EurekaClient : 客户端应用访问注册的微服务(无断路器场景)
演示客户端应用如何访问注册在EurekaServer里的微服务 一.概念和定义 采用Ribbon或Feign方式访问注册到EurekaServer中的微服务.1.Ribbon实现了客户端负载均衡,2. ...
- PyQt5--基础篇:用eric6工具实现三级联动效果
今天给大家介绍下python gui界面的三级联动效果,我们用工具eric6来实现,先看下效果图. 首先我们先创建项目linkage,再新建窗体进入到Qt设计师工具开始设计界面,完成后保存并退出. 在 ...