zoukankan      html  css  js  c++  java
  • BestCoder Round #33


    A.

     zhx's submissions

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
    Total Submission(s): 858    Accepted Submission(s): 233


    Problem Description
    As one of the most powerful brushes, zhx submits a lot of code on many oj and most of them got AC.
    One day, zhx wants to count how many submissions he made on n ojs. He knows that on the ith oj, he made ai submissions. And what you should do is to add them up.
    To make the problem more complex, zhx gives you n Bbase numbers and you should also return a Bbase number to him.
    What's more, zhx is so naive that he doesn't carry a number while adding. That means, his answer to 5+6 in 10base is 1. And he also asked you to calculate in his way.
     

    Input
    Multiply test cases(less than 1000). Seek EOF as the end of the file.
    For each test, there are two integers n and B separated by a space. (1n1002B36)
    Then come n lines. In each line there is a Bbase number(may contain leading zeros). The digits are from 0 to 9 then from a to z(lowercase). The length of a number will not execeed 200.
     

    Output
    For each test case, output a single line indicating the answer in Bbase(no leading zero).
     

    Sample Input
    2 3 2 2 1 4 233 3 16 ab bc cd
     

    Sample Output
    1 233 14
     

    Source



    题意:n个B进制的数相加。B进制输出结果。

    解析:開始理解错题意了。最后才发现是每位相加时不产生进位。。。直接模拟就可以。



    AC代码:

    #include <cstdio>
    #include <cstring>
    #include <iostream>
    #include <algorithm>
    using namespace std;
    
    int n, m;
    
    char s[1002][202];
    char ans[202];
    int len[202];
    
    int get(char c){
    	return (c >= '0' && c <= '9') ? c - '0' : c  - 'a' + 10;
    }
    
    char put(int x){
    	return x < 10 ?

    x + '0' : x - 10 + 'a'; } int main(){ // freopen("in.txt", "r", stdin); while(scanf("%d%d", &n, &m)==2){ int maxlen = 0; for(int i=0; i<n; i++){ scanf("%s", s[i]); len[i] = strlen(s[i]); maxlen = max(maxlen, len[i]); } for(int i=0; i<maxlen; i++) ans[i] = '0'; ans[maxlen] = 0; for(int j=1; j<=maxlen; j++){ for(int i=0; i<n; i++){ if(len[i] >= j){ int cnt = maxlen - j; ans[cnt] = put((get(ans[cnt]) + get(s[i][len[i] - j])) % m); } } } int i = 0; while(ans[i] == '0' && i < maxlen - 1) i ++; printf("%s ", ans + i); } return 0; }



    PS:模拟到吐血。。




    B.

    zhx's contest

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
    Total Submission(s): 833    Accepted Submission(s): 274


    Problem Description
    As one of the most powerful brushes, zhx is required to give his juniors n problems.
    zhx thinks the ith problem's difficulty is i. He wants to arrange these problems in a beautiful way.
    zhx defines a sequence {ai} beautiful if there is an i that matches two rules below:
    1: a1..ai are monotone decreasing or monotone increasing.
    2: ai..an are monotone decreasing or monotone increasing.
    He wants you to tell him that how many permutations of problems are there if the sequence of the problems' difficulty is beautiful.
    zhx knows that the answer may be very huge, and you only need to tell him the answer module p.
     

    Input
    Multiply test cases(less than 1000). Seek EOF as the end of the file.
    For each case, there are two integers n and p separated by a space in a line. (1n,p1018)
     

    Output
    For each test case, output a single line indicating the answer.
     

    Sample Input
    2 233 3 5
     

    Sample Output
    2 1
    Hint
    In the first case, both sequence {1, 2} and {2, 1} are legal. In the second case, sequence {1, 2, 3}, {1, 3, 2}, {2, 1, 3}, {2, 3, 1}, {3, 1, 2}, {3, 2, 1} are legal, so the answer is 6 mod 5 = 1
     

    Source


    题意:给一个n,统计1~n的数构成的先递增后递减或先递减后递增的序列的个数。

    解析:这样的情况仅仅须要考虑最大值的位置就可以,共同拥有2^(n-1)  * 2种,在两端时有单增或单减2种。可是前面考虑的时候反复了两次,故终于结果是2^n - 2.注意要特判n == 1时,直接输出结果就可以。



    AC代码:

    #include <cstdio>
    
    #define LL __int64
    
    LL q_mul(LL x, LL n, LL p){          //快乘,非常坑的是两数都不能直接相乘。据说会爆掉
        LL res = 0;
    	while(n){
            if(n & 1) res = (res + x) % p;
            x = (x + x) % p;
            n >>= 1;
    	}
    	return res;
    }
    
    LL pow_mod(LL x, LL n, LL p){        //高速幂
    	LL res = 1;
    	while(n){
            if(n & 1) res = q_mul(res, x, p);   //计算res * x
            x = q_mul(x, x, p);                 //计算x * x
            n >>= 1;
    	}
    	return res;
    }
    
    int main(){
        #ifdef sxk
            freopen("in.txt", "r", stdin);
        #endif //sxk
    
    	LL n, p;
    	while(scanf("%I64d%I64d", &n, &p)!=EOF){
    		if(n == 1){
                printf("%I64d
    ", n % p);
                continue;
            }
    		else printf("%I64d
    ", (pow_mod(2, n, p) - 2 + p) % p);
    	}
    	return 0;
    }
    


    未完。

    。。待续



  • 相关阅读:
    Android活动条(actionbar)使用具体解释(一)
    Cocos2d-x之LayerMultiplex的使用
    使用UIWebView载入本地或远程server上的网页
    Ubuntu 13.10上用户怎样获得root权限,用户怎样获得永久root权限,假设配置root登录
    android-async-http框架
    android开发——自己定义相机(Camera)开发总结
    Android中measure过程、WRAP_CONTENT详解以及 xml布局文件解析流程浅析
    Android 中自定义控件和属性(attr.xml,declare-styleable,TypedArray)的方法和使用
    Android 数字签名学习笔记
    Android 4.4从图库选择图片,获取图片路径并裁剪
  • 原文地址:https://www.cnblogs.com/yjbjingcha/p/6924389.html
Copyright © 2011-2022 走看看