山东省第一届ACM省赛 C SDUT 2153 Clockwise

13 篇文章 0 订阅
4 篇文章 0 订阅

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 input consists of several test cases.
The first line of input in each test case contains one integer N (2<N300), 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.

输出

  For each case, print your answer with the following format:
 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 xy, print “Remove x bead(s), C”, otherwise print “Remove y bead(s), CC” instead.
Your output format should imitate the sample output. Print a blank line after each test case.

示例输入

31 12 23 331 12 21 141 12 23 32 20

示例输出

CCCRemove 1 bead(s), C

#include <bits/stdc++.h>
#define LL long long
#define eps 1e-10
using namespace std;

class Point
{
public:
    double x, y;
    Point(double x = 0, double y = 0):x(x),y(y) {}
};
Point p[310];
int dp[310][310];
Point operator - (Point a, Point b)
{
    return Point(a.x-b.x, a.y-b.y);
}
double Cross(Point a, Point b)
{
    return a.x*b.y-b.x*a.y;
}
double Dot(Point a, Point b)
{
    return a.x* b.x + a.y * b.y;
}

bool Check(int i, int j, int k, bool f)
{
    if(!k) return true;
    Point v1 = p[i] - p[j];
    Point v2 = p[j] - p[k];
    double x = Cross(v1, v2);
    if(fabs(x) < eps)
    {
        double d = Dot(v1,v2);
        if(d > eps) return f;
        return !f;
    }
    else if(x > eps) return f;
    return !f;
}

int main()
{
    int n;
    while(~scanf("%d",&n) && n)
    {
        for(int i=1; i<=n; i++)
        {
            scanf("%lf %lf", &p[i].x, &p[i].y);
        }
        int ans1 = 0;
        int ans2 = 0;
        memset(dp, 0, sizeof(dp));
        for(int i=2; i<=n; i++)
        {
            for(int j=1; j<i; j++)
            {
                int MAX = 0;
                for(int k=0; k<i; k++)
                    if(Check(i, j, k, true)) MAX = max(MAX, dp[k][j]+1);
                dp[j][i] = MAX;
                ans1 = max(dp[j][i],ans1);
            }
        }

        memset(dp, 0, sizeof(dp));
        for(int i=2; i<=n; i++)
        {
            for(int j=1; j<i; j++)
            {
                int MAX = 0;
                for(int k=0; k<i; k++)
                    if(Check(i, j, k, false)) MAX = max(MAX, dp[k][j]+1);
                dp[j][i] = MAX;
                ans2 = max(dp[j][i], ans2);
            }
        }
        if(ans1 == n-1)
            printf("C\n");
        else if(ans2 == n-1)
            printf("CC\n");
        else if(ans1 >= ans2)
            printf("Remove %d bead(s), C\n", n-1-ans1);
        else
            printf("Remove %d bead(s), CC\n", n-1-ans2);
        printf("\n");
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值