Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

再猥琐一下,double改成longlong,去掉结构体,优化到90+MS

Posted by speedcell4 at 2012-01-12 02:07:47 on Problem 2318 and last updated at 2012-01-12 02:08:32
In Reply To:再来个二分的,172MS Posted by:speedcell4 at 2012-01-12 01:49:58
#include <algorithm>
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>

#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <string>
#include <bitset>
#include <complex>
#include <memory>
#include <numeric>

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>
#include <ctype.h>
#include <locale.h>

using namespace std;

const int    inf = 0x7f7f7f7f;
const int    INF = 0x7fffffff;
const double eps = 1e-8;
const double  pi = acos(-1.0);

template<class Type> bool scanf(Type & val)
{
    char cin =getchar();
    if(cin==EOF) return false;
    else
    {
        val=0;
        while('0'>cin||cin>'9') if((cin=getchar())==EOF) return false;
        while('0'<=cin&&cin<='9')
        {
            val*=10,val+=(cin-'0');
            if((cin=getchar())==EOF) return false;
        }
        return true;
    }
}

#define _gret(a,b) ((a)-(b)>eps)
#define _less(a,b) ((b)-(a)>eps)
#define _equl(a,b) (fabs((a)-(b))<eps)
#define _sign(val) (_gret(val,0.0)?1:(_equl(val,0.0)?0:-1))

#define _lowbit(val) ((val)&(-val))
#define _max(a,b) (_gret(a,b)?(a):(b))
#define _min(a,b) (_less(a,b)?(a):(b))
#define _for(i,a,b) for(int i=(a);i<=(b);i++)
#define _clr(a,val,n) memset(a,val,sizeof(a[0])*(n))

typedef struct POINTE
{
    double x,y;
    POINTE(double _x=0,double _y=0):x(_x),y(_y){}
};
double det(double x1,double y1,double x2,double y2){return x1*y2-x2*y1;}
double cross(double x,double y,double x1,double y1,double x2,double y2)
{
    return det(x1-x,y1-y,x2-x,y2-y);
}

const int MAXN = 6000;
long long n,m,num[MAXN],X1,Y1,X2,Y2,X,Y,U[MAXN],L[MAXN],u,l;

int findToy(double X,double Y)
{
    double ans1,ans2;
    int front=0,end=n+1,i;
    do
    {
        i=(front+end)/2;
        ans1=cross(X,Y,1.0*U[i],1.0*Y1,1.0*L[i],1.0*Y2);
        ans2=cross(X,Y,1.0*U[i+1],1.0*Y1,1.0*L[i+1],1.0*Y2);
        if(!_gret(ans1*ans2,0.0)) return i;
        else if(_gret(ans1,0.0)) front=i;
        else end=i;
    }
    while(1);
}

int main()
{
    while(scanf("%I64d %I64d %I64d %I64d %I64d %I64d",&n,&m,&X1,&Y1,&X2,&Y2),n)
    {
        U[0]=X1;
        L[0]=X1;
        U[n+1]=X2;
        L[n+1]=X2;
        _for(i,1,n)
        {
            scanf("%I64d %I64d",&U[i],&L[i]);
        }
        _clr(num,0,n+1);
        _for(j,0,m-1)
        {
            scanf("%I64d %I64d",&X,&Y);
            num[findToy(1.0*X,1.0*Y)]++;
        }
        _for(i,0,n) printf("%d: %I64d\n",i,num[i]);
        printf("\n");
    }
    return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator