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个点构成的向量) ...
随机推荐
- HTML 事件属性(如:onsubmit)
学习啥都需要一个基础 基础很重要: HTML 4 的新特性之一是可以使 HTML 事件触发浏览器中的行为,比方说当用户点击某个 HTML 元素时启动一段 JavaScript. 在现代浏览器中都内置有 ...
- 5分钟教你配置命令行界面的163邮箱client
网易163免费邮箱相关server信息: mutt 是命令行下的邮件client,它仅是管理邮件的组织编辑,邮件的发送和接收须要调用相应的程序. 这里用的各自是getmail 和 msmtp. 过程例 ...
- Percona Toolkit工具集介绍
部署mysql工具是一个非常重要的部分,所以工具的可靠性和很好的设计非常重要.percona toolkit是一个有30多个mysql工具的工具箱.兼容mysql,percona server,mar ...
- Python目录常用操作
os.path.basename(path) #取文件名 os.path.getsize(path) #取文件大小 os.path.exists(path) #文件是否存在 os.path.dirna ...
- Atitit.分布式远程调用 rpc rmi CORBA的关系
Atitit.分布式远程调用 rpc rmi CORBA的关系 1. 远程调用(包括rpc,rmi,rest)1 2. 分布式调用大体上就分为两类,RPC式的,REST式的1 3. RPC(远程 ...
- Cocoa、Foundation、UIKit、Objective-c、XCode、Interface Builder的概念
转自:http://blog.csdn.net/hou_cocoa/article/details/6187418 Cocoa 是在Mac OS X系统上原生的一个编译环境.他包含两个框架,其实就是一 ...
- makefile之include
"include"指示符告诉 make 暂停读取当前的 Makefile,而转去读取"include"指定的一个或者多个文件,完成以后再继续当前 Makefil ...
- line: 1: Syntax error: word unexpected (expecting ")")
开发板上运行可执行程序报出错误: line1: 1: Syntax error: word unexpected (expecting ")") 解决思路: 1.编译器的问题 用a ...
- SAP安装前添加虚拟网卡步骤
添加虚拟网卡: 打开控制面版中的设备管理器 点击菜单栏上的[操作(A)] 选择[添加过时硬盘件] 选择[ 安装我手动从列表选择的硬件(高级)(M) ],点击[下一步] 选择[网络适配器],点击[下一步 ...
- hadoop三大组件的简单图解
如有不对,欢迎大家指正