首页 > ACM题库 > HDU-杭电 > hdu 2915 Top Spinning[解题报告]hoj
2014
02-21

hdu 2915 Top Spinning[解题报告]hoj

Top Spinning

问题描述 :

Spinning tops are one of the most popular and the most traditional toys. Not only spinning them, but also making one’s own is a popular enjoyment.

One of the easiest way to make a top is to cut out a certain shape from a cardboard and pierce an axis stick through its center of mass. Professionally made tops usually have three dimensional shapes, but in this problem we consider only two dimensional ones.

Usually, tops have rotationally symmetric shapes, such as a circle, a rectangle (with 2-fold rotational symmetry) or a regular triangle (with 3-fold symmetry). Although such symmetries are useful in determining their centers of mass, they are not definitely required; an asymmetric top also spins quite well if its axis is properly pierced at the center of mass.

When a shape of a top is given as a path to cut it out from a cardboard of uniform thickness, your task is to find its center of mass to make it spin well. Also, you have to determine whether the center of mass is on the part of the cardboard cut out. If not, you cannot pierce the axis stick, of course.

Java Spicific : Submitted Java programs may not use classes implementing the interface “java.awt.Shape”. You may use them for your debugging purposes.

输入:

The input consists of multiple datasets, each of which describes a counterclockwise path on a cardboard to cut out a top. A path is indicated by a sequence of command lines, each of which specifies a line segment or an arc.

In the description of commands below, the current position is the position to start the next cut, if any. After executing the cut specified by a command, the current position is moved to the end position of the cut made.

The commands given are one of those listed below. The command name starts from the first column of a line and the command and its arguments are separated by a space. All the command arguments are integers.

start x y
Specifies the start position of a path. This command itself does not specify any cutting; it only sets the current position to be (x; y).

line x y

Specifies a linear cut along a straight line from the current position to the position (x; y), which is not identical to the current position.

arc x y r

Specifies a round cut along a circular arc. The arc starts from the current position and ends at (x; y), which is not identical to the current position. The arc has a radius of |r|.

When r is negative, the center of the circle is to the left side of the direction of this round cut; when it is positive, it is to the right side (Figure 7). The absolute value of r is greater than the half distance of the two ends of the arc. Among two arcs connecting the start and the end positions with the specified radius, the arc specified is one with its central angle less than 180 degrees.

close
Closes a path by making a linear cut to the initial start position and terminates a dataset. If the current position is already at the start position, this command simply indicates the end of a dataset.

The figure below gives an example of a command sequence and its corresponding path. Note that, in this case, the given radius -r is negative and thus the center of the arc is to the left of the arc. The arc command should be interpreted as shown in this figure and, not the other way around on the same circle.

A dataset starts with a start command and ends with a close command.

The end of the input is specified by a line with a command end.There are at most 100 commands in a dataset and at most 100 datasets are in the input.

Absolute values of all the coordinates and radii are less than or equal to 100.You may assume that the path does not cross nor touch itself. You may also assume that paths will never expand beyond edges of the cardboard, or, in other words, the cardboard is virtually
infinitely large.

输出:

The input consists of multiple datasets, each of which describes a counterclockwise path on a cardboard to cut out a top. A path is indicated by a sequence of command lines, each of which specifies a line segment or an arc.

In the description of commands below, the current position is the position to start the next cut, if any. After executing the cut specified by a command, the current position is moved to the end position of the cut made.

The commands given are one of those listed below. The command name starts from the first column of a line and the command and its arguments are separated by a space. All the command arguments are integers.

start x y
Specifies the start position of a path. This command itself does not specify any cutting; it only sets the current position to be (x; y).

line x y

Specifies a linear cut along a straight line from the current position to the position (x; y), which is not identical to the current position.

arc x y r

Specifies a round cut along a circular arc. The arc starts from the current position and ends at (x; y), which is not identical to the current position. The arc has a radius of |r|.

When r is negative, the center of the circle is to the left side of the direction of this round cut; when it is positive, it is to the right side (Figure 7). The absolute value of r is greater than the half distance of the two ends of the arc. Among two arcs connecting the start and the end positions with the specified radius, the arc specified is one with its central angle less than 180 degrees.

close
Closes a path by making a linear cut to the initial start position and terminates a dataset. If the current position is already at the start position, this command simply indicates the end of a dataset.

The figure below gives an example of a command sequence and its corresponding path. Note that, in this case, the given radius -r is negative and thus the center of the arc is to the left of the arc. The arc command should be interpreted as shown in this figure and, not the other way around on the same circle.

