Poj1228 Grandpa's Estate

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Elemmir/article/details/51558848

给出了一些凸包上的点,问该凸包是否为稳定凸包。
稳定凸包即指在不删掉当前凸包上的点的情况下,无法通过加点来得到更大的凸包。这样的凸包每条边上除两端点外都一定还有点。
求出凸包顶点,判断凸包每条边上是否还有点即可。
既然那么多人都写Graham,那我就写写分治来愉悦一下吧。

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<cmath>
using namespace std;
const int maxn = 1005;
#define EPS 1e-6
#define INF 1e9
struct point {
    double x,y;
    point(){}
    point(double _x,double _y):x(_x),y(_y){}
    point operator - (const point &a) {return point(x-a.x,y-a.y);}
    bool operator != (const point &a) {return x!=a.x || y!=a.y;}
    bool operator == (const point &a) {return x==a.x && y==a.y;}
};
double multi(point a,point b) {return a.x*b.y - a.y*b.x;}
double dis(point a,point b) {point c=a-b;return sqrt(1.0*c.x*c.x+1.0*c.y*c.y);}
bool cmp(point a,point b) {return a.x < b.x || (a.x==b.x && a.y < b.y);}
point P[maxn],hull[maxn];
int N,cnt=0;
double s[maxn];
void quickhull(int L,int R,point a,point b) {
    int x = L,i=L-1,j=R+1;
    for(int k = L; k <= R; k++) if( s[k]-s[x] > EPS || ( fabs(s[x]-s[k])<EPS && cmp(P[x],P[k]))) x=k;
    point y = P[x];
    for(int k = L; k <= R; k++) {
        s[++i] = multi(a-P[k],y-P[k]);
        if( s[i] > EPS) swap(P[i],P[k]); else i--;
    }
    for(int k = R; k >= L; k--) {
        s[--j] = multi(y-P[k],b-P[k]);
        if( s[j] > EPS) swap(P[j],P[k]); else j++;
    }
    if( L <= i ) quickhull(L,i,a,y);
    hull[++cnt] = y;
    if( j <= R ) quickhull(j,R,y,b);
}
bool judge(point a,point b,point k) {
    return fabs(multi(k-a,b-a)) < EPS;
}
int main() {
    int T;
    for(scanf("%d",&T);T;T--) {
        scanf("%d",&N);
        memset(s,0,sizeof s);
        P[0] = point(INF,INF); int x = 0;
        for(int i = 1; i <= N; i++) {
            scanf("%lf%lf",&P[i].x,&P[i].y);
            if( cmp(P[i],P[x]) ) x=i;
        }
        if(N< 5) {puts("NO"); continue;}
        swap(P[1],P[x]);

        cnt=0;
        hull[++cnt] = P[1];
        quickhull(2,N,P[1],P[1]);
        hull[++cnt] = P[1];
        bool fg = 1;
        for(int i = 2; i <= cnt; i++) {
            point a = hull[i-1];
            point b = hull[i];
            bool found=0;
            for(int j = 1; j <= N; j++){
                if(P[j] == a || P[j] == b) continue;
                if(judge(a,b,P[j])) {found=1;break;}
            }
            if( !found ){ fg = 0; break;}
        }
        puts( fg ? "YES" : "NO");

    }
}
阅读更多

Grandpa's Other Estate

09-19

DescriptionnnFrom our previous contest, we know that Kamran the Believer inherited many of his grandpa抯 belongings. Apparently, his grandpa had been a mathematician in his life with interests in puzzle solving, since he has made Kamran solve another programming problem! nGrandpa had a big garden with many valuable walnut trees. He has written in his will that Kamran can inherit one piece of square shaped land of a given size in the garden, such that its sides be parallel to the x and y axes. Taking advantage of the fact that no other restrictions have been mentioned in the will, Kamran wants to choose the land in which the most number of trees lie. Kamran is too wealthy now and thus too lazy to spend time and solve another algorithmic problem. He has hired you to solve this problem for him. nYou are given the location of all trees in the big garden and the size of the land to choose. You are to write a program to find out where to choose the land so that the most number of trees lie in it. You may consider trees as points in the plane and the land as a square. You are to find the position of the square such that it includes as many points as possible. Note that the points on the border of the square are considered to be inside it. nInputnnThe first line of the input file contains a single integer t (1 <= t <= 10), the number of test cases, followed by the input data for each test case. The first line of each test case contains an integer n (1 <= n <= 100), the number of trees, and an integer r (1 <= r <= 1000), the length of the land's side, followed by n lines, each containing two integers x and y (0 <= x, y <= 100,000) representing the coordinates of a walnut tree. Note that all coordinates are pairwise distinct.nOutputnnThere should be one line per test case containing the maximum number of trees that Kamran can own.nSample Inputnn1 n3 1 n1 2 n2 1 n4 3 nSample Outputnn2

换一批

Grandpa's Rubik Cube

06-07

A very well-known toy/pastime, called Rubik's cube, consists of a cube as shown in Figure 1a, where letters stand for colors (e.g. B for blue, R for red,...). The goal of the game is to rotate the faces of the cube in such a way that at the end each face has a different color, as shown in Figure 1b. Notice that,nnnnwhen a face is rotated, the configuration of colors in all the adjacent faces changes. Figure 2 illustrates a rotation of one of the faces. Given a scrambled configuration, reaching the final position can be quite challenging, as you may know.nnnnBut your grandpa has many years of experience, and claims that, given any configuration of the Rubik cube, he can come up with a sequence of rotations leading to a winning configuration.nnIn order to show all faces of the cube we shall represent the cube as in Figure 3a. The six colors are Yellow, Red, Blue, Green, White and Magenta (represented by their first letters).nnYou will be given an initial configuration and a list of rotations. A rotation will be represented by an integer number, indicating the face to be rotated and the direction of the rotation (a positive value means clockwise rotation, negative value means counter-clockwise rotation). Faces of the cube are numbered as shown in Figure 3b. You must write a program that checks whether the list of rotations will lead to a winning configuration.nnnnnInputnnThe input contains several test cases. The first line of the input is an integer which indicates the number of tests. Each test description consists of ten lines of input. The first nine lines of a test will describe an initial configuration, in the format shown in Figure 3a. The next line will contain a list of rotations, ending with the value 0.nnnOutputnnFor each test case your program should print one line. If your grandpa is correct, print "Yes, grandpa!", otherwise print "No, you are wrong!".nnnSample Inputnn3n G Y Yn G Y Yn G Y YnW W W Y R R M M M G G BnW W W Y R R M M M G G BnW W W Y R R M M M G G Bn R B Bn R B Bn R B Bn-1 0n G Y Yn G Y Yn G Y YnW W W Y R R M M M G G BnW M W Y R R M W M G G BnW W W Y R R M M M G G Bn R B Bn R B Bn R B Bn-1 0n M W Mn W W Gn W W YnG Y Y M M B M B G W R BnB Y Y M M B M G G W R RnY M G W B B R R G R R Wn R Y Yn G B Yn R G Bn+4 +6 -2 +3 -4 +2 -3 -6 0nnnSample OutputnnYes, grandpa!nNo, you are wrong!nYes, grandpa!

Grandpa is Famous

02-23

The whole family was excited by the news. Everyone knew grandpa had been an extremely good bridge player for decades, but when it was announced he would be in the Guinness Book of World Records as the most successful bridge player ever, whow, that was astonishing!nnThe International Bridge Association (IBA) has maintained, for several years, a weekly rank? ing of the best players in the world. Considering that each appearance in a weekly ranking constitutes a point for the player, grandpa was nominated the best player ever because he got the highest number of points.nnHaving many friends who were also competing against him, grandpa is extremely curious to know which player(s) took the second place. Since the IBA rankings are now available in the internet he turned to you for help. He needs a program which, when given a list of weekly rankings, finds out which player(s) got the second place according to the number of points.nnInputnnThe input contains several test cases. Players are identified by integers from 1 to 10000. The first line of a test case contains two integers N and M indicating respectively the number of rankings available (2 <= N <= 500) and the number of players in each ranking (2 <= M <= 500). Each of the next N lines contains the description of one weekly ranking. Each description is composed by a sequence of M integers, separated by a blank space, identifying the players who figured in that weekly ranking. You can assume that:nn 1. in each test case there is exactly one best player and at least one second best player,n 2. each weekly ranking consists of M distinct player identifiers.nThe end of input is indicated by N = M = 0.nnOutputnnFor each test case in the input your program must produce one line of output, containing the identification number of the player who is second best in number of appearances in the rankings. If there is a tie for second best, print the identification numbers of all second best players in increasing order. Each identification number produced must be followed by a blank space.nnSample Inputnn4 5n20 33 25 32 99n32 86 99 25 10n20 99 10 33 86n19 33 74 99 32n3 6n2 34 67 36 79 93n100 38 21 76 91 85n32 23 85 31 88 1n0 0nSample Outputnn32 33n1 2 21 23 31 32 34 36 38 67 76 79 88 91 93 100

tomcat运行出现java.lang.UnsatisfiedLinkError: rockey.JRockey.Rockey(S[S[I[I[S[S[S[S[B)S

03-23

2009-3-23 14:23:05 org.apache.catalina.core.AprLifecycleListener initrn信息: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Java\jdk1.6.0_10\bin;E:\apache-tomcat-6.0.18\binrn2009-3-23 14:23:05 org.apache.coyote.http11.Http11Protocol initrn信息: Initializing Coyote HTTP/1.1 on http-8080rn2009-3-23 14:23:05 org.apache.catalina.startup.Catalina loadrn信息: Initialization processed in 451 msrn2009-3-23 14:23:05 org.apache.catalina.core.StandardService startrn信息: Starting service Catalinarn2009-3-23 14:23:05 org.apache.catalina.core.StandardEngine startrn信息: Starting Servlet Engine: Apache Tomcat/6.0.18rn2009-3-23 14:23:06 org.apache.catalina.core.ApplicationContext logrn信息: ContextListener: contextInitialized()rn2009-3-23 14:23:06 org.apache.catalina.core.ApplicationContext logrn信息: SessionListener: contextInitialized()rn2009-3-23 14:23:06 org.apache.catalina.loader.WebappClassLoader validateJarFilern信息: validateJarFile(E:\apache-tomcat-6.0.18\webapps\join\WEB-INF\lib\servlet.jar) - jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending class: javax/servlet/Servlet.classrnInitializing c3p0 pool... com.mchange.v2.c3p0.PoolBackedDataSource@3f4ebd [ connectionPoolDataSource -> com.mchange.v2.c3p0.WrapperConnectionPoolDataSource@10c3a08 [ acquireIncrement -> 1, acquireRetryAttempts -> 30, acquireRetryDelay -> 1000, autoCommitOnClose -> false, automaticTestTable -> null, breakAfterAcquireFailure -> false, checkoutTimeout -> 0, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, idleConnectionTestPeriod -> 300, initialPoolSize -> 1, maxIdleTime -> 5000, maxPoolSize -> 20, maxStatements -> 0, maxStatementsPerConnection -> 0, minPoolSize -> 1, nestedDataSource -> com.mchange.v2.c3p0.DriverManagerDataSource@89dd [ description -> null, driverClass -> null, factoryClassLocation -> null, jdbcUrl -> jdbc:mysql://localhost/asp?useUnicode=true&characterEncoding=gbk, properties -> user=******, password=****** ] , preferredTestQuery -> null, propertyCycle -> 300, testConnectionOnCheckin -> false, testConnectionOnCheckout -> false, usesTraditionalReflectiveProxies -> false ] , factoryClassLocation -> null, numHelperThreads -> 3, poolOwnerIdentityToken -> 3f4ebd ] rnmembers = 37rnRockey:Library Loaded Error.rnjava.lang.UnsatisfiedLinkError: rockey.JRockey.Rockey(S[S[I[I[S[S[S[S[B)Srn at rockey.JRockey.Rockey(Native Method)rn at com.aljoin.oa.core.misc.DogReader.readDog(DogReader.java:44)rn at com.aljoin.oa.core.misc.DogReader.(DogReader.java:30)rn at com.aljoin.oa.core.misc.DogReader.(DogReader.java:245)rn at com.aljoin.oa.core.version.VersionFactory.buildSystemVersion(VersionFactory.java:29)rn at com.aljoin.oa.core.misc.EnterpriseWebListener.setSystemVersion(EnterpriseWebListener.java:35)rn at com.aljoin.oa.core.misc.WebListener.contextInitialized(WebListener.java:42)rn at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3843)rn at org.apache.catalina.core.StandardContext.start(StandardContext.java:4342)rn at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)rn at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)rn at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:525)rn at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:926)rn at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:889)rn at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:492)rn at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1149)rn at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311)rn at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)rn at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)rn at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)rn at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)rn at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)rn at org.apache.catalina.core.StandardService.start(StandardService.java:516)rn at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)rn at org.apache.catalina.startup.Catalina.start(Catalina.java:578)rn at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)rn at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)rn at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)rn at java.lang.reflect.Method.invoke(Method.java:597)rn at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)rn at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)rn2009-3-23 14:23:22 org.apache.catalina.core.ApplicationContext logrn信息: QuartzInitializer: Quartz Initializer Servlet loaded, initializing Scheduler...rn2009-3-23 14:23:22 org.apache.coyote.http11.Http11Protocol startrn信息: Starting Coyote HTTP/1.1 on http-8080rn2009-3-23 14:23:22 org.apache.jk.common.ChannelSocket initrn信息: JK: ajp13 listening on /0.0.0.0:8009rn2009-3-23 14:23:22 org.apache.jk.server.JkMain startrn信息: Jk running ID=0 time=0/31 config=nullrn2009-3-23 14:23:22 org.apache.catalina.startup.Catalina startrn信息: Server startup in 16481 msrn

没有更多推荐了,返回首页