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\n",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\n",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\n",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\n");
      else{
        if(check1()||check2()) printf("Yes\n");
        else printf("No\n");
      }
    }
    return 0;
}
View Code

 

转载于:https://www.cnblogs.com/lllxq/p/10316588.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值