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个点构成的向量) ...
随机推荐
- MSS & MTU
- Git高速入门——Git安装、创建版本号库以及经常使用命令
学习Git最全面的资料,在我看来是这本书--Pro Git,网上关于Git的教程有非常多,包含当中一些非常优秀的教程.这一系列的博客,主要是记录自己学习Git的经历.以及在这一过程中遇到的一些问题. ...
- linux内核学习推荐书籍
<UNIX环境高级编程>,推荐指数:★★★★★ <UNIX环境高级编程>是 Unix/ Linux 程序员案头必备的一本书籍.可以说,Linux 程序员如果没有读过这本书,就好 ...
- 【linux】FTP添加用户,设置权限和目录
一.目的,新建一个用户 test2,登录ftp,它只有自己的主目录权限,其他同级和上级目录没有权限 二.ftp安装.配置 yum -y install vsftpd //通过yum来安装vsftpd ...
- sms_queue 短信队列
git地址:https://github.com/Filix/sms_queue 简介 通过队列的方式发送短信,暂时实现了redis作为队列. 以实现的第三方短信服务: 百悟.漫道. 发送短信方,只需 ...
- git eclipse 不标记修改后的文件(没有图标标明)
在使用Eclipse做开发的时候,已经修改了某个文件,但是文件的图标没有明显的标示,如图: 解决上面问题的办法如下:
- Redis总结(一)Redis安装(转载)
最近项目中需要使用Redis,刚好这两天有时间,便总结记录一下Redis的安装,以及如何在.NET中使用Redis. Redis是一个用的比较广泛的Key/Value的内存数据库.目前新浪微博.Git ...
- EMQ 注意事项
ClientID 唯一:否则后连接的会将前面的踢下去 发送的消息内容太长(payload),导致客户端断线,原因是EMQ默认的消息长度是64K(65536字节),一旦超过就会出问题.可能出现场景: 日 ...
- Oracle 客户端注册表字符集修改-----解决乱码 .
本地ORACLE连接创建好后,默认是GBK的字符集,如果连接服务器不是同样的GBK字符集就会出现中文乱码的问题,这种情况我们需要修改本地的字符集来和服务器匹配. 通过注册表修改 HKEY_LOCA ...
- hdu 4779 Tower Defense (思维+组合数学)
Tower Defense Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 132768/132768 K (Java/Others) ...