Codeforces 868B Race Against Time 思维 and 排序

告诉你实际的时间,问你在实际的机械表盘上 两点是否可以不跨越指针到达?(起点终点不在指针上,ac之后知道的)

解:得到double 数据之后排序,圆周相邻即可

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define en '\n'
int rd(){
int tt;scanf("%d",&tt);return tt;
}
int  h,m,s,t1,t2;
const int mo=60;
const int maxn=1e2+10;
bool vis[maxn];
bool yes=0;
bool ok(int x){
return !vis[x] and x!=h and x!=m and x!=s;
}
void  dfs(int x){
    vis[x]=1;
    int shang=((x-1)+mo)%mo;
    int xia=((x+1)%mo);
    if(shang==t2 or xia==t2){
        yes=1;
        return ;
    }
    if(ok(shang))dfs(shang);
    if(ok(xia))dfs(xia);
}
struct node{
double val,ind;
};
bool cmp(node a,node b){
return a.val<b.val;
}
vector<node>vec;
signed main(){
    #ifdef swt
    freopen("input2.txt","r",stdin);
    #endif // swt
    cin>>h>>m>>s>>t1>>t2;
    h=(h%12)*5;
    t1=((t1)%12)*5;
    t2=((t2)%12)*5;
    if(t1==t2){cout<<"YES"<<en;return 0;}
    double ss=s;
    double mm=m+(ss/60);
    double hh=h+(mm/60);
    vec.pb((node){ss,0}),vec.pb((node){mm,0}),vec.pb((node){hh,0});
    double tt1=t1,tt2=t2;
    if(tt1>tt2)swap(tt1,tt2);
    vec.pb((node){tt1,1});
    vec.pb((node){tt2,2});
    sort(vec.begin(),vec.end(),cmp);
    if(vec[0].ind==1 and vec[vec.size()-1].ind==2){
        cout<<"YES"<<en;return 0;
    }
    for(int i=1;i<vec.size();i++){
        if(vec[i].ind==2 and vec[i-1].ind==1){
        cout<<"YES"<<en;return 0;
        }
    }
    cout<<"NO"<<en;
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值