A dataset starts with a start command and ends with a close command.

The end of the input is specified by a line with a command end.There are at most 100 commands in a dataset and at most 100 datasets are in the input.

Absolute values of all the coordinates and radii are less than or equal to 100.You may assume that the path does not cross nor touch itself. You may also assume that paths will never expand beyond edges of the cardboard, or, in other words, the cardboard is virtually
infinitely large.

样例输入:

start 0 0
arc 2 2 -2
line 2 5
arc 0 3 -2
close
start -1 1
line 2 1
line 2 2
line -2 2
arc -3 1 -1
line -3 -2
arc -2 -3 -1
line 2 -3
line 2 -2
line -1 -2
line -1 -1
arc -1 0 2
close
start 0 0
line 3 0
line 5 -1
arc 4 -2 -1
line 6 -2
line 6 1
line 7 3
arc 8 2 -1
line 8 4
line 5 4
line 3 5
arc 4 6 -1
line 2 6
line 2 3
line 1 1
arc 0 2 -1
close
end

样例输出:

1.00000 2.50000 +
-1.01522 -0.50000 -
4.00000 2.00000 +
HINT

//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<sstream>
#include<cmath>
#include<climits>
#include<string>
#include<map>
#include<queue>
#include<vector>
#include<stack>
#include<set>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb(a) push_back(a)
#define INF 0x1f1f1f1f
#define lson idx<<1,l,mid
#define rson idx<<1|1,mid+1,r
#define PI  3.1415926535898
template<class T> T min(const T& a,const T& b,const T& c) {
    return min(min(a,b),min(a,c));
}
template<class T> T max(const T& a,const T& b,const T& c) {
    return max(max(a,b),max(a,c));
}
void debug() {
#ifdef ONLINE_JUDGE
#else

    freopen("d:\\in.txt","r",stdin);
    freopen("d:\\out1.txt","w",stdout);
#endif
}
int getch() {
    int ch;
    while((ch=getchar())!=EOF) {
        if(ch!=' '&&ch!='\n')return ch;
    }
    return EOF;
}

vector<int>  g[2000];
int dp[2000][2];
int f(int idx,int flag,int fa)
{
    if(dp[idx][flag]>=0)return dp[idx][flag];
    int a=1;
    for(int i=0;i<g[idx].size();i++)
    {
        int v=g[idx][i];
        if(v!=fa)
            a+=f(v,1,idx);
    }
    if(fa==-1||flag==1)
    {
        int x=0;
        for(int i=0;i<g[idx].size();i++)
        {
            int v=g[idx][i];
            if(v!=fa)
                x+=f(v,0,idx);
        }
        a=min(a,x);
    }
    return dp[idx][flag]=a;
}
int main()
{
    int n;
    while(scanf("%d",&n)!=EOF)
    {
        for(int i=0;i<n;i++)
            g[i].clear();
        for(int i=1;i<=n;i++)
        {
            int u,k;
            scanf(" %d:(%d)",&u,&k);
            for(int j=1;j<=k;j++)
            {
                int v;
                scanf("%d",&v);
                g[u].pb(v);
                g[v].pb(u);
            }
        }
        memset(dp,-1,sizeof(dp));
        int num=f(0,1,-1);
        printf("%d\n",num);
    }
    return 0;
}

  1. 题本身没错,但是HDOJ放题目的时候,前面有个题目解释了什么是XXX定律。
    这里直接放了这个题目,肯定没几个人明白是干啥

  2. /*
    * =====================================================================================
    *
    * Filename: 1366.cc
    *
    * Description:
    *
    * Version: 1.0
    * Created: 2014年01月06日 14时52分14秒
    * Revision: none
    * Compiler: gcc
    *
    * Author: Wenxian Ni (Hello World~), [email protected]
    * Organization: AMS/ICT
    *
    * =====================================================================================
    */

    #include
    #include

    using namespace std;

    int main()
    {
    stack st;
    int n,i,j;
    int test;
    int a[100001];
    int b[100001];
    while(cin>>n)
    {
    for(i=1;i>a[i];
    for(i=1;i>b[i];
    //st.clear();
    while(!st.empty())
    st.pop();
    i = 1;
    j = 1;

    while(in)
    break;
    }
    while(!st.empty()&&st.top()==b[j])
    {
    st.pop();
    j++;
    }
    }
    if(st.empty())
    cout<<"YES"<<endl;
    else
    cout<<"NO"<<endl;
    }
    return 0;
    }