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.算法是用来解决问题的方法与步骤. 2.计算机擅长重复,常用枚举的方法 ...
- 在linux中关闭防火墙
1) 重启后生效 开启: chkconfig iptables on 关闭: chkconfig iptables off 2) 即时生效,重启后失效 开启: service iptables sta ...
- AWS中的Internet 网关
nternet 网关是一种横向扩展.支持冗余且高度可用的 VPC 组件,可实现 VPC 中的实例与 Internet 之间的通信.因此它不会对网络流量造成可用性风险或带宽限制. Internet 网关 ...
- Android Notification setLatestEventInfo方法已废弃
代替setLatestEventInfo的方法是用Notification.Builder创建Builder对象,通过该对象设置Notification相关属性. otification.Builde ...
- php_类的定义
此文章为原创见解,例子各方面也是东拼西凑.如果有错请留言.谢谢 在面向对象的思维中提出了两个概念,类和对象. 类是对某一类实物的抽象描述,而对象用于表示现实中该类事物的个体, 例子:老虎是父类,东北虎 ...
- Golang学习--平滑重启
在上一篇博客介绍TOML配置的时候,讲到了通过信号通知重载配置.我们在这一篇中介绍下如何的平滑重启server. 与重载配置相同的是我们也需要通过信号来通知server重启,但关键在于平滑重启,如果只 ...
- You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'like '%逸%'' at line 1
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mapper PUBLIC "-/ ...
- LDAP apacheds解决方案
Apache DS 配置与管理 LADP基本介绍 LDAP(轻量级目录访问协议)以目录的形式来管理资源(域用户,用户组,地址簿,邮件用户,打印机等等). 特点: 1. LDAP是一种网略协议而 ...
- 新概念英语(1-47)A cup of coffee
新概念英语(1-47)A cup of coffee How does Ann like her coffee? A:Do you like coffee, Ann? B:Yes, I do. A:D ...
- Linux实战案例(7)安装jdk
一.文件准备 1.1 文件名称 jdk-8u121-linux-x64.tar.gz 1.2 下载地址 http://www.oracle.com/technetwork/java/javase/do ...