• Codeforces初体验


    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,原文链接为点我
  • 相关阅读:
    封装/继承
    模板
    常用模块-re模块1
    包常用模块
    模块和软件开发的目录规范
    Hadoop 综合大作业
    hive基本操作与应用
    用mapreduce 处理气象数据集
    熟悉常用的HBase操作,编写MapReduce作业
    爬虫大作业
  • 原文地址:https://www.cnblogs.com/gavanwanggw/p/6795467.html
Copyright © 2020-2023  润新知