Your Ride Is Here

今天是我第一次在USACO上做题,虽然这是一个很简单很简单的题目,但是这个传说中USA培养参加IOI参赛选手的OJ,不仅让我有点向往啊。 :P 这个OJ挺让人喜欢的。我很少自己认认真真的想题,也不少的OJ上都只是过过场,最近看了不少退役大牛的博文,顿时让我感到自己是多么的可笑,让我这只井里之蛙深刻的明白自己是多么的肤浅,感受到与其它人的巨大差异,这种差异不是在目前的能力上,而是在思想意识、觉悟上。

今后我给自己定了如下的原则:

1.做题一定要形成思路,不要一拿到题就一副大牛样子(还差得远呢)动键盘,
敲代码,做题关键在于自己的思路,有了思路之后,也不要因为实现较为复杂
不愿编码,另外做题也不要因为此题以前做过就不愿去做。记得上次的华中南赛,
就因为这个毛病本来一个很简单的题目,就因为实现起来的代码比平时见到的水题就
长就一直等到最后才去做。这些都说明自己仅仅是一个菜鸟而已。

2.每做一道题目都要有自己的的收获。不要因为这一道题目涉及的算法很难懂就拖延到
以后,到最后还是不懂。多花一点时间来把一个算法搞懂比自己去刷那几个水题来得
强,来得实在。一定要把一个算法弄懂,否则就永远只是会那几个只能称为模板的水
题,而算法稍微一变,就不知所云了。只有这样做题才有意义。

3.要有死磕、钻研的精神。说实话,搞了这么久的ACM,局然从来没有这么过,说来我还
没有入门呢。就拿这个USACO开始吧,听说如果能够在USACO上真正做出40%的题就有
在国际上获银奖的实力呢。 :lol:

4.数学,这个现在越发觉得其真是太重要啦,真后悔啊,让数学贯穿整个ACM学习生涯。


好了,说了这么多,总是不得要领,以后再想到什么再补充吧。

回归正题。

题目大意:给定两个串A,B,定义一个函数f(S):S中各个字母(注意只要大写字母)所代表的数字的乘积,如f("ABCZ")=1*2*3*26,串的长度不会超过6。如果f(A)%47==f(B)%47,则输出"GO",否则输出"STAY"。
题目分析:此题是一个很水的题目,不过相对一个入门的人来说还是一个比较好的入门题的。涉及的知识点有:1.文件操作,这个对ACM来说其实不需要的,但由于这个信息学OJ,与我们要求不同。2.字母ASCII码的特点:连续的,所以很容易与数字一一对应。3.其它只是字符串操作而已。
注意如果此题的字符串的长度不规定为6,就还涉及到数论经常会用到的一点小小的技巧:
(a*b)%c=((a%c)*(b%c))%c
代码:

/*
ID:xxfz014
PROG:ride
LANG:C++
*/
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
string s1,s2;
ifstream fin("ride.in");
ofstream fout("ride.out");
fin>>s1>>s2;
int len1=s1.length(),len2=s2.length();
int res1=1,res2=1;
for(int i=0;i<len1;i++) res1=res1*(s1[i]-'A'+1)%47;
for(int i=0;i<len2;i++) res2=res2*(s2[i]-'A'+1)%47;
if(res1==res2) fout<<"GO"<<endl;
else fout<<"STAY"<<endl;
fin.close();
fout.close();
return 0;
}


附:
Programming Contest Problem Types

Hal Burch conducted an analysis over spring break of 1999 and made an amazing discovery: there are only 16 types of programming contest problems! Furthermore, the top several comprise almost 80% of the problems seen at the IOI. Here they are:

Dynamic Programming
Greedy
Complete Search
Flood Fill
Shortest Path
Recursive Search Techniques
Minimum Spanning Tree
Knapsack
Computational Geometry
Network Flow
Eulerian Path
Two-Dimensional Convex Hull
BigNums
Heuristic Search
Approximate Search
Ad Hoc Problems
The most challenging problems are Combination Problems which involve a loop (combinations, subsets, etc.) around one of the above algorithms - or even a loop of one algorithm with another inside it. These seem extraordinarily tricky to get right, even though conceptually they are ``obvious''.

If you can master solving just 40% of these problem types, you can almost guarantee a silver medal at the IOI. Mastering 80% moves you into the gold range almost for sure. Of course, `mastery' is a tough nut to crack! We'll be supplying a plethora of problems so that you can hone your skills in the quest for international fame.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
To solve this problem, we can use the concept of relative speed. Let's consider the scenario step by step: 1. First, we need to find the person who sets off the earliest among all the riders. Let's call this person "earliestRider". The time when Weiwei arrives at his office will be equal to the set off time of "earliestRider" plus the time it takes for Weiwei to catch up with "earliestRider". 2. Next, we calculate the relative speed between Weiwei and "earliestRider". If Weiwei is faster than "earliestRider", he will catch up with them before they reach the office. Otherwise, Weiwei will need to wait for someone faster to catch up to him. 3. Once Weiwei catches up with "earliestRider", we update the set off time of "earliestRider" to the time when Weiwei catches up with them. 4. We repeat steps 1-3 until Weiwei reaches his office. Here's a sample C++ code that implements this logic: ```cpp #include <iostream> #include <vector> struct Rider { int setOffTime; int speed; }; int main() { int n; // number of riders (excluding Weiwei) std::cout << "请输入骑行人数(不包括Weiwei):"; std::cin >> n; std::vector<Rider> riders(n); std::cout << "请依次输入每位骑行人的出发时间和速度:" << std::endl; for (int i = 0; i < n; i++) { std::cin >> riders[i].setOffTime >> riders[i].speed; } int weiweiSpeed; std::cout << "请输入Weiwei的速度:"; std::cin >> weiweiSpeed; int weiweiArrivalTime = 0; while (true) { int earliestRiderIndex = -1; int earliestRiderTime = INT_MAX; // Find the earliest rider for (int i = 0; i < n; i++) { if (riders[i].setOffTime < earliestRiderTime) { earliestRiderTime = riders[i].setOffTime; earliestRiderIndex = i; } } // Calculate the time Weiwei takes to catch up with the earliest rider double timeToCatchUp = static_cast<double>(4.5) / (weiweiSpeed - riders[earliestRiderIndex].speed); if (earliestRiderTime + timeToCatchUp <= 60) { weiweiArrivalTime = earliestRiderTime + timeToCatchUp; riders[earliestRiderIndex].setOffTime += timeToCatchUp; } else { break; // Weiwei arrives at or after 60 minutes, stop the loop } } std::cout << "Weiwei到达办公室的时间为:" << weiweiArrivalTime << "分钟" << std::endl; return 0; } ``` In this code, we first input the number of riders (excluding Weiwei) and their set off times and speeds. Then we input Weiwei's speed. The program iterates until Weiwei arrives at or after 60 minutes, finding the earliest rider, calculating the time to catch up with them, and updating their set off time accordingly. Finally, it outputs Weiwei's arrival time at the office. Please note that this is a simplified implementation and doesn't handle all possible edge cases. You can modify and improve it based on your specific requirements. Let me know if you have any further questions!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值