题目大意:

n个点,第i个点和第i+1个点可以构成向量,问最少删除多少个点可以让构成的向量顺时针旋转或者逆时针旋转。

分析:

dp很好想,dp[j][i]表示以向量ji(第j个点到第i个点构成的向量)为终点的最大顺时针/逆时针向量数。状态转移方程为 dp[j][i] = max{dp[k][j]+1}。

问题个关键是如何判断2个向量是顺时针还是逆时针。

计算几何用的知识是求叉积和点积,叉积的作用是判断两个向量的左右(顺逆),点积的作用是判断两个向量的前后。举个例子,假设有2个向量v1,v2,‘*’暂时代表叉积运算,‘·’暂时代表点积运算。叉积判定:如果v1*v2>0,则v1在v2的顺时针方向;如果v1*v2=0,则v1、v2共线;如果v1*v2<0,则v1在v2的逆时针方向。点积判定:如果v1·v2>0,则v1和v2都指向同一侧面;如果v1·v2=0,则v1和v2垂直;如果v1·v2<0,则v1和v2都指向相反的侧面。

顺时针的旋转范围是(0<=T<180),逆时针的旋转范围是(0<T<=180),也就是说如果两条向量共线的话,顺时针旋转可以同方向(T=0),不能反方向;逆时针旋转可以反方向(T=180),不能同方向。

 #include<cstdio>
#include<cstring>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<set>
#include<queue>
#include<stack>
#define MAXN 310 using namespace std;
int dp[MAXN][MAXN],n;
struct Point
{
int x,y;
Point (int x_=,int y_=):x(x_),y(y_) {}
} p[MAXN];
typedef Point Vector;
Vector operator -(Point a,Point b)
{
return Vector(a.x-b.x,a.y-b.y);
}
int Cross(Vector a,Vector b)//向量叉积
{
return a.x*b.y-a.y*b.x;
}
int Dot(Vector a,Vector b)//向量点乘
{
return a.x*b.x+a.y*b.y;
}
int if_shun(int i,int j,int k)//判断顺时针
{ Vector v1=p[i]-p[j];
Vector v2=p[j]-p[k];
int tem=Cross(v1,v2);
if(tem>)
return ;
else if(tem<)
return ;
if(tem==)
{
int tem1=Dot(v1,v2);
if(tem1<)
return ;
return ;
}
}
int if_ni(int i,int j,int k)//判断逆时针
{ Vector v1=p[i]-p[j];
Vector v2=p[j]-p[k];
int tem=Cross(v1,v2);
if(tem>)
return ;
else if(tem<)
return ;
if(tem==)
{
int tem1=Dot(v1,v2);//向量共线,判断一下方向
if(tem1<)
return ;
return ;
}
}
int puan_shun()
{
int ans=;
//dp[0][1]=1;
for(int i=; i<n; i++)
{
for(int j=; j<i; j++)
{
dp[j][i]=;
for(int k=; k<j; k++)
{
if(if_shun(i,j,k))
dp[j][i]=max(dp[j][i],dp[k][j]+);
}
ans=max(ans,dp[j][i]);
} }
return ans;
}
int puan_ni()
{
int ans=;
//dp[0][1]=1;
for(int i=; i<n; i++)
{
for(int j=; j<i; j++)
{
dp[j][i]=;
for(int k=; k<j; k++)
{
if(if_ni(i,j,k))
dp[j][i]=max(dp[j][i],dp[k][j]+);
}
ans=max(ans,dp[j][i]);
} }
return ans;
} int main()
{
while(scanf("%d",&n)!=EOF&&n)
{
for(int i=; i<n; i++)
scanf("%d %d",&p[i].x,&p[i].y);
memset(dp,,sizeof(dp));
int ans1=puan_shun();
memset(dp,,sizeof(dp));
int ans2=puan_ni();
//printf("%d %d==\n",ans1,ans2);
if(ans1==n-)
printf("C\n");
else if(ans2==n-)
printf("CC\n");
else if(ans1>=ans2)
printf("Remove %d bead(s), C\n",n-ans1-);
else
printf("Remove %d bead(s), CC\n",n-ans2-);
printf("\n");
}
return ;
}

sdut 2153 Clockwise (2010年山东省第一届ACM大学生程序设计竞赛)的更多相关文章

  1. sdut 2159 Ivan comes again!(2010年山东省第一届ACM大学生程序设计竞赛) 线段树+离散

    先看看上一个题: 题目大意是: 矩阵中有N个被标记的元素,然后针对每一个被标记的元素e(x,y),你要在所有被标记的元素中找到一个元素E(X,Y),使得X>x并且Y>y,如果存在多个满足条 ...

  2. 2010年山东省第一届ACM大学生程序设计竞赛 Balloons (BFS)

    题意 : 找联通块的个数,Saya定义两个相连是 |xa-xb| + |ya-yb| ≤ 1 ,但是Kudo定义的相连是 |xa-xb|≤1 并且 |ya-yb|≤1.输出按照两种方式数的联通块的各数 ...

  3. Hello World! 2010年山东省第一届ACM大学生程序设计竞赛

    Hello World! Time Limit: 1000MS Memory limit: 65536K 题目描述 We know that Ivan gives Saya three problem ...

  4. Phone Number 2010年山东省第一届ACM大学生程序设计竞赛

    Phone Number Time Limit: 1000MS Memory limit: 65536K 题目描述 We know that if a phone number A is anothe ...

  5. [2011山东省第二届ACM大学生程序设计竞赛]——Identifiers

    Identifiers Time Limit: 1000MS Memory limit: 65536K 题目:http://acm.sdut.edu.cn/sdutoj/problem.php?act ...

  6. sdut Mountain Subsequences 2013年山东省第四届ACM大学生程序设计竞赛

    Mountain Subsequences 题目描述 Coco is a beautiful ACMer girl living in a very beautiful mountain. There ...

  7. [2012山东省第三届ACM大学生程序设计竞赛]——n a^o7 !

    n a^o7 ! 题目:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2413 Time Lim ...

  8. angry_birds_again_and_again(2014年山东省第五届ACM大学生程序设计竞赛A题)

    http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2877 题目描述 The problems ca ...

  9. [2012山东省第三届ACM大学生程序设计竞赛]——Mine Number

    Mine Number 题目:http://acm.sdut.edu.cn/sdutoj/problem.php? action=showproblem&problemid=2410 Time ...

随机推荐

  1. Wcf Client 异常和关闭的通用处理方法

    在项目中采用wcf通讯,客户端很多地方调用服务,需要统一的处理超时和通讯异常以及关闭连接. 1.调用尝试和异常捕获 首先,项目中添加一个通用类ServiceDelegate.cs public del ...

  2. ID3

    # -*- coding: utf-8 -*- import copy from numpy import * import math class ID3DTree(object): def __in ...

  3. js基础之DOM

    一.创建子节点 发帖在顶部显示: var oBtn = document.getElementById('btn1'); var oUl = document.getElementById('ul1' ...

  4. 知名杀毒软件Mcafee(麦咖啡)个人版 资源汇总兼科普(来自卡饭)

    虽然早已不是用咖啡了,但我也实时关注的咖啡的一举一动,潜水看帖日久,发现小白众多,好多有价值的帖子淹没于帖海当中,甚是惋惜.     我有如下建议      1.咖啡区管理层,能否吧一些优秀的资源教程 ...

  5. ZOJ 3279

    线段树单点更新 //============================================================================ // Name : E.c ...

  6. Debugger Exception Notification

    --------------------------- Debugger Exception Notification --------------------------- Project PJSP ...

  7. Failed to instantiate the default view controller for UIMainStoryboardFile 'Main'

    给UITableViewController 展示数据时候 删除系统自带viewController 然后拖过来一个UITableViewController 指定class后没有指定main入口 报 ...

  8. RPI学习--wiringPi_setups

    reference: http://wiringpi.com/reference/setup/ There are four ways to initialise wiringPi. wiringPi ...

  9. switch… case 语句的用法(一)

    public class Test7 { public static void main(String[] args) { int i=5; switch(i) { case 1: System.ou ...

  10. windows下将磁盘脱机,并在"我的电脑"下显示

    方案一: .右键单击"我的电脑". 2.打开:管理-磁盘管理. 3.在右边出现的磁盘分区里,你想隐藏的分区上右键单击“更改驱动器名和路径”. 4.出现一个对话框,点击“删除”. 5 ...