• Codeforces Round #316 (Div. 2) (ABC题)


    A - Elections

    题意:

    每一场城市选举的结果,第一关键字是票数(降序),第二关键字是序号(升序),第一位获得胜利。
    最后的选举结果,第一关键字是获胜城市数(降序),第二关键字是序号(升序),第一位获得胜利。
    求最后选举获胜者。

    思路:

    直接模拟就可以。

    代码:

    /*
    * @author FreeWifi_novicer
    * language : C++/C
    */
    #include<cstdio>
    #include<iostream>
    #include<cstring>
    #include<cstdlib>
    #include<cmath>
    #include<algorithm>
    #include<string>
    #include<map>
    #include<set>
    #include<vector>
    #include<queue>
    
    using namespace std;
    
    #define clr( x , y ) memset(x,y,sizeof(x))
    #define cls( x ) memset(x,0,sizeof(x))
    #define mp make_pair
    #define pb push_back
    typedef long long lint;
    typedef long long ll;
    typedef long long LL;
    const int maxn = 105;
    struct C{
        int v;
        int no;
    }c[maxn][maxn];
    
    int cnt[maxn];
    bool cmp(C a , C b){
        if(a.v != b.v) return a.v < b.v;
        return a.no > b.no;
    }
    int main(){
      //freopen("input.txt","r",stdin);
        int n,m;
        while( cin >> n >> m){
            cls(cnt);
            for(int i = 1 ; i <= m ; i++){
                for(int j = 1 ; j <= n ; j++){
                    c[i][j].no = j;
                    scanf("%d",&c[i][j].v);
                }
                sort(c[i]+1 , c[i]+n+1 , cmp);
                for(int j = 1 ; j <= n ; j++){
                }
                cnt[c[i][n].no]++;
            }
            int ans = n;
            int tmp = cnt[n];
            for(int i = n ; i >= 1 ; i--){
                if(tmp <= cnt[i]){
                    ans = i;
                    tmp = cnt[i];
                }
            }
            cout << ans << endl;
        }
        return 0;
    }
    

    B - Simple Game

    题意:

    Misha 与 Andrew 玩游戏,两人在1~n范围内各选一个数字(可同样),然后在1~n范围内随机出一个数字x,Misha 和 Andrew 的数字减去x的绝对值较小者获胜。若一致,则 Misha 获胜,如今已知 n 与 Misha 选择的数字,求 Andrew 胜率最高(同等胜率取最小)的数字。

    思路:

    分类讨论,仅仅须要考虑 Misha 左右的位置就可以。
    注意 n = 1 时的情况特判。

    代码:

    /*
    * @author FreeWifi_novicer
    * language : C++/C
    */
    #include<cstdio>
    #include<iostream>
    #include<cstring>
    #include<cstdlib>
    #include<cmath>
    #include<algorithm>
    #include<string>
    #include<map>
    #include<set>
    #include<vector>
    #include<queue>
    
    using namespace std;
    
    #define clr( x , y ) memset(x,y,sizeof(x))
    #define cls( x ) memset(x,0,sizeof(x))
    #define mp make_pair
    #define pb push_back
    typedef long long lint;
    typedef long long ll;
    typedef long long LL;
    
    int main(){
    //  freopen("input.txt","r",stdin);
        int m,n;
        while(cin >> n >> m){
            if(m == 1){
                if(n == 1)
                    cout << 1 << endl;
                else{
                    cout << m+1 << endl;
                }
                continue;
            }
            if(m == n){
                if(n == 1)
                    cout << 1 << endl;
                else{
                    cout << m-1 << endl;
                }
                continue;
            }
            int ans;
            if(n&1){
                int tmp = (n+1) / 2;
                if(m < tmp){
                    ans = m+1;
                }
                else if(m > tmp)
                    ans = m-1;
                else if(m == tmp)
                    ans = m-1;
            }
            else{
                int tmp = n / 2;
                if(m < tmp){
                    ans = m+1;
                }
                else if(m > tmp)
                    ans = m-1;
                else if(m == tmp)
                    ans = m+1;
            }
            cout << ans << endl;
        }
        return 0;
    }
    

    C - Replacement

    题意:

    输入一个含 ‘.’ 与小写英文字母的字符串。
    定义一种操作为: 将字符串中的 “..” 替代为 “.” ;
    定义字符串的价值等于最大操作次数。


    如今有 m 个询问 , 每个询问都将改变字符串指定位置上的字符为指定字符,计算询问后的字符串价值。

    思路:

    这题神似线段树的风格(用线段树也确实能够做。
    这题的关键是简化不同情况的分类讨论。我之前的想法一直是记录每个 ‘.’ 区间的情况,然后询问时二分在哪个区间就可以,结果发现写起来思路混乱毫无逻辑。又是set又是map的。。


    直到在standing榜看到第二名的神牛的代码。

    。怒删原来代码重写了一份。简单了非常多非常多。

    代码:

    /*
    * @author FreeWifi_novicer
    * language : C++/C
    */
    #include<cstdio>
    #include<iostream>
    #include<cstring>
    #include<cstdlib>
    #include<cmath>
    #include<algorithm>
    #include<string>
    #include<map>
    #include<set>
    #include<vector>
    #include<queue>
    
    using namespace std;
    
    #define clr( x , y ) memset(x,y,sizeof(x))
    #define cls( x ) memset(x,0,sizeof(x))
    #define mp make_pair
    #define pb push_back
    typedef long long lint;
    typedef long long ll;
    typedef long long LL;
    
    int main(){
      //freopen("input.txt","r",stdin);
        int n , m ;
        string s;
        cin >> n >> m >> s;
        int cnt = 0;
        for( int i = 1 ; i < s.length() ; i++ ){
            if( s[i] == '.' && s[i-1] == '.') cnt ++;
        }
        for( int i = 1 ; i <= m ; i++ ){
            int p ;
            char c ;
            scanf( "%d %c" , &p , &c );
            p--;
            if( p > 0 && s[p] == '.' && s[p - 1] == '.' ) cnt--;
            if( p < s.length() && s[p] == '.' && s[p + 1] == '.' ) cnt--;
            s[p] = c;
            if( p < s.length() && s[p] == '.' && s[p + 1] == '.' ) cnt++;
            if( p > 0 && s[p] == '.' && s[p - 1] == '.' ) cnt++;
            cout << cnt << endl;
        }
        return 0;
    }
    
  • 相关阅读:
    学习游戏设计
    AspectJ
    Spring AOP进行日志记录,管理 (使用Spring的拦截器功能获取对action中每个方法的调用情况,在方法调用前和调用后记录相关日志。)
    Java内存泄露测试及工具
    使用Tomcat插件开发WEB应用
    想学习建个网站?WAMP Server助你在Windows上快速搭建PHP集成环境
    UML 基础:类图
    Impala学习--Impala前端代码分析,Impala后端代码分析
    Impala学习--Impala概述,Impala系统架构
    图论--2-SAT--HDU/HDOJ 1814 Peaceful Commission
  • 原文地址:https://www.cnblogs.com/tlnshuju/p/7199892.html
Copyright © 2020-2023  润新知