sdut 2153:Clockwise(第一届山东省省赛原题,计算几何+DP)
Clockwise
Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^
题目描述
Saya have a long necklace with N beads, and she signs the beads from 1 to N. Then she fixes them to the wall to show N-1 vectors – vector i starts from bead i and end up with bead i+1.
One day, Kudo comes to Saya’s home, and she sees the beads on the wall. Kudo says it is not beautiful, and let Saya make it better.
She says: “I think it will be better if it is clockwise rotation. It means that to any vector i (i < N-1), it will have the same direction with vector i+1 after clockwise rotate T degrees, while 0≤T<180.”
It is hard for Saya to reset the beads’ places, so she can only remove some beads. To saving the beads, although she agrees with Kudo’s suggestion, she thinks counterclockwise rotation is also acceptable. A counterclockwise rotation means to any vector i (i < N-1), it will have the same direction with vector i+1 after counterclockwise rotate T degrees, while 0 < T ≤ 180.”
Saya starts to compute at least how many beads she should remove to make a clockwise rotation or a counterclockwise rotation.
Since the necklace is very-very long, can you help her to solve this problem?
输入
The first line of input in each test case contains one integer N (2<N≤300), which represents the number of beads.
Each of the next N lines contains two integer x and y, represents the coordinate of the beads. You can assume that 0<x,y<10000.
The last case is followed by a line containing one zero.
输出
If it is clockwise rotation without removing any beads, please print “C; otherwise if it is counterclockwise rotation without removing any beads, print “CC” instead; otherwise, suppose remove at least x beads to make a clockwise rotation and remove at least y beads to make a counterclockwise rotation. If x≤y, print “Remove x bead(s), C”, otherwise print “Removey bead(s), CC” instead.
Your output format should imitate the sample output. Print a blank line after each test case.
示例输入
3
1 1
2 2
3 3 3
1 1
2 2
1 1 4
1 1
2 2
3 3
2 2 0
示例输出
C
CC
Remove 1 bead(s), C
提示
来源

#include <iostream>
#include <cmath>
#include <string.h>
using namespace std;
#define eps 1e-10
int dp[][];
/********** 定义点 **********/
struct Point{
double x,y;
Point(double x=,double y=):x(x),y(y) {}
};
Point p[];
/********** 定义向量 **********/
typedef Point Vector;
/********** 点 - 点 = 向量 **********/
Vector operator - (Point a,Point b)
{
return Vector(a.x-b.x,a.y-b.y);
}
/********** 2向量求叉积 **********/
double Cross(Vector a,Vector b)
{
return a.x*b.y-b.x*a.y;
}
/********** 向量点积 **********/
double Dot(Vector a,Vector b)
{
return a.x*b.x+a.y*b.y;
}
bool check1(int i,int j,int k) //核对向量ji是否在向量kj的顺时针方向或者同方向
{
if(k==) return true;
Vector v1 = p[i]-p[j]; //向量ji
Vector v2 = p[j]-p[k]; //向量kj
double x = Cross(v1,v2);
if(fabs(x)<eps){ //向量ji和kj共线,判断一下两向量方向。
double d = Dot(v1,v2);
if(d>eps) //顺时针可以有同方向(0≤T<180)
return true;
else //反方向
return false;
}
else if(x>eps){ //向量ji在向量kj的顺时针方向
return true;
}
return false;
}
bool check2(int i,int j,int k)
{
if(k==) return true;
Vector v1 = p[i]-p[j]; //向量ji
Vector v2 = p[j]-p[k]; //向量kj
double x = Cross(v1,v2);
if(fabs(x)<eps){ //向量ji和kj共线,判断一下两向量方向
double d = Dot(v1,v2);
if(d>eps) //同方向
return false;
else //逆时针可以有反方向(0 < T ≤ 180)
return true;
}
else if(x<eps){ //向量ji在向量kj的逆时针方向
return true;
}
return false;
}
int main()
{
int n;
while(cin>>n){
if(n==) break;
//dp[j][i]表示以向量ji(第j个点到第i个点构成的向量)为终点的最大顺时针向量数
int i,j,k;
for(i=;i<=n;i++) //输入n个点
cin>>p[i].x>>p[i].y;
int r1=,r2=; //最大向量数
//dp
memset(dp,,sizeof(dp));
for(i=;j<=n;i++)
for(j=;j<i;j++){
int Max = ;
for(k=;k<i;k++){
if(check1(i,j,k)){
if(dp[k][j]+>Max)
Max = dp[k][j]+;
}
}
dp[j][i]=Max;
if(dp[j][i]>r1)
r1 = dp[j][i];
}
memset(dp,,sizeof(dp));
for(i=;j<=n;i++)
for(j=;j<i;j++){
int Max = ;
for(k=;k<i;k++){
if(check2(i,j,k)){
if(dp[k][j]+>Max)
Max = dp[k][j]+;
}
}
dp[j][i]=Max;
if(dp[j][i]>r2)
r2 = dp[j][i];
}
if(r1==n-) //向量数比点数少一个
cout<<"C"<<endl;
else if(r2==n-)
cout<<"CC"<<endl;
else if(r1>=r2)
cout<<"Remove "<<n--r1<<" bead(s), C"<<endl;
else
cout<<"Remove "<<n--r2<<" bead(s), CC"<<endl;
cout<<endl;
}
return ;
}
Freecode : www.cnblogs.com/yym2013
sdut 2153:Clockwise(第一届山东省省赛原题,计算几何+DP)的更多相关文章
- sdut 2159:Ivan comes again!(第一届山东省省赛原题,STL之set使用)
Ivan comes again! Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 The Fairy Ivan gave Say ...
- sdut 2152:Balloons(第一届山东省省赛原题,DFS搜索)
Balloons Time Limit: 1000MS Memory limit: 65536K 题目描述 Both Saya and Kudo like balloons. One day, the ...
- sdut 2154:Shopping(第一届山东省省赛原题,水题)
Shopping Time Limit: 1000MS Memory limit: 65536K 题目描述 Saya and Kudo go shopping together.You can ass ...
- sdut 2158:Hello World!(第一届山东省省赛原题,水题,穷举)
Hello World! Time Limit: 1000MS Memory limit: 65536K 题目描述 We know that Ivan gives Saya three problem ...
- sdut 2162:The Android University ACM Team Selection Contest(第二届山东省省赛原题,模拟题)
The Android University ACM Team Selection Contest Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里 ...
- sdut 2163:Identifiers(第二届山东省省赛原题,水题)
Identifiers Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 Identifier is an important c ...
- sdut 2165:Crack Mathmen(第二届山东省省赛原题,数论)
Crack Mathmen Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 Since mathmen take securit ...
- Rectangles(第七届ACM省赛原题+最长上升子序列)
题目链接: http://acm.nyist.edu.cn/JudgeOnline/problem.php?pid=1255 描述 Given N (4 <= N <= 100) rec ...
- sdut 2153 Clockwise (2010年山东省第一届ACM大学生程序设计竞赛)
题目大意: n个点,第i个点和第i+1个点可以构成向量,问最少删除多少个点可以让构成的向量顺时针旋转或者逆时针旋转. 分析: dp很好想,dp[j][i]表示以向量ji(第j个点到第i个点构成的向量) ...
随机推荐
- Asp.Net MVC4开发二: Entity Framework在Asp.Net MVC4中的应用
ORM作为一种数据库訪问机制已广泛地应用于各种项目其中,在.Net开发中,应用比較广泛的ORM框架大致有以下几个: 官方支持的有:Linq to SQL.Entity Framework.三方的有:N ...
- IOS+openCV在Xcode的入门开发(转)
看这篇文章之前先看看这个地址:OpenCV iOS开发(一)——安装 昨天折腾了一天,终于搞定了openCV+IOS在Xcode下的环境并且实现一个基于霍夫算法的圆形识别程序.废话不多说,下面就是具体 ...
- laravel使用的模板引擎 blade
使用blade引擎的话必须在控制器中使用use Blade
- LeetCode 155 Min Stack(最小栈)
翻译 设计支持push.pop.top和在常量时间内检索最小元素的栈. push(x) -- 推送元素X进栈 pop() -- 移除栈顶元素 top() -- 得到栈顶元素 getMin() -- 检 ...
- layui更新表格单元格数据口,更新单元格的内容
//监听工具条 table.on('tool(edit)', function(obj){ var data = obj.data; if(obj.event === 'getinvitation') ...
- php检测iis环境是否支持htaccess
php检测iis环境是否支持htaccess的方法. modrewrite.php <?php echo "mod_rewrite works"; ?> open_me ...
- MySQL慢查询查找和调优测试
MySQL慢查询查找和调优测试,接下来详细介绍,需要了解的朋友可以参考下.本文参考自:http://www.jbxue.com/db/4376.html 编辑 my.cnf或者my.ini文件,去除 ...
- atitit.html5 vs 原生 app的区别与选择
atitit.html5 vs 原生 app的区别与选择 1. html5的优点 1 1.1. 最大优势::在跨平台(ios苹果,android安卓等) 1 1.2. 开放性 1 1.3. 快速的更 ...
- Delphi记录record中的变体
program Day4; {$APPTYPE CONSOLE} uses SysUtils, Util in 'Util.pas'; type TPerson = packed record ID ...
- Struts2初学 Struts.xml详解二
A.使用继承实现设置全局视图 package节点中还可以设置全局的视图,如: <global-results> <result name="e ...