`

Your Ride Is Here

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

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

    1.做题一定要形成思路,不要一拿到题就一副大牛样子(还差得远呢)动键盘,
       敲代码,做题关键在于自己的思路,有了思路之后,也不要因为实现较为复杂
       不愿编码,另外做题也不要因为此题以前做过就不愿去做。记得上次的华中南赛,
       就因为这个毛病本来一个很简单的题目,就因为实现起来的代码比平时见到的水题就
       长就一直等到最后才去做。这些都说明自己仅仅是一个菜鸟而已。
   
    2.每做一道题目都要有自己的的收获。不要因为这一道题目涉及的算法很难懂就拖延到
      以后,到最后还是不懂。多花一点时间来把一个算法搞懂比自己去刷那几个水题来得
      强,来得实在。一定要把一个算法弄懂,否则就永远只是会那几个只能称为模板的水
      题,而算法稍微一变,就不知所云了。只有这样做题才有意义。

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

   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.

   
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics