zoukankan      html  css  js  c++  java
  • contest 1.24

    A.Missing Runners

    #include <iostream>
    #include<cstdio>
    using namespace std;
     
    int vis[60005];
     
    int main()
    {
        int n;scanf("%d",&n);
        for(int i=1;i<=n-1;i++){
            int t;scanf("%d",&t);
            vis[t]=1;
        }
        for(int i=1;i<=n;i++) if(!vis[i]) printf("%d
    ",i);
        return 0;
    }
    View Code

    B.Oblongs and Right Triangles

    A.动态仙人掌

    排序+贪心

    #include <iostream>
    #include<cstdio>
    #include<algorithm>
    using namespace std;
     
    struct Node{double p,h;}node[300005];
     
    bool cmp(Node a,Node b){
      return a.p-a.h<b.p-b.h;
    }
     
    int main()
    {
        int n;scanf("%d",&n);
        for(int i=1;i<=n;i++){
            scanf("%lf%lf",&node[i].p,&node[i].h);
        }
        sort(node+1,node+1+n,cmp);
        double last_rpos=node[1].p+node[1].h;
        double last_height=node[1].h;
        double last_lpos=last_rpos-2*last_height;
        if(last_lpos<0){
            puts("-1");
            return 0;
        }
        double ans=last_height;
        int i;
        for(i=2;i<=n;i++){
            double l=node[i].p-node[i].h;
            double r=node[i].p+node[i].h;
            if(l>=last_rpos){
                last_rpos=r;
                last_height=node[i].h;
                ans=max(ans,last_height);
            }
            else if(l>=last_lpos){
                if(r<=last_rpos) continue;
                else{
                    last_rpos=r;
                    last_height=(r-last_lpos)*1.0/2.0;
                    ans=max(ans,last_height);
                }
            }
            else{
                last_rpos=r;
                last_height=node[i].h;
                ans=max(ans,last_height);
            }
            last_lpos=last_rpos-2*last_height;
            if(last_lpos<0) break;
        }
        if(i<=n) puts("-1");
        else printf("%.1f
    ",ans);
        return 0;
    }
    View Code

    E.旅程

    倒过来操作

    #include <iostream>
    #include<cstdio>
    #define inf 0x3f3f3f3f
    typedef long long ll;
    using namespace std;
    
    struct Query{
      ll op,u,v,w;
    }q[100005];
    ll Map[205][205];
    ll ans[100005];
    
    int main()
    {
        ll n,m;scanf("%lld%lld",&n,&m);
        for(ll i=1;i<=n;++i){
            for(ll j=1;j<=n;++j){
                scanf("%lld",&Map[i][j]);
            }
        }
        for(ll i=1;i<=m;i++){
            ll op,u,v;
            scanf("%lld%lld%lld",&op,&u,&v);
            q[i].op=op,q[i].u=u,q[i].v=v;
            if(op==1){
                q[i].w=Map[u][v];
                Map[u][v]=inf;
            }
        }
        for(ll k=1;k<=n;k++){
            for(ll i=1;i<=n;i++){
                for(ll j=1;j<=n;j++){
                    Map[i][j]=min(Map[i][j],Map[i][k]+Map[k][j]);
                }
            }
        }
        ll cnt=0;
        for(ll i=m;i>=1;i--){
            ll op=q[i].op,u=q[i].u,v=q[i].v;
            if(op==2){
                ans[++cnt]=Map[u][v];
            }
            else{
                Map[u][v]=min(Map[u][v],q[i].w);
                for(ll i=1;i<=n;i++){
                    for(ll j=1;j<=n;j++){
                        Map[i][j]=min(Map[i][j],Map[i][u]+Map[u][j]);
                    }
                }
                for(ll i=1;i<=n;i++){
                    for(ll j=1;j<=n;j++){
                        Map[i][j]=min(Map[i][j],Map[i][v]+Map[v][j]);
                    }
                }
            }
        }
        for(ll i=cnt;i>=1;i--){
            if(ans[i]==inf) puts("-1");
            else printf("%lld
    ",ans[i]);
        }
        return 0;
    }
    View Code

    D.妹子

    几何

    #include <iostream>
    #include<cstdio>
    #include<cmath>
    using namespace std;
    
    int a1,b1,a2,b2;
    
    bool check1(){
      if(a2>a1) return 0;
      double angle1=asin(a1*1.0/sqrt(a2*a2+b2*b2));
      double angle2=atan(a2*1.0/(b2*1.0));
      return b2*cos(angle1-angle2)+a2*sin(angle1-angle2)<=b1;
    }
    
    bool check2(){
      if(a1>a2) return 0;
      double angle1=asin(a2*1.0/sqrt(a1*a1+b1*b1));
      double angle2=atan(a1*1.0/(b1*1.0));
      return b1*cos(angle1-angle2)+a1*sin(angle1-angle2)<=b2;
    }
    
    int main()
    {
        int n;scanf("%d",&n);
        while(n--){
          scanf("%d%d",&a1,&b1);
          if(a1>b1) swap(a1,b1);
          scanf("%d%d",&a2,&b2);
          if(a2>b2) swap(a2,b2);
          if((a1<=a2&&b1<=b2)||(a2<=a1&&b2<=b1)) printf("Yes
    ");
          else{
            if(check1()||check2()) printf("Yes
    ");
            else printf("No
    ");
          }
        }
        return 0;
    }
    View Code
    转载请注明出处:https://www.cnblogs.com/lllxq/
  • 相关阅读:
    关于Excel无法打开,因为文件格式或文件扩展名无效的解决方法
    SpringBoot整合rabbitmq
    异步线程池的使用
    java1.8新特性之stream流式算法
    hashMap的底层实现
    redis底层设计(五)——内部运作机制
    redis底层设计(四)——功能的实现
    redis底层设计(三)——redis数据类型
    redis底层设计(二)——内存映射数据结构
    redis底层设计(一)——内部数据结构
  • 原文地址:https://www.cnblogs.com/lllxq/p/10316588.html
Copyright © 2011-2022 走看看