zoukankan      html  css  js  c++  java
  • 2012 winter training @HIT Day 1 解题报告

    今天是第一天acm冬训,这次冬训主要是学习知识,而且是第一天,也是为了照顾11级没有基础的新同学,题目都很水。

    http://acm.hit.edu.cn/hoj/contest/view?id=100127

    所有题目都没有标题,标题是我自己加的……

    第一题:Gifts of Peter's friends

    读懂题就应该能敲出代码了,就是有的同学抱怨这题的英文写的比较烂,据说这英文是俄罗斯人写的。。

    核心步骤就是把数据当下标,下标变数据。

    /*This Code is Submitted by acehypocrisy for Problem 4000082 at 2012-01-18 16:44:29*/
    #include <stdio.h>
    
    int output[100];
    int n;
    int main()
    {
        while(scanf("%d", &n) == 1){
            int i;
            for (i = 0; i < n; i++){
                int temp;
                scanf("%d", &temp);
                output[temp - 1] = i + 1;
            }
            for (i = 0; i < n; i++){
                printf("%d", output[i]);
                if (i == n - 1){
                    printf("\n");
                }else
                    printf(" ");
            }
        }
        return 0;
    }
     
    

    第二题:Peter and his Photos & Postcards

    一个字符一个字符地判断,记录上一个字符和当前字符重复的次数。和上一个字符一样计数++,不一样或者计数大于5 Peter就要跑一趟了……

    另外题目下面有NOTE,是给的另一种思路。

    /*This Code is Submitted by acehypocrisy for Problem 4000083 at 2012-01-18 17:12:12*/
    #include <stdio.h>
    #include <string.h>
    
    int main()
    {
        char input[101];
        while (scanf("%s", input) == 1){
            unsigned int i;
            int count = 0, thisCh = 0;
            char last;
            for(i = 0; i < strlen(input); i++){
                if (i == 0){
                    last = input[0];
                    thisCh++;
                    continue;
                }
                if (input[i] == last){
                    thisCh++;
                    if (thisCh > 5){
                        count++;
                        thisCh = 1;
                    }
                }else{
                    count++;
                    thisCh = 1;
                    last = input[i];
                }
            }
            count++;
            printf("%d\n", count);
        }
        return 0;
    }
     
    

    第三题:Teams' Ranklists of ACM/ICPC Regional Contest

    acm竞赛的排名标准,更像是一道和工程有关的题,而不是算法。。。另外要在输入数据的地方做一下注意。排序可以直接使用STL的sort,自己写一个排序的函数。还有一个地方要注意,是按照字典顺序而不是字母表顺序,也就是说不区分大小写的;相关的问题是strlwr函数,这个函数不是标准库函数,只在windows的某些编译器的库中存在,提交到oj连编译这关都过不了……可以使用transform函数。感谢范利鑫学长指点

    /*This Code is Submitted by acehypocrisy for Problem 4000084 at 2012-01-18 19:14:26*/
    #include <stdio.h>
    #include <string.h>
    #include <vector>
    #include <algorithm>
    using namespace std;
    
    struct Team{
        char name[30];
        bool problem_issolved[9];
        int problem_wacount[9];
        int problem_actime[9];
        int sproblem_num;
        int penalty;
    };
    
    
    
    
    bool compare(const Team& a, const Team& b){
        if (a.sproblem_num < b.sproblem_num){
            return false;
        }else if (a.sproblem_num > b.sproblem_num){
            return true;
        }else{
            if(a.penalty < b.penalty)
                return true;
            else if (a.penalty > b.penalty)
                return false;
            else{
                char an[30], bn[30];
                strcpy(an, a.name);
                strcpy(bn, b.name);
                int i;
                for (i = 0; i < strlen(an); i++){
                    if (an[i] >= 'A' && an[i] <= 'Z')
                        an[i] += 'a' - 'A';
                }
                for (i = 0; i < strlen(bn); i++){
                    if (bn[i] >= 'A' && bn[i] <= 'Z')
                        bn[i] += 'a' - 'A';
                }
                if (strcmp(an, bn) < 0)
                    return true;
                return false;
            }
        }
    }
    
    int main()
    {
        int m,n;
        while (scanf("%d %d", &n, &m) == 2){
            vector<Team> teams;
            int i;
            for (i = 0; i < n; i++){
                Team temp;
                memset(&temp, 0, sizeof(temp));
                scanf("%s", temp.name);
                teams.push_back(temp);
            }
            for  (i = 0; i < m; i++){
                char t[5];
                int h,m,s, total_s;
                char state[10];
                char name[30];
                scanf("%s %d:%d:%d %s %s", t, &h, &m, &s, state, name);
                total_s = 3600 * h + 60 * m + s;
                int a;
                for (a = 0; a < n; a++){
                    if (strcmp(name, teams[a].name) == 0){
                        if (strcmp(state, "AC") == 0){
                            if (teams[a].problem_issolved[t[0] - 'A'] == false){
                                teams[a].problem_issolved[t[0] - 'A'] = true;
                                teams[a].sproblem_num++;
                                teams[a].problem_actime[t[0] - 'A'] = total_s;
                            }
                        }else{
                            if (teams[a].problem_issolved[t[0] - 'A'] == false){
                                teams[a].problem_wacount[t[0] - 'A']++;
                            }
                        }
                        break;
                    }
                }
            }
            for(i = 0; i < n; i++){
                int j;
                for (j = 0; j < 9; j++){
                    if (teams[i].problem_issolved[j]){
                        teams[i].penalty += 20 * 60 * teams[i].problem_wacount[j];
                        teams[i].penalty += teams[i].problem_actime[j];
                    }
                }
            }
            sort(teams.begin(), teams.end(), compare);
            for(i = 0; i < teams.size(); i++){
                printf("%s\n", teams[i].name);
            }
            printf("\n");
    
        }
        return 0;
    }
     
    

    第四题:Finding Points

    简单的排序问题,首按y坐标排序,次按x坐标排序。不过需要注意的是这样排好后最后一个元素并不是我们需要的元素,还应该再有一个从后向前查找具有最小x最大y的那个元素。另外在输出的问题上,最最简单的办法就是。。。把输入当做字符串存起来!什么格式问题全都无视掉。不知道算不算是投机取巧。。

    /*This Code is Submitted by acehypocrisy for Problem 4000085 at 2012-01-18 17:43:40*/
    #include <iostream>
    #include <stdio.h>
    #include <string.h>
    #include <vector>
    #include <algorithm>
    using namespace std;
    
    struct input{
        char coord[10000];
        double x;
        double y;
    };
    
    
    bool compare(const input& a, const input& b){
        if (a.y == b.y){
            if (a.x - b.x < 1e-10){
                return true;
            }
            return false;
        }else if (a.y - b.y < 1e-10){
            return true;
        }else if(a.y - b.y > 1e-10){
            return false;
        }
    }
    
    int main()
    {
        int n;
        scanf("%d", &n);
        while (n--){
            vector<input> in;
            int k;
            scanf("%d", &k);
            while (k--){
                input temp;
                scanf("%s", temp.coord);
                sscanf(temp.coord, "(%lf,%lf)", &temp.x, &temp.y);
                in.push_back(temp);
            }
            sort(in.begin(), in.end(), compare);
            int i = in.size() - 1;
            while ( i > 0){
                if (in[i].y == in[i-1].y){
                    i--;
                }else{
                    break;
                }
            }
            printf("%s %s\n", in[i].coord, in.front().coord);
        }
        return 0;
    }
     
    

     Day1 就这四道题,明天会继续。

  • 相关阅读:
    echarts中图表过于靠左或靠右的情况解决办法。
    C#语法糖大汇总【转发】
    近期对于windows服务的理解
    解决echarts中X轴文字过长的问题。【转】
    两个页面之间通过后台处理,调用父窗体方法。
    docker
    docker php
    webpack
    jwt 解密
    阿里云服务器 ECS Linux 主机删除文件后磁盘空间显示不变(转载https://www.zhanqunfuwuqi.com/archives/5293)
  • 原文地址:https://www.cnblogs.com/tuesday/p/2325961.html
Copyright © 2011-2022 走看看