BestCoder Round #33

16 篇文章 0 订阅


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. ( 1n100 2B36 )
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\n", 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", n % p);
            continue;
        }
		else printf("%I64d\n", (pow_mod(2, n, p) - 2 + p) % p);
	}
	return 0;
}


未完。。。待续



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值