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
One day, zhx wants to count how many submissions he made on
To make the problem more complex, zhx gives you
What's more, zhx is so naive that he doesn't carry a number while adding. That means, his answer to
For each test, there are two integers
Then come n lines. In each line there is a
2 3 2 2 1 4 233 3 16 ab bc cd
1 233 14
题意: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
zhx thinks the
zhx defines a sequence
1:
2:
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
For each case, there are two integers
2 233 3 5
2 1HintIn 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
题意:给一个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; }
未完。
。。待续