Codeforces Round #438 B Race Against Time(模拟)
2017-10-06 15:42
459 查看
题目链接:点击打开链接
一个基于时钟的模拟题,将时钟分为3600份,从起点分别顺时针和逆时针走一遍即可
AC代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int clock[3601];
int h, m, s, t1, t2;
void solve()
{
memset(clock,0,sizeof(clock));
if(m==0) m=60;
if(s==0) s=60;
clock[(m*60+s)%3601]=-1, clock[s*60]=-1;
clock[(300*h+m+(s+59)/60)%3601]=-1;
for(int i=t1*300;!clock[i%3601];i++)
clock[i%3601]=1;
for(int i=t1*300-1;!clock[i%3601];i--)
{
if(i==0) i=3600;
clock[i%3601]=1;
}
if(clock[t2*300]) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
while(cin>>h>>m>>s>>t1>>t2)
{
solve();
}
return 0;
}
一个基于时钟的模拟题,将时钟分为3600份,从起点分别顺时针和逆时针走一遍即可
AC代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int clock[3601];
int h, m, s, t1, t2;
void solve()
{
memset(clock,0,sizeof(clock));
if(m==0) m=60;
if(s==0) s=60;
clock[(m*60+s)%3601]=-1, clock[s*60]=-1;
clock[(300*h+m+(s+59)/60)%3601]=-1;
for(int i=t1*300;!clock[i%3601];i++)
clock[i%3601]=1;
for(int i=t1*300-1;!clock[i%3601];i--)
{
if(i==0) i=3600;
clock[i%3601]=1;
}
if(clock[t2*300]) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
while(cin>>h>>m>>s>>t1>>t2)
{
solve();
}
return 0;
}
相关文章推荐
- Codeforces Round #438 - B. Race Against Time
- Codeforces Round #438 B. Race Against Time 思路很重要
- Codeforces Round #438 B. Race Against Time
- Codeforces Round #438 B. Race Against Time 题解
- 【Codeforces Round #438 B】Race Against Time
- CodeFroces Round 438 B.Race Against Time(模拟)
- 【模拟】Codeforces Round #438 A. Bark to Unlock 题解
- Educational Codeforces Round 7(B)模拟
- Codeforces Round #328 (Div. 2)Problem A. PawnChess(模拟)
- Codeforces Round 389 Div.2 B. Santa Claus and Keyboard Check(模拟)
- Codeforces Round #376 (Div. 2)F(前缀和,模拟)
- Codeforces Round #182 (Div. 1) B. Yaroslav and Time(二分+SPFA变形)
- Codeforces Round #438 by Sberbank and Barcelona Bootcamp (Div. 1 + Div. 2 combined)C - Qualification
- Codeforces Round #438 - A. Bark to Unlock
- Educational Codeforces Round 27 C. Two TVs(模拟)
- Educational Codeforces Round 32 B题 Buggy Robot(模拟)
- Educational Codeforces Round 11B. Seating On Bus 模拟
- Codeforces Educational Codeforces Round 5 A. Comparing Two Long Integers 高精度比大小,模拟
- Codeforces Round #373 (Div. 2) C 模拟
- Codeforces Round #379 (Div. 2) D. Anton and Chess 模拟