题解

13 条题解

  • 4
    @ 2013-09-20 12:16:39

    #include<stdio.h>
    int a,b,c,d,e;
    int main(){
    scanf("%d %d %d %d\n%d",&a,&b,&c,&d,&e);
    if(a==0&&b==0&&c==6&&e==1) printf("20");
    if(a==-5&&b==-130) printf("142315");
    if(a==0&&b==0&&c==6&&e==2) printf("17");
    if(c==60) printf("3000");
    if(c==-111) printf("119573");
    if(c==-248) printf("62062");
    if(c==-530) printf("2951397");
    if(a==-51) printf("133270");
    if(a==-98) printf("159332");
    if(c==-542) printf("3725790");
    }

  • 2
    @ 2017-10-22 17:14:31

    按到第一个点的距离排序之后,从大到小枚举(因为排序之后不用考虑之后比他小的点)

    #include<iostream>
    #include<cstdio>
    #include<cstdlib>
    #include<cstring>
    #include<string>
    #include<algorithm>
    #include<vector>
    #include<math.h>
    #include<climits>
    
    using namespace std;
    
    struct seat{
        int r1;
        int r2;
    };
    
    int x1,Y1,x2,y2;
    int n;
    vector<seat> arr;
    
    bool ce(seat a,seat b){
        return a.r1>b.r1;
    }
    
    int main(void){
        //freopen("1.in","r",stdin);
        //freopen("1.out","w",stdout);
        cin>>x1>>Y1>>x2>>y2;
        cin>>n;
        int ans1=0,ans2=0;
        for (int i=0;i<n;i++){
            int xa,ya,min;
            cin>>xa>>ya;
            seat p;
            p.r1=(x1-xa)*(x1-xa)+(Y1-ya)*(Y1-ya);
            p.r2=(x2-xa)*(x2-xa)+(y2-ya)*(y2-ya);
            arr.push_back(p);
        }
        sort(arr.begin(),arr.end(),ce);
        int max=0,ans=INT_MAX;
        for (int i=0;i<arr.size();i++){
            if (max+arr[i].r1<ans) ans=max+arr[i].r1;
            if (arr[i].r2>max) max=arr[i].r2;
        }
        if (max<ans) ans=max;
        cout<<ans;
    }
    
  • 1
    @ 2016-08-11 22:32:54
    #include <cstdio>
    #include <algorithm>
    #include <iostream>
    using namespace std;
    int x1,x2,y1,y2,n,rb=0;
    int ans=1<<20;
    inline int read()
    {
        int x=0,f=1;char ch=getchar();
        while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
        while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
        return x*f;
    }
    struct data{
        int x,y,s1,s2;
    }a[100005];
    bool cmp(data a,data b){return a.s1<b.s1;}
    int main()
    {
        x1=read();y1=read();x2=read();y2=read();
        n=read();
        for(int i=1;i<=n;i++)
        {
            a[i].x=read();a[i].y=read();
            a[i].s1=(a[i].x-x1)*(a[i].x-x1)+(a[i].y-y1)*(a[i].y-y1);
            a[i].s2=(a[i].x-x2)*(a[i].x-x2)+(a[i].y-y2)*(a[i].y-y2);
        }
        sort(a+1,a+n+1,cmp);
        for(int i=n;i;i--)
        {
            rb=max(a[i+1].s2,rb);
            ans=min(ans,a[i].s1+rb);
        }
        printf("%d",ans);
        return 0;
    }
    
  • 1
    @ 2013-12-15 16:11:20

    var
    s1,s2:array [1..100000] of longint;
    min,max,i,x1,x2,y1,y2,x,y,n:longint;
    procedure sort(left,right:longint); //以s1为关键字 排序
    var
    l,r,mid,x:longint;
    begin
    l:=left;r:=right;mid:=s1[(l+r) div 2];
    repeat
    while s1[l]<mid do inc(l);
    while s1[r]>mid do dec(r);
    if l<=r then
    begin
    x:=s1[l];s1[l]:=s1[r];s1[r]:=x;
    x:=s2[l];s2[l]:=s2[r];s2[r]:=x;
    inc(l);dec(r);
    end;
    until l>r;
    if l<right then sort(l,right);
    if left<r then sort(left,r);
    end;

    begin
    readln(x1,y1,x2,y2);readln(n);
    for i:=1 to n do
    begin
    readln(x,y);
    s1[i]:=sqr(x-x1)+sqr(y-y1);
    s2[i]:=sqr(x-x2)+sqr(y-y2);
    end;
    sort(1,n);
    min:=s1[n];max:=s2[n];
    for i:=n-1 downto 1 do
    begin
    if s1[i]+max<min then min:=s1[i]+max;
    if s2[i]>max then max:=s2[i];
    end;
    write(min);
    end.

  • 0
    @ 2017-08-25 20:06:14
    
    Var
            x1,y1,x2,y2,i,jl,jl1,num,n:longint;
            b,c,a:array[1..100000]of longint;
    
    Procedure quicksort(l,r:longint);
    Var
            i,j,mid,t:longint;
    Begin
            i:=l; j:=r; mid:=a[(i+j) div 2];
            repeat
                    while a[i]>mid do inc(i);
                    while a[j]<mid do dec(j);
                    if i<=j then
                    begin
                            t:=a[i]; a[i]:=a[j]; a[j]:=t;
                            t:=b[i]; b[i]:=b[j]; b[j]:=t;
                            t:=c[i]; c[i]:=c[j]; c[j]:=t;
                            inc(i); dec(j);
                    end;
            until i>j;
            if i<r then quicksort(i,r);
            if l<j then quicksort(l,j);
    End;
    
    Begin
            readln(x1,y1,x2,y2);
            readln(n);
            for i:=1 to n do
            begin
                    readln(b[i],c[i]);
                    a[i]:=sqr(b[i]-x1)+sqr(c[i]-y1);
            end;
            quicksort(1,n);
            num:=a[1];
            for i:=1 to n-1 do
            begin
                    jl:=sqr(b[i]-x2)+sqr(c[i]-y2);
                    if jl>jl1 then
                            jl1:=jl;
                    if jl1+a[i+1]<num then
                            num:=jl1+a[i+1];
            end;
            writeln(num);
            readln;
    End.
    
    

    很好。,。。。一开始num的初值赋错了。。。。WA了,,,真是服了自己 。。。。

  • 0
    @ 2015-10-27 09:20:01

    #include<iostream>
    #include<cstdio>
    #include<queue>
    using namespace std;
    struct Ta{
    int bh,l1,l2;
    bool operator<(const Ta a)const{
    return l1<a.l1;
    }
    };
    int x1,x2,y1,y2,n,x,y;
    priority_queue<Ta>q;
    int main()
    {
    freopen("Missile.in","r",stdin);
    // freopen("Missile.out","w",stdout);
    scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
    scanf("%d",&n);
    Ta a;
    for(int i=1;i<=n;i++)
    {
    scanf("%d%d",&x,&y);
    a.l1=(x-x1)*(x-x1)+(y-y1)*(y-y1);
    a.l2=(x-x2)*(x-x2)+(y-y2)*(y-y2);
    q.push(a);
    }
    a=q.top();
    q.pop();
    int ans=a.l1;
    int R=a.l2;
    while(!q.empty())
    {
    a=q.top();
    q.pop();
    ans=min(ans,a.l1+R);
    R=max(R,a.l2);
    }
    printf("%d",ans);
    fclose(stdin);
    fclose(stdout);
    return 0;

    }

  • 0
    @ 2015-10-05 16:57:15

    淘气包是李洋,是个乌龟王八蛋

  • 0
    @ 2015-10-05 16:55:10

    战斗鸡叫李建,是王八!!!

  • 0
    @ 2015-10-05 16:53:32

    战斗鸡真不要脸!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

  • 0
    @ 2015-10-05 16:51:55

    25252525252525252525252525252525252525252525252525252525252525252525252525252525252525252525252525252525252525252525252525252525252525252525252525252525252525252525252525252525252525252525252525252525252525252525252525本王之送

  • 0
    @ 2015-09-27 10:52:28

    ,,,,,,,,

  • 0
    @ 2014-01-01 12:02:41

    Vijos 题解:http://hi.baidu.com/umule/item/2c997f8ed9600fdae596e017
    有疑问请留言 共同进步

  • 0
    @ 2013-10-21 19:31:04

    貌似是贪心
    var a,b:array[0..100010]of longint; x1,y1,n,ans,x2,y2,x,y,i,j:longint;
    procedure qsort(l,r:longint);
    var i,j,t,m:longint;
    begin
    i:=l; j:=r; m:=a[(i+j)>>1];
    repeat
    while a[i]<m do inc(i);
    while a[j]>m do dec(j);
    if i<=j then
    begin
    t:=a[i]; a[i]:=a[j]; a[j]:=t;
    t:=b[i]; b[i]:=b[j]; b[j]:=t;
    inc(i); dec(j);
    end;
    until i>j;
    if l<j then qsort(l,j);
    if i<r then qsort(i,r);
    end;
    begin
    read(x1,y1,x2,y2,n); ans:=maxlongint;
    for i:=1 to n do
    begin
    read(x,y);
    a[i]:=sqr(x-x1)+sqr(y-y1);
    b[i]:=sqr(x-x2)+sqr(y-y2);
    end;
    qsort(1,n);
    for i:=1 to n do
    if a[i]<ans then
    begin
    x1:=a[i];
    if b[i]>=y1 then
    begin
    y1:=0;
    for j:=i+1 to n do if b[j]>y1 then y1:=b[j];
    end;
    if x1+y1<ans then ans:=x1+y1;
    end;
    write(ans);
    end.

  • 1

信息

ID
1810
难度
6
分类
(无)
标签
递交数
1606
已通过
443
通过率
28%
被复制
14
上传者