BC#33

来源:互联网 发布:电力系统仿真软件比较 编辑:程序博客网 时间:2024/05/04 06:56

zhx's submissions

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


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 3221 42333 16abbccd
 

Sample Output
123314
 

Source
BestCoder Round #33
 

#include <cstdio>#include <iostream>#include <cstring>#include <cmath>#include <algorithm>#include <string.h>#include <string>#include <vector>#include <queue>#define MEM(a,x) memset(a,x,sizeof a)#define eps 1e-8#define MOD 10009#define MAXN 10010#define INF 99999999#define ll __int64#define bug cout<<"here"<<endl#define fread freopen("ceshi.txt","r",stdin)#define fwrite freopen("out.txt","w",stdout)using namespace std;void read(int &x){    char ch;    x=0;    while(ch=getchar(),ch!=' '&&ch!='\n')    {        x=x*10+ch-'0';    }}char ch[210];int a[210];int main(){//    fread;    int n,b;    while(scanf("%d%d",&n,&b)!=EOF)    {        MEM(a,0);        while(n--)        {            scanf("%s",ch);            int len=strlen(ch);            for(int i=0;i<len;i++)            {                if(ch[i]>='0'&&ch[i]<='9')  a[len-1-i]+=ch[i]-'0';                else a[len-1-i]+=ch[i]-'a'+10;            }        }        int i;        for(i=200;i>=0;i--)        {            a[i]%=b;            if(a[i])                break;        }        if(i==-1)        {            printf("0\n");            continue;        }        for(;i>=0;i--)        {            a[i]%=b;            if(a[i]<=9) printf("%d",a[i]);            else printf("%c",a[i]-10+'a');        }        puts("");    }    return 0;}


zhx's contest

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


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 2333 5
 

Sample Output
21
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
 

#include <cstdio>#include <iostream>#include <cstring>#include <cmath>#include <algorithm>#include <string.h>#include <string>#include <vector>#include <queue>#define MEM(a,x) memset(a,x,sizeof a)#define eps 1e-8#define MOD 10009#define MAXN 10010#define INF 99999999#define ll long long#define bug cout<<"here"<<endl#define fread freopen("ceshi.txt","r",stdin)#define fwrite freopen("out.txt","w",stdout)using namespace std;void read(int &x){    char ch;    x=0;    while(ch=getchar(),ch!=' '&&ch!='\n')    {        x=x*10+ch-'0';    }}ll n,p;ll mult(ll a,ll b){    ll res=0;    while(b)    {        if(b&1)            res=(res+a)%p;        a=(a+a)%p;        b>>=1;    }    return res%p;}ll power(ll a,ll b){    ll res=1;    while(b)    {        if(b&1)            res=mult(res,a);        a=mult(a,a);        b>>=1;    }    return res;}int main(){    //fread;    while(scanf("%I64d%I64d",&n,&p)!=EOF)    {        if(n==1)        {            printf("%I64d\n",1LL%p);            continue;        }        ll ans=power(2,n);        ans-=2;        ans%=p;        ans+=p;        ans%=p;        printf("%I64d\n",ans);    }    return 0;}



0 0
原创粉丝点击