Codeforces 437E The Child and Polygon
http://codeforces.com/problemset/problem/437/E
题意:求一个多边形划分成三角形的方案数
思路:区间dp,每次转移只从一个方向转移(L,R连线的某一侧),能保证正确。
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<iostream>
#define ll long long
const ll Mod=;
ll f[][];
struct Point{
double x,y;
Point(){}
Point(double x0,double y0):x(x0),y(y0){}
}p[];
Point operator -(Point p1,Point p2){
return Point(p1.x-p2.x,p1.y-p2.y);
}
double operator *(Point p1,Point p2){
return p1.x*p2.y-p1.y*p2.x;
}
int read(){
int t=,f=;char ch=getchar();
while (ch<''||ch>''){if (ch=='-') f=-;ch=getchar();}
while (''<=ch&&ch<=''){t=t*+ch-'';ch=getchar();}
return t*f;
}
ll solve(int l,int r){
if (f[l][r]!=-) return f[l][r];
if (l>r) return f[l][r]=;
if (l+==r) return f[l][r]=;
f[l][r]=;
for (int i=l+;i<r;i++){
if ((p[r]-p[l])*(p[i]-p[l])<)
(f[l][r]+=(solve(l,i)*solve(i,r))%Mod)%=Mod;
}
return f[l][r];
}
int main(){
int n=read();
for (int i=;i<=n;i++) p[i].x=read(),p[i].y=read();
for (int i=;i<=n;i++)
for (int j=;j<=n;j++)
f[i][j]=-;
double res=;
p[n+]=p[];
for (int i=;i<=n;i++)
res+=p[i]*p[i+];
if (res<){
for (int i=;i<=n/;i++) std::swap(p[i],p[n-i+]);
}
printf("%lld\n",solve(,n));
}
Codeforces 437E The Child and Polygon的更多相关文章
- Codeforces 437E The Child and Polygon(间隔DP)
题目链接:Codeforces 437E The Child and Polygon 题目大意:给出一个多边形,问说有多少种切割方法.将多边形切割为多个三角形. 解题思路:首先要理解向量叉积的性质,一 ...
- Codeforces 437B The Child and Set
题目链接:Codeforces 437B The Child and Set 開始是想到了这样的情况,比方lowbit之后从大到小排序后有这么几个数,200.100,60.50.S = 210.那先选 ...
- Codeforces 437C The Child and Toy(贪心)
题目连接:Codeforces 437C The Child and Toy 贪心,每条绳子都是须要割断的,那就先割断最大值相应的那部分周围的绳子. #include <iostream> ...
- Codeforces 437A The Child and Homework
题目链接:Codeforces 437A The Child and Homework 少看了一个条件,最后被HACK掉到203名,要不然就冲到100多一点了==.. 做这个题收获最大的是英语,A t ...
- Codeforces 437D The Child and Zoo(贪心+并查集)
题目链接:Codeforces 437D The Child and Zoo 题目大意:小孩子去參观动物园,动物园分非常多个区,每一个区有若干种动物,拥有的动物种数作为该区的权值.然后有m条路,每条路 ...
- Codeforces 437D The Child and Zoo(并查集)
Codeforces 437D The Child and Zoo 题目大意: 有一张连通图,每个点有对应的值.定义从p点走向q点的其中一条路径的花费为途径点的最小值.定义f(p,q)为从点p走向点q ...
- Codeforces 437D The Child and Zoo - 树分治 - 贪心 - 并查集 - 最大生成树
Of course our child likes walking in a zoo. The zoo has n areas, that are numbered from 1 to n. The ...
- Codeforces 438D The Child and Sequence - 线段树
At the children's day, the child came to Picks's house, and messed his house up. Picks was angry at ...
- 【codeforces 755D】PolandBall and Polygon
time limit per test4 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
随机推荐
- 8.2.1.2 How MySQL Optimizes WHERE Clauses MySQL 优化WHERE 子句
8.2.1.2 How MySQL Optimizes WHERE Clauses MySQL 优化WHERE 子句 本节讨论优化用于处理WHERE子句, 例子是使用SELECT 语句,但是相同的优化 ...
- #翻译# 深入JavaScript的Unicode难题(上)
退一步说, JavaScript处理Unicode时有些怪异. 这篇文章会说明JS在Unicode上令人痛苦的部分, 然后提供解决方案, 并说明在未来的ECMAScript6中是如何改善这些问题的. ...
- HDOJ 1395 2^x mod n = 1
Problem Description Give a number n, find the minimum x(x>0) that satisfies 2^x mod n = 1. Input ...
- cf509B Painting Pebbles
B. Painting Pebbles time limit per test 1 second memory limit per test 256 megabytes input standard ...
- [LeetCode] 45. Jump Game II 解题思路
Given an array of non-negative integers, you are initially positioned at the first index of the arra ...
- HDU 4119Isabella's Message2011成都现场赛I题(字符串模拟)
Isabella's Message Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
- Linux如何创建一个新进程
2016-03-31 张超<Linux内核分析>MOOC课程http://mooc.study.163.com/course/USTC-1000029000 Linux如何创建一个新进程 ...
- Jdbc 事务
package com.j1; import java.sql.Connection; import java.sql.SQLException; import com.mysql.jdbc.Prep ...
- $(document).ready(); $().ready(); $()
$(document).ready(function(){}); $().ready(function(){}); $(function(){}), 三者效果是一样的,在文档加载完成之后执行()中的代 ...
- flv网页播放器播放失败
在IIS6.0上发布网站时,在路径正确的情况下,网页flv播放器还是无法播放flv视频的解决方法. 1.打开IIS6.0管理器,打开发布的网站,点击打开属性窗口. 2.在HTTP头选项里找到MIME类 ...