2015 AlBaath Collegiate Programming Contest A
Description
Tamer is traveling with his brother on a long highway. He sees a traffic light at a distance. He calculated that it will take him x seconds until he arrives at the traffic light, he also knows that the green light lasts for g seconds, the yellow light lasts for y seconds and the red light lasts for r seconds. Now he is wondering in what color will the light be when he arrives there?
You know he is now busy driving, so he asks you to tell him the answer! you know that the light has just turned green at the moment of his question, and that the sequence of the lights is: GREEN, YELLOW, RED and then GREEN and so on.
The first line of input contains one integer T - the number of test cases.
Each test case contains four integers x, g, y, r as described in the statement.
1 ≤ x, g, y, r ≤ 109
For each test case output a single word, "RED" or "YELLOW" or "GREEN" without the quotes.
3
5 5 2 8
7 5 2 8
16 5 2 8
YELLOW
RED
GREEN
In the samples the light changes as follows:
Light: g, g, g, g, g, y, y, r, r, r, r, r , r , r , r , g , g , g , g ...
Time : 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18...
题意:告诉我们红绿灯三种颜色的时间变化,告诉一个总时间,问经过时应该是哪种颜色
解法:总时间%红绿灯变化总时间,讨论余
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | #include<bits/stdc++.h> using namespace std; int main() { int t; int a,b,c,d; cin>>t; while (t--) { cin>>a>>b>>c>>d; int mod=a%(b+c+d); if (mod<b) { cout<< "GREEN" <<endl; } else if (mod>=b&&mod<b+c) { cout<< "YELLOW" <<endl; } else { cout<< "RED" <<endl; } } return 0; } |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 从HTTP原因短语缺失研究HTTP/2和HTTP/3的设计差异
· 三行代码完成国际化适配,妙~啊~