hznu 1437: Clockwise(隐藏的暴力水题,数学)

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 0T<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 vectori+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 x 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

http://hsacm.cn/JudgeOnline/problem.php?id=1437

咋一看这道题目以为是几何难题,其实很水的。。。

题意:给出n个点的坐标,相邻的点组成一条向量,从i指向i+1,问最少删掉几个点可以使剩下点组成的向量都指向顺时针或都指向逆时针。

#include<iostream>  
#include<algorithm>  
#include<string>  
#include<string.h>  
#include<set>  
#include<vector>  
#include<cmath>  
#include<cstdlib>  
#include<cstdio>  
#define ll long long  
using namespace std;
int n;  
struct node{
    int a,b;
};
node x[301];
int y[301][301]; 
int isok(int i,int j,int k){
    int x1=x[i].a-x[j].a;
    int y1=x[i].b-x[j].b;
    int x2=x[j].a-x[k].a;
    int y2=x[j].b-x[k].b;
    if(x1*y2==x2*y1){    //两条向量共线要特殊判断(同向和反向)
        if (min(x1,x2)<=0&&max(x1,x2)>=0&&min(y1,y2)<=0&&max(y1,y2)>=0)  
            return 0;
        else
            return 1;
    }
    if (x1*y2-x2*y1>0)  //1在2的右边
        return true;  
    return false;       //1在2的左边
} 
int main(){
    while(scanf("%d",&n)&&n!=0){
        for(int i=0;i<n;++i){
            scanf("%d %d",&x[i].a,&x[i].b);
        }
        int s1=0,s2=0;
        memset(y,0,sizeof(y));
        for(int i=0;i<n;++i){
            for(int j=0;j<i;++j)
                y[j][i]=1;
        }
        for(int i=0;i<n;++i){  //枚举i+1
            for(int j=0;j<i;++j){  //枚举 i
                for(int k=0;k<j;++k){  //枚举i-1
                    if(isok(i,j,k))  //顺时针
                        y[j][i]=max(y[j][i],y[k][j]+1);
                    if(y[j][i]>s1)
                        s1=y[j][i];
                }
            }
        }
        memset(y,0,sizeof(y));
        for(int i=0;i<n;++i){
            for(int j=0;j<i;++j)
                y[j][i]=1;
        }
        for(int i=0;i<n;++i){
            for(int j=0;j<i;++j){
                for(int k=0;k<j;++k){
                    if(!isok(i,j,k))  //逆时针
                        y[j][i]=max(y[j][i],y[k][j]+1);
                    if(y[j][i]>s2)
                        s2=y[j][i];
                }
            }
        }
        if(s1==n-1)
            printf("C\n");
        else if(s2==n-1)
            printf("CC\n");  
        else{
            if(s1>=s2)
                printf("Remove %d bead(s), C\n",n-1-s1);  
            else
                printf("Remove %d bead(s), CC\n",n-1-s2);  
        }  
        printf("\n");
    }
    return 0;
}

你可能感兴趣的:(hznu 1437: Clockwise(隐藏的暴力水题,数学))