Codeforces初體驗

來源:互聯網
上載者:User

標籤:codeforces   string   演算法   刷題   

Codeforces印象

這兩天抽時間去codeforces體驗了一把。
首先,果然有眾多大牛存在,很多名人一直參加每周一次的比賽,積分2000+,並參與出題。
另外,上面題目很多,估計至少一千題。比賽結束後,題目將轉為練習題,可以持續嘗試。每道題目都有標籤,如greedy, math, matrices等等,可以點擊相應的標籤只做相關的題目。可惜我做了好幾道之後才發現。

這次解決的題目

首次嘗試,這次做的幾個都是選的完成人數最多的,比較簡單,但還是有些東西是從中新學習到的。以後最好分類練習。

1A Theatre Square
  • 用a x a的磚塊去鋪滿面積m x n的廣場,不準破壞磚塊,允許超出廣場,求磚塊數目
  • 分別計算長寬至少多少塊即可
  • 小技巧:(m-1)/a+1來計算長度方向的磚塊數目
#include<iostream>#include<limits>using namespace std;int main(){  long long m,n,a;  //cout << numeric_limits<long>::max() << endl;  cin >> m >> n >> a;  cout << ((m-1)/a + 1)*((n-1)/a + 1) << endl;  return 0;}


4A Watermelon
  • 太過簡單
158A Next Round
  • 太過簡單
71A Way Too Long Words
  • 給定一個單詞,如果長度超過10,改成縮寫形式:首字母+中間的字母個數+尾字母
  • 直接輸出結果即可
118A String Task
  • 給定一個單詞,刪掉所有母音字母,其餘字母轉換為小寫並每個字母前加.符號
  • 使用ostringstream和tolower函數
#include<iostream>#include<sstream>using namespace std;int main(){  string str;  cin >> str;  ostringstream ostr;  for(auto i:str){    char t=tolower(i);    if(t == 'a' || t=='o' || t=='y'||t=='e' ||t=='u' || t=='i')      ;    else      ostr<< '.' << t;  }  cout << ostr.str() << endl;  return 0;}


158B Taxi
  • n個小組,每組不超過4人,出租車每車不能超過4人,同組人不能分開,求最少要多少輛車
  • 貪心,盡量坐滿每一輛車,剩下的進行組合
#include<iostream>#include<vector>using namespace std;int main(){  int n;  cin >> n;  // can't initialize a vector with its element;  //vector<int> test(1,2,3,4);  vector<int> stat(4,0);  for(int i = 0;i < n;i++){    int tmp;    cin >> tmp;    stat[tmp-1] += 1;  }  int num_taxi = 0;  num_taxi += stat[3];  if(stat[2]>= stat[0]){    num_taxi += stat[2];    num_taxi += (stat[1]+1)/2;  }  else{    num_taxi += stat[2];    stat[0] -= stat[2];    num_taxi += (stat[0] + stat[1]*2 -1)/4 + 1;  }  cout << num_taxi << endl;  return 0;}


50A Domino piling
  • mxn的廣場用2x1的磚塊鋪滿,至少多少塊?
  • 分析m,n在為奇偶的情況下的鋪法即可
231A Team
  • 太過簡單
116A Tram
  • 太多簡單
131A cAPS lOCK
  • 根據特定條件更改字串中的字母大小寫
  • 關鍵是如何遍曆字串中的字元並更改大小寫
  • for(char &c:s) 可以方便的遍曆字串
  • cctype標頭檔中包含了islower,tolower,isupper,toupper等char字元處理函數
#include<iostream>#include<cctype>using namespace std;bool meet_rule(string s){    for(char &c:s.substr(1))    {        if(islower(c))            return false;    }    return true;}int main(){    string s;    cin >> s;    if(meet_rule(s))    {        for(char &c:s)        {        if(true )        {            if(islower(c))                c = toupper(c);            else                 c = tolower(c);        }        }    }    cout << s << endl;    return 0;}


282A Bit++
  • 太過簡單
轉載請註明Focustc,部落格地址為http://blog.csdn.net/caozhk,原文連結為點我
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.