codeforces 開始的幾個題

來源:互聯網
上載者:User

最近開始做codeforces上得題,感覺有以下幾點:

1、俄羅斯式的英語真難懂啊!2、codeforces上得題目很不錯,對于思路來說,有點的妙,甚至是一些簡單的題 3、codeforces上很重視計算幾何,這個方面我不是很強,而且,codeforces很注重數學和數學思想!


開始總結一下這幾天的題吧

codeforces beta round #1A 簡單題,不解釋

codeforces beta round #2A A題都是不很難,10進位和26進位之間的轉換,但是26進位中沒有0的概念,得A是1,這個不是很難想

codeforces beta round #4A 有一個重w的西瓜,問能不能切成兩塊都是偶數重的西瓜?  當w=2不能,但是當w>2是偶數能,奇不能,沒意思吧

codeforces beta round #82A 有這麼一個隊列,當隊首的人出隊之後,隊尾將出現兩個出隊的人,題目有點意思;隊伍初始化為5個人

數學吧,這個我用過,代碼如下:

#include <iostream>#include <stdio.h>#include <string.h>using namespace std;int get(int n){    if(n <= 5) return n;    else return get( (n-4)/2 );}int main(){    string re[] = { "", "Sheldon", "Leonard", "Penny", "Rajesh", "Howard"};    int n;    while(cin >> n)    {        cout << re[get(n)] << "\n";    }}

codeforces beta round #A 做完這個題之後的第一感覺是,讓一個水題給虐了,首先是題目的意思看不懂。看了好多遍也沒有看懂最後誰贏!以至於代碼敲了好幾遍!

最後雖然看懂了,但是也用了我很久的時間,有點浪費啊!這個題贏的規則,也有點彆扭,就是最後的最高分,當有多個人時,贏的人為這些最高分的人中最先達到或者超過這個分數的人。

//讓一個水題虐了!!!#include <algorithm>#include <string.h>#include <stdio.h>#include <iostream>#include <map>using namespace std;map <string ,int> mapp;map <string ,int> mapp2;struct note{    string name;    int score;}data[1100];int ma;int main(){    int n;    while(cin >> n)    {        ma = -100000000;        string re;        for(int i = 0;i < n;i++)            cin >> data[i].name >> data[i].score;        mapp.clear();        for(int i = 0;i < n;i++)        {            string name = data[i].name;            int score = data[i].score;            mapp[ name ] += score;        }        map <string ,int> ::iterator   theIter;        for   (theIter   =   mapp.begin();   theIter   !=   mapp.end();   theIter   ++){            ma = max(ma,theIter -> second);        }        mapp2.clear();        for(int i = 0;i < n;i++)        {            string name = data[i].name;            int score = data[i].score;            mapp2[ name ] += score;            if(mapp[ name ] == ma && mapp2[ name ] >= ma)            {                re = name;                break;            }        }        cout << re << "\n";    }    return 0;}

codeforces beta round #2B 問題是求矩陣左上方到右下角的路徑所有數位乘的最後末尾的0的個數最少。首先很明顯和2,5因子數有關。思路:兩遍dp分別求出最少的2和最少的5,這兩個最少的一個就是答案。但是這個裡面並沒有考慮0的情況,考慮進去就管了。最後輸出路徑就行了,這個題思路是這樣的沒錯,但是我還沒有a

codeforces beta round #3A 題目大意:棋盤上有兩個點,始點和終點,可以8個方向走,問最短的路徑是多少步,輸出每一步的方向,這個題有一個部落格說事廣搜,我覺得用廣搜就相當於殺雞用牛刀,呵呵,這個直接輸出就是了

//這個題的代碼不是很好,見諒#include <iostream>#include <string.h>#include <stdio.h>using namespace std;int abs(int a){    return a > 0 ? a : 0-a;}string getR(int a,int b,int aa,int bb){    if(a == aa) return b < bb ? "U":"D";    if(b == bb) return a < aa ? "R":"L";    if(a > aa && b > bb) return "LD";    else if(a > aa && b < bb) return "LU";    else if(a < aa && b > bb) return "RD";    else if(a < aa && b < bb) return "RU";}int main(){    int a,aa,b,bb;    char c[10];    gets(c);    a = c[0]-'a'; b = c[1]-'0';    gets(c);    aa = c[0]-'a';bb = c[1]-'0';    int re = abs(a-aa) + abs(b-bb) - min(abs(a-aa),abs(b-bb)) ;    printf("%d\n",re);    string s;    s = getR(a,b,aa,bb);    for(int i = 0;i < min(abs(a-aa),abs(b-bb));i++)        cout << s << "\n";    int t = min(abs(a-aa),abs(b-bb));    if(a > aa) a -= t;else a += t;    if(b > bb) b -= t;else b += t;    s = getR(a,b,aa,bb);    for(int i = 0;i < re-t;i++)        cout << s << "\n";    return 0;}





聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.