2015 Multi-University Training Contest 5 1009 模板

来源:互联网 发布:seo屈臣氏优化方案 编辑:程序博客网 时间:2024/06/07 17:26

比赛链接:click here~~

hdu 5344  MZL's xor

【题意】:

Problem Description
MZL loves xor very much.Now he gets an array A.The length of A is n.He wants to know the xor of all (Ai+Aj)(1i,jn)
The xor of an array B is defined as B1 xor B2...xor Bn
 

Input
Multiple test cases, the first line contains an integer T(no more than 20), indicating the number of cases.
Each test case contains four integers:n,m,z,l
A1=0,Ai=(Ai1m+z) mod l
1m,z,l5105,n=5105
 

Output
For every test.print the answer.
 

Sample Input
23 5 5 76 8 8 9
 

Sample Output
1416
 
根据公式递推数列后几项,然后两两相加异或,看完题写完,然后看到5*10^5的范围,居然不敢交,以为要什么优化,然后最后发现当ai!=aj时,(ai+aj)和(aj+ai)抵消,所以最后答案就是相加异或输出就ok了。
代码:
[cpp] view plaincopy
  1. /*************hdu 5344 **************  
  2. #include <bits/stdc++.h>  
  3. using namespace std;  
  4. typedef long long LL;  
  5. LL num[100000000];  
  6. int t,n,m,z,l;  
  7. int main()  
  8. {  
  9.     scanf("%d",&t);  
  10.     while(t--)  
  11.     {  
  12.         scanf("%d %d %d %d",&n,&m,&z,&l);  
  13.         num[1]=0;  
  14.         for(int i=2; i<=n; ++i)  
  15.         {  
  16.             num[i]=(num[i-1]*m+z)%l;  
  17.         }  
  18.         num[1]=0;  
  19.         for(int i=2; i<=n; ++i)  
  20.         {  
  21.             num[1]^=(num[i]+num[i]);  
  22.         }  
  23.         printf("%d\n",num[1]);  
  24.     }  
  25.     return 0;  
  26. }  

hdu 5349   MZL's simple problem
【题意】RT:
Problem Description
A simple problem
Problem Description
You have a multiple set,and now there are three kinds of operations:
1 x : add number x to set
2 : delete the minimum number (if the set is empty now,then ignore it)
3 : query the maximum number (if the set is empty now,the answer is 0)
 

Input
The first line contains a number N (N106),representing the number of operations.
Next N line ,each line contains one or two numbers,describe one operation.
The number in this set is not greater than 109.
 

Output
For each operation 3,output a line representing the answer.
 

Sample Input
61 21 331 31 43
 

Sample Output
34

【题意】RT
代码:
[cpp] view plaincopy
  1. #include <bits/stdc++.h>  
  2. using namespace std;  
  3. struct cmp  
  4. {  
  5.     bool operator () (int x,int y){  
  6.         return x>y;  
  7.     }  
  8. };  
  9. int main()  
  10. {  
  11.     int t,op,m;  
  12.     int maxx=-1e9;  
  13.     scanf("%d",&t);  
  14.     priority_queue< int ,vector <int>,cmp> val;  
  15.     while(t--){  
  16.         scanf("%d",&op);  
  17.         if(op==1){  
  18.             scanf("%d",&m);  
  19.             val.push(m);  
  20.             maxx=max(maxx,m);  
  21.         }  
  22.         else if(op==2){  
  23.             if(!val.empty()){  
  24.                 val.pop();  
  25.             }  
  26.             if(val.empty()){  
  27.                 maxx=-1e9;  
  28.             }  
  29.         }  
  30.         else{  
  31.             if(val.empty()){  
  32.                 puts("0");  
  33.                 continue;  
  34.             }  
  35.             printf("%d\n",maxx);  
  36.         }  
  37.     }  
  38.     return 0;  
  39. }  

hdu 5351   MZL's Border
【题意】:

给出一个斐波那契字符串,求截取前m个字符串得到之后的最大重复子串

ps:最后一个小时推出了规律,就是斐波那契数列!调试完大数模板,在比赛最后一分钟提交,可惜超内存了囧~~最后题目拉到hduoj上之后,改了一下取模的大数类型就过了啊,真心后悔比赛的时候没有认真去看题,没有和队友讨论,如果早一点疯狂讨论,思路其实不难推出来,因为给定的n其实是没什么作用,我们只要推出前m个字符串有多少个对称子串,最后会发现其实是满足规律的,可以发现,只要找到第一个i使得m+1<fibi,答案就是m-fib(i-2).画画图,打打表,就能发现了

代码:

[cpp] view plaincopy
  1. #include <cstdio>  
  2. #include <iostream>  
  3. #include <cstring>  
  4. //#include<cstdio>  
  5. //const int mod=258280327;  
  6. using namespace std;  
  7.   
  8. #define DIGIT   4      //四位隔开,即万进制  
  9. #define DEPTH   10000        //万进制  
  10. #define MAX     5000    //题目最大位数/4,要不大直接设为最大位数也行  
  11. typedef int bignum_t[MAX+1];  
  12.   
  13. /************************************************************************/  
  14. /* 读取操作数,对操作数进行处理存储在数组里                             */  
  15. /************************************************************************/  
  16. int read(bignum_t a,istream&is=cin)  
  17. {  
  18.     char buf[MAX*DIGIT+1],ch ;  
  19.     int i,j ;  
  20.     memset((void*)a,0,sizeof(bignum_t));  
  21.     if(!(is>>buf))return 0 ;  
  22.     for(a[0]=strlen(buf),i=a[0]/2-1; i>=0; i--)  
  23.         ch=buf[i],buf[i]=buf[a[0]-1-i],buf[a[0]-1-i]=ch ;  
  24.     for(a[0]=(a[0]+DIGIT-1)/DIGIT,j=strlen(buf); j<a[0]*DIGIT; buf[j++]='0');  
  25.     for(i=1; i<=a[0]; i++)  
  26.         for(a[i]=0,j=0; j<DIGIT; j++)  
  27.             a[i]=a[i]*10+buf[i*DIGIT-1-j]-'0' ;  
  28.     for(; !a[a[0]]&&a[0]>1; a[0]--);  
  29.     return 1 ;  
  30. }  
  31.   
  32. void write(const bignum_t a,ostream&os=cout)  
  33. {  
  34.     int i,j ;  
  35.     for(os<<a[i=a[0]],i--; i; i--)  
  36.         for(j=DEPTH/10; j; j/=10)  
  37.             os<<a[i]/j%10 ;  
  38. }  
  39.   
  40. int comp(const bignum_t a,const bignum_t b)  
  41. {  
  42.     int i ;  
  43.     if(a[0]!=b[0])  
  44.         return a[0]-b[0];  
  45.     for(i=a[0]; i; i--)  
  46.         if(a[i]!=b[i])  
  47.             return a[i]-b[i];  
  48.     return 0 ;  
  49. }  
  50.   
  51. int comp(const bignum_t a,const int b)  
  52. {  
  53.     int c[12]=  
  54.     {  
  55.         1  
  56.     }  
  57.     ;  
  58.     for(c[1]=b; c[c[0]]>=DEPTH; c[c[0]+1]=c[c[0]]/DEPTH,c[c[0]]%=DEPTH,c[0]++);  
  59.     return comp(a,c);  
  60. }  
  61.   
  62. int comp(const bignum_t a,const int c,const int d,const bignum_t b)  
  63. {  
  64.     int i,t=0,O=-DEPTH*2 ;  
  65.     if(b[0]-a[0]<d&&c)  
  66.         return 1 ;  
  67.     for(i=b[0]; i>d; i--)  
  68.     {  
  69.         t=t*DEPTH+a[i-d]*c-b[i];  
  70.         if(t>0)return 1 ;  
  71.         if(t<O)return 0 ;  
  72.     }  
  73.     for(i=d; i; i--)  
  74.     {  
  75.         t=t*DEPTH-b[i];  
  76.         if(t>0)return 1 ;  
  77.         if(t<O)return 0 ;  
  78.     }  
  79.     return t>0 ;  
  80. }  
  81. /************************************************************************/  
  82. /* 大数与大数相加                                                       */  
  83. /************************************************************************/  
  84. void add(bignum_t a,const bignum_t b)  
  85. {  
  86.     int i ;  
  87.     for(i=1; i<=b[0]; i++)  
  88.         if((a[i]+=b[i])>=DEPTH)  
  89.             a[i]-=DEPTH,a[i+1]++;  
  90.     if(b[0]>=a[0])  
  91.         a[0]=b[0];  
  92.     else  
  93.         for(; a[i]>=DEPTH&&i<a[0]; a[i]-=DEPTH,i++,a[i]++);  
  94.     a[0]+=(a[a[0]+1]>0);  
  95. }  
  96. /************************************************************************/  
  97. /* 大数与小数相加                                                       */  
  98. /************************************************************************/  
  99. void add(bignum_t a,const int b)  
  100. {  
  101.     int i=1 ;  
  102.     for(a[1]+=b; a[i]>=DEPTH&&i<a[0]; a[i+1]+=a[i]/DEPTH,a[i]%=DEPTH,i++);  
  103.     for(; a[a[0]]>=DEPTH; a[a[0]+1]=a[a[0]]/DEPTH,a[a[0]]%=DEPTH,a[0]++);  
  104. }  
  105. /************************************************************************/  
  106. /* 大数相减(被减数>=减数)                                               */  
  107. /************************************************************************/  
  108. void sub(bignum_t a,const bignum_t b)  
  109. {  
  110.     int i ;  
  111.     for(i=1; i<=b[0]; i++)  
  112.         if((a[i]-=b[i])<0)  
  113.             a[i+1]--,a[i]+=DEPTH ;  
  114.     for(; a[i]<0; a[i]+=DEPTH,i++,a[i]--);  
  115.     for(; !a[a[0]]&&a[0]>1; a[0]--);  
  116. }  
  117. /************************************************************************/  
  118. /* 大数减去小数(被减数>=减数)                                           */  
  119. /************************************************************************/  
  120. void sub(bignum_t a,const int b)  
  121. {  
  122.     int i=1 ;  
  123.     for(a[1]-=b; a[i]<0; a[i+1]+=(a[i]-DEPTH+1)/DEPTH,a[i]-=(a[i]-DEPTH+1)/DEPTH*DEPTH,i++);  
  124.     for(; !a[a[0]]&&a[0]>1; a[0]--);  
  125. }  
  126.   
  127. void sub(bignum_t a,const bignum_t b,const int c,const int d)  
  128. {  
  129.     int i,O=b[0]+d ;  
  130.     for(i=1+d; i<=O; i++)  
  131.         if((a[i]-=b[i-d]*c)<0)  
  132.             a[i+1]+=(a[i]-DEPTH+1)/DEPTH,a[i]-=(a[i]-DEPTH+1)/DEPTH*DEPTH ;  
  133.     for(; a[i]<0; a[i+1]+=(a[i]-DEPTH+1)/DEPTH,a[i]-=(a[i]-DEPTH+1)/DEPTH*DEPTH,i++);  
  134.     for(; !a[a[0]]&&a[0]>1; a[0]--);  
  135. }  
  136. /************************************************************************/  
  137. /* 大数相乘,读入被乘数a,乘数b,结果保存在c[]                          */  
  138. /************************************************************************/  
  139. void mul(bignum_t c,const bignum_t a,const bignum_t b)  
  140. {  
  141.     int i,j ;  
  142.     memset((void*)c,0,sizeof(bignum_t));  
  143.     for(c[0]=a[0]+b[0]-1,i=1; i<=a[0]; i++)  
  144.         for(j=1; j<=b[0]; j++)  
  145.             if((c[i+j-1]+=a[i]*b[j])>=DEPTH)  
  146.                 c[i+j]+=c[i+j-1]/DEPTH,c[i+j-1]%=DEPTH ;  
  147.     for(c[0]+=(c[c[0]+1]>0); !c[c[0]]&&c[0]>1; c[0]--);  
  148. }  
  149. /************************************************************************/  
  150. /* 大数乘以小数,读入被乘数a,乘数b,结果保存在被乘数                   */  
  151. /************************************************************************/  
  152. void mul(bignum_t a,const int b)  
  153. {  
  154.     int i ;  
  155.     for(a[1]*=b,i=2; i<=a[0]; i++)  
  156.     {  
  157.         a[i]*=b ;  
  158.         if(a[i-1]>=DEPTH)  
  159.             a[i]+=a[i-1]/DEPTH,a[i-1]%=DEPTH ;  
  160.     }  
  161.     for(; a[a[0]]>=DEPTH; a[a[0]+1]=a[a[0]]/DEPTH,a[a[0]]%=DEPTH,a[0]++);  
  162.     for(; !a[a[0]]&&a[0]>1; a[0]--);  
  163. }  
  164.   
  165. void mul(bignum_t b,const bignum_t a,const int c,const int d)  
  166. {  
  167.     int i ;  
  168.     memset((void*)b,0,sizeof(bignum_t));  
  169.     for(b[0]=a[0]+d,i=d+1; i<=b[0]; i++)  
  170.         if((b[i]+=a[i-d]*c)>=DEPTH)  
  171.             b[i+1]+=b[i]/DEPTH,b[i]%=DEPTH ;  
  172.     for(; b[b[0]+1]; b[0]++,b[b[0]+1]=b[b[0]]/DEPTH,b[b[0]]%=DEPTH);  
  173.     for(; !b[b[0]]&&b[0]>1; b[0]--);  
  174. }  
  175. /**************************************************************************/  
  176. /* 大数相除,读入被除数a,除数b,结果保存在c[]数组                         */  
  177. /* 需要comp()函数                                                         */  
  178. /**************************************************************************/  
  179. void div(bignum_t c,bignum_t a,const bignum_t b)  
  180. {  
  181.     int h,l,m,i ;  
  182.     memset((void*)c,0,sizeof(bignum_t));  
  183.     c[0]=(b[0]<a[0]+1)?(a[0]-b[0]+2):1 ;  
  184.     for(i=c[0]; i; sub(a,b,c[i]=m,i-1),i--)  
  185.         for(h=DEPTH-1,l=0,m=(h+l+1)>>1; h>l; m=(h+l+1)>>1)  
  186.             if(comp(b,m,i-1,a))h=m-1 ;  
  187.             else l=m ;  
  188.     for(; !c[c[0]]&&c[0]>1; c[0]--);  
  189.     c[0]=c[0]>1?c[0]:1 ;  
  190. }  
  191.   
  192. void div(bignum_t a,const int b,int&c)  
  193. {  
  194.     int i ;  
  195.     for(c=0,i=a[0]; i; c=c*DEPTH+a[i],a[i]=c/b,c%=b,i--);  
  196.     for(; !a[a[0]]&&a[0]>1; a[0]--);  
  197. }  
  198. /************************************************************************/  
  199. /* 大数平方根,读入大数a,结果保存在b[]数组里                           */  
  200. /* 需要comp()函数                                                       */  
  201. /************************************************************************/  
  202. void sqrt(bignum_t b,bignum_t a)  
  203. {  
  204.     int h,l,m,i ;  
  205.     memset((void*)b,0,sizeof(bignum_t));  
  206.     for(i=b[0]=(a[0]+1)>>1; i; sub(a,b,m,i-1),b[i]+=m,i--)  
  207.         for(h=DEPTH-1,l=0,b[i]=m=(h+l+1)>>1; h>l; b[i]=m=(h+l+1)>>1)  
  208.             if(comp(b,m,i-1,a))h=m-1 ;  
  209.             else l=m ;  
  210.     for(; !b[b[0]]&&b[0]>1; b[0]--);  
  211.     for(i=1; i<=b[0]; b[i++]>>=1);  
  212. }  
  213. /************************************************************************/  
  214. /* 返回大数的长度                                                       */  
  215. /************************************************************************/  
  216. int length(const bignum_t a)  
  217. {  
  218.     int t,ret ;  
  219.     for(ret=(a[0]-1)*DIGIT,t=a[a[0]]; t; t/=10,ret++);  
  220.     return ret>0?ret:1 ;  
  221. }  
  222. /************************************************************************/  
  223. /* 返回指定位置的数字,从低位开始数到第b位,返回b位上的数               */  
  224. /************************************************************************/  
  225. int digit(const bignum_t a,const int b)  
  226. {  
  227.     int i,ret ;  
  228.     for(ret=a[(b-1)/DIGIT+1],i=(b-1)%DIGIT; i; ret/=10,i--);  
  229.     return ret%10 ;  
  230. }  
  231. /************************************************************************/  
  232. /* 返回大数末尾0的个数                                                  */  
  233. /************************************************************************/  
  234. int zeronum(const bignum_t a)  
  235. {  
  236.     int ret,t ;  
  237.     for(ret=0; !a[ret+1]; ret++);  
  238.     for(t=a[ret+1],ret*=DIGIT; !(t%10); t/=10,ret++);  
  239.     return ret ;  
  240. }  
  241.   
  242. void comp(int*a,const int l,const int h,const int d)  
  243. {  
  244.     int i,j,t ;  
  245.     for(i=l; i<=h; i++)  
  246.         for(t=i,j=2; t>1; j++)  
  247.             while(!(t%j))  
  248.                 a[j]+=d,t/=j ;  
  249. }  
  250.   
  251. void convert(int*a,const int h,bignum_t b)  
  252. {  
  253.     int i,j,t=1 ;  
  254.     memset(b,0,sizeof(bignum_t));  
  255.     for(b[0]=b[1]=1,i=2; i<=h; i++)  
  256.         if(a[i])  
  257.             for(j=a[i]; j; t*=i,j--)  
  258.                 if(t*i>DEPTH)  
  259.                     mul(b,t),t=1 ;  
  260.     mul(b,t);  
  261. }  
  262. /************************************************************************/  
  263. /* 组合数                                                               */  
  264. /************************************************************************/  
  265. void combination(bignum_t a,int m,int n)  
  266. {  
  267.     int*t=new int[m+1];  
  268.     memset((void*)t,0,sizeof(int)*(m+1));  
  269.     comp(t,n+1,m,1);  
  270.     comp(t,2,m-n,-1);  
  271.     convert(t,m,a);  
  272.     delete[]t ;  
  273. }  
  274. /************************************************************************/  
  275. /* 排列数                                                               */  
  276. /************************************************************************/  
  277. void permutation(bignum_t a,int m,int n)  
  278. {  
  279.     int i,t=1 ;  
  280.     memset(a,0,sizeof(bignum_t));  
  281.     a[0]=a[1]=1 ;  
  282.     for(i=m-n+1; i<=m; t*=i++)  
  283.         if(t*i>DEPTH)  
  284.             mul(a,t),t=1 ;  
  285.     mul(a,t);  
  286. }  
  287.   
  288. #define SGN(x) ((x)>0?1:((x)<0?-1:0))  
  289. #define ABS(x) ((x)>0?(x):-(x))  
  290.   
  291. int read(bignum_t a,int&sgn,istream&is=cin)  
  292. {  
  293.     char str[MAX*DIGIT+2],ch,*buf ;  
  294.     int i,j ;  
  295.     memset((void*)a,0,sizeof(bignum_t));  
  296.     if(!(is>>str))return 0 ;  
  297.     buf=str,sgn=1 ;  
  298.     if(*buf=='-')sgn=-1,buf++;  
  299.     for(a[0]=strlen(buf),i=a[0]/2-1; i>=0; i--)  
  300.         ch=buf[i],buf[i]=buf[a[0]-1-i],buf[a[0]-1-i]=ch ;  
  301.     for(a[0]=(a[0]+DIGIT-1)/DIGIT,j=strlen(buf); j<a[0]*DIGIT; buf[j++]='0');  
  302.     for(i=1; i<=a[0]; i++)  
  303.         for(a[i]=0,j=0; j<DIGIT; j++)  
  304.             a[i]=a[i]*10+buf[i*DIGIT-1-j]-'0' ;  
  305.     for(; !a[a[0]]&&a[0]>1; a[0]--);  
  306.     if(a[0]==1&&!a[1])sgn=0 ;  
  307.     return 1 ;  
  308. }  
  309. struct bignum  
  310. {  
  311.     bignum_t num ;  
  312.     int sgn ;  
  313. public :  
  314.     inline bignum()  
  315.     {  
  316.         memset(num,0,sizeof(bignum_t));  
  317.         num[0]=1 ;  
  318.         sgn=0 ;  
  319.     }  
  320.     inline int operator!()  
  321.     {  
  322.         return num[0]==1&&!num[1];  
  323.     }  
  324.     inline bignum&operator=(const bignum&a)  
  325.     {  
  326.         memcpy(num,a.num,sizeof(bignum_t));  
  327.         sgn=a.sgn ;  
  328.         return*this ;  
  329.     }  
  330.     inline bignum&operator=(const int a)  
  331.     {  
  332.         memset(num,0,sizeof(bignum_t));  
  333.         num[0]=1 ;  
  334.         sgn=SGN (a);  
  335.         add(num,sgn*a);  
  336.         return*this ;  
  337.     }  
  338.     ;  
  339.     inline bignum&operator+=(const bignum&a)  
  340.     {  
  341.         if(sgn==a.sgn)add(num,a.num);  
  342.         else if  
  343.         (sgn&&a.sgn)  
  344.         {  
  345.             int ret=comp(num,a.num);  
  346.             if(ret>0)sub(num,a.num);  
  347.             else if(ret<0)  
  348.             {  
  349.                 bignum_t t ;  
  350.                 memcpy(t,num,sizeof(bignum_t));  
  351.                 memcpy(num,a.num,sizeof(bignum_t));  
  352.                 sub (num,t);  
  353.                 sgn=a.sgn ;  
  354.             }  
  355.             else memset(num,0,sizeof(bignum_t)),num[0]=1,sgn=0 ;  
  356.         }  
  357.         else if(!sgn)  
  358.             memcpy(num,a.num,sizeof(bignum_t)),sgn=a.sgn ;  
  359.         return*this ;  
  360.     }  
  361.     inline bignum&operator+=(const int a)  
  362.     {  
  363.         if(sgn*a>0)add(num,ABS(a));  
  364.         else if(sgn&&a)  
  365.         {  
  366.             int  ret=comp(num,ABS(a));  
  367.             if(ret>0)sub(num,ABS(a));  
  368.             else if(ret<0)  
  369.             {  
  370.                 bignum_t t ;  
  371.                 memcpy(t,num,sizeof(bignum_t));  
  372.                 memset(num,0,sizeof(bignum_t));  
  373.                 num[0]=1 ;  
  374.                 add(num,ABS (a));  
  375.                 sgn=-sgn ;  
  376.                 sub(num,t);  
  377.             }  
  378.             else memset(num,0,sizeof(bignum_t)),num[0]=1,sgn=0 ;  
  379.         }  
  380.         else if  
  381.         (!sgn)sgn=SGN(a),add(num,ABS(a));  
  382.         return*this ;  
  383.     }  
  384.     inline bignum operator+(const bignum&a)  
  385.     {  
  386.         bignum ret ;  
  387.         memcpy(ret.num,num,sizeof (bignum_t));  
  388.         ret.sgn=sgn ;  
  389.         ret+=a ;  
  390.         return ret ;  
  391.     }  
  392.     inline bignum operator+(const int a)  
  393.     {  
  394.         bignum ret ;  
  395.         memcpy(ret.num,num,sizeof (bignum_t));  
  396.         ret.sgn=sgn ;  
  397.         ret+=a ;  
  398.         return ret ;  
  399.     }  
  400.     inline bignum&operator-=(const bignum&a)  
  401.     {  
  402.         if(sgn*a.sgn<0)add(num,a.num);  
  403.         else if  
  404.         (sgn&&a.sgn)  
  405.         {  
  406.             int ret=comp(num,a.num);  
  407.             if(ret>0)sub(num,a.num);  
  408.             else if(ret<0)  
  409.             {  
  410.                 bignum_t t ;  
  411.                 memcpy(t,num,sizeof(bignum_t));  
  412.                 memcpy(num,a.num,sizeof(bignum_t));  
  413.                 sub(num,t);  
  414.                 sgn=-sgn ;  
  415.             }  
  416.             else memset(num,0,sizeof(bignum_t)),num[0]=1,sgn=0 ;  
  417.         }  
  418.         else if(!sgn)add (num,a.num),sgn=-a.sgn ;  
  419.         return*this ;  
  420.     }  
  421.     inline bignum&operator-=(const int a)  
  422.     {  
  423.         if(sgn*a<0)add(num,ABS(a));  
  424.         else if(sgn&&a)  
  425.         {  
  426.             int  ret=comp(num,ABS(a));  
  427.             if(ret>0)sub(num,ABS(a));  
  428.             else if(ret<0)  
  429.             {  
  430.                 bignum_t t ;  
  431.                 memcpy(t,num,sizeof(bignum_t));  
  432.                 memset(num,0,sizeof(bignum_t));  
  433.                 num[0]=1 ;  
  434.                 add(num,ABS(a));  
  435.                 sub(num,t);  
  436.                 sgn=-sgn ;  
  437.             }  
  438.             else memset(num,0,sizeof(bignum_t)),num[0]=1,sgn=0 ;  
  439.         }  
  440.         else if  
  441.         (!sgn)sgn=-SGN(a),add(num,ABS(a));  
  442.         return*this ;  
  443.     }  
  444.     inline bignum operator-(const bignum&a)  
  445.     {  
  446.         bignum ret ;  
  447.         memcpy(ret.num,num,sizeof(bignum_t));  
  448.         ret.sgn=sgn ;  
  449.         ret-=a ;  
  450.         return ret ;  
  451.     }  
  452.     inline bignum operator-(const int a)  
  453.     {  
  454.         bignum ret ;  
  455.         memcpy(ret.num,num,sizeof(bignum_t));  
  456.         ret.sgn=sgn ;  
  457.         ret-=a ;  
  458.         return ret ;  
  459.     }  
  460.     inline bignum&operator*=(const bignum&a)  
  461.     {  
  462.         bignum_t t ;  
  463.         mul(t,num,a.num);  
  464.         memcpy(num,t,sizeof(bignum_t));  
  465.         sgn*=a.sgn ;  
  466.         return*this ;  
  467.     }  
  468.     inline bignum&operator*=(const int a)  
  469.     {  
  470.         mul(num,ABS(a));  
  471.         sgn*=SGN(a);  
  472.         return*this ;  
  473.     }  
  474.     inline bignum operator*(const bignum&a)  
  475.     {  
  476.         bignum ret ;  
  477.         mul(ret.num,num,a.num);  
  478.         ret.sgn=sgn*a.sgn ;  
  479.         return ret ;  
  480.     }  
  481.     inline bignum operator*(const int a)  
  482.     {  
  483.         bignum ret ;  
  484.         memcpy(ret.num,num,sizeof (bignum_t));  
  485.         mul(ret.num,ABS(a));  
  486.         ret.sgn=sgn*SGN(a);  
  487.         return ret ;  
  488.     }  
  489.     inline bignum&operator/=(const bignum&a)  
  490.     {  
  491.         bignum_t t ;  
  492.         div(t,num,a.num);  
  493.         memcpy (num,t,sizeof(bignum_t));  
  494.         sgn=(num[0]==1&&!num[1])?0:sgn*a.sgn ;  
  495.         return*this ;  
  496.     }  
  497.     inline bignum&operator/=(const int a)  
  498.     {  
  499.         int t ;  
  500.         div(num,ABS(a),t);  
  501.         sgn=(num[0]==1&&!num [1])?0:sgn*SGN(a);  
  502.         return*this ;  
  503.     }  
  504.     inline bignum operator/(const bignum&a)  
  505.     {  
  506.         bignum ret ;  
  507.         bignum_t t ;  
  508.         memcpy(t,num,sizeof(bignum_t));  
  509.         div(ret.num,t,a.num);  
  510.         ret.sgn=(ret.num[0]==1&&!ret.num[1])?0:sgn*a.sgn ;  
  511.         return ret ;  
  512.     }  
  513.     inline bignum operator/(const int a)  
  514.     {  
  515.         bignum ret ;  
  516.         int t ;  
  517.         memcpy(ret.num,num,sizeof(bignum_t));  
  518.         div(ret.num,ABS(a),t);  
  519.         ret.sgn=(ret.num[0]==1&&!ret.num[1])?0:sgn*SGN(a);  
  520.         return ret ;  
  521.     }  
  522.     inline bignum&operator%=(const bignum&a)  
  523.     {  
  524.         bignum_t t ;  
  525.         div(t,num,a.num);  
  526.         if(num[0]==1&&!num[1])sgn=0 ;  
  527.         return*this ;  
  528.     }  
  529.     inline int operator%=(const int a)  
  530.     {  
  531.         int t ;  
  532.         div(num,ABS(a),t);  
  533.         memset(num,0,sizeof (bignum_t));  
  534.         num[0]=1 ;  
  535.         add(num,t);  
  536.         return t ;  
  537.     }  
  538.     inline bignum operator%(const bignum&a)  
  539.     {  
  540.         bignum ret ;  
  541.         bignum_t t ;  
  542.         memcpy(ret.num,num,sizeof(bignum_t));  
  543.         div(t,ret.num,a.num);  
  544.         ret.sgn=(ret.num[0]==1&&!ret.num [1])?0:sgn ;  
  545.         return ret ;  
  546.     }  
  547.     inline int operator%(const int a)  
  548.     {  
  549.         bignum ret ;  
  550.         int t ;  
  551.         memcpy(ret.num,num,sizeof(bignum_t));  
  552.         div(ret.num,ABS(a),t);  
  553.         memset(ret.num,0,sizeof(bignum_t));  
  554.         ret.num[0]=1 ;  
  555.         add(ret.num,t);  
  556.         return t ;  
  557.     }  
  558.     inline bignum&operator++()  
  559.     {  
  560.         *this+=1 ;  
  561.         return*this ;  
  562.     }  
  563.     inline bignum&operator--()  
  564.     {  
  565.         *this-=1 ;  
  566.         return*this ;  
  567.     }  
  568.     ;  
  569.     inline int operator>(const bignum&a)  
  570.     {  
  571.         return sgn>0?(a.sgn>0?comp(num,a.num)>0:1):(sgn<0?(a.sgn<0?comp(num,a.num)<0:0):a.sgn<0);  
  572.     }  
  573.     inline int operator>(const int a)  
  574.     {  
  575.         return sgn>0?(a>0?comp(num,a)>0:1):(sgn<0?(a<0?comp(num,-a)<0:0):a<0);  
  576.     }  
  577.     inline int operator>=(const bignum&a)  
  578.     {  
  579.         return sgn>0?(a.sgn>0?comp(num,a.num)>=0:1):(sgn<0?(a.sgn<0?comp(num,a.num)<=0:0):a.sgn<=0);  
  580.     }  
  581.     inline int operator>=(const int a)  
  582.     {  
  583.         return sgn>0?(a>0?comp(num,a)>=0:1):(sgn<0?(a<0?comp(num,-a)<=0:0):a<=0);  
  584.     }  
  585.     inline int operator<(const bignum&a)  
  586.     {  
  587.         return sgn<0?(a.sgn<0?comp(num,a.num)>0:1):(sgn>0?(a.sgn>0?comp(num,a.num)<0:0):a.sgn>0);  
  588.     }  
  589.     inline int operator<(const int a)  
  590.     {  
  591.         return sgn<0?(a<0?comp(num,-a)>0:1):(sgn>0?(a>0?comp(num,a)<0:0):a>0);  
  592.     }  
  593.     inline int operator<=(const bignum&a)  
  594.     {  
  595.         return sgn<0?(a.sgn<0?comp(num,a.num)>=0:1):(sgn>0?(a.sgn>0?comp(num,a.num)<=0:0):a.sgn>=0);  
  596.     }  
  597.     inline int operator<=(const int a)  
  598.     {  
  599.         return sgn<0?(a<0?comp(num,-a)>=0:1):  
  600.                (sgn>0?(a>0?comp(num,a)<=0:0):a>=0);  
  601.     }  
  602.     inline int operator==(const bignum&a)  
  603.     {  
  604.         return(sgn==a.sgn)?!comp(num,a.num):0 ;  
  605.     }  
  606.     inline int operator==(const int a)  
  607.     {  
  608.         return(sgn*a>=0)?!comp(num,ABS(a)):0 ;  
  609.     }  
  610.     inline int operator!=(const bignum&a)  
  611.     {  
  612.         return(sgn==a.sgn)?comp(num,a.num):1 ;  
  613.     }  
  614.     inline int operator!=(const int a)  
  615.     {  
  616.         return(sgn*a>=0)?comp(num,ABS(a)):1 ;  
  617.     }  
  618.     inline int operator[](const int a)  
  619.     {  
  620.         return digit(num,a);  
  621.     }  
  622.     friend inline istream&operator>>(istream&is,bignum&a)  
  623.     {  
  624.         read(a.num,a.sgn,is);  
  625.         return  is ;  
  626.     }  
  627.     friend inline ostream&operator<<(ostream&os,const bignum&a)  
  628.     {  
  629.         if(a.sgn<0)  
  630.             os<<'-' ;  
  631.         write(a.num,os);  
  632.         return os ;  
  633.     }  
  634.     friend inline bignum sqrt(const bignum&a)  
  635.     {  
  636.         bignum ret ;  
  637.         bignum_t t ;  
  638.         memcpy(t,a.num,sizeof(bignum_t));  
  639.         sqrt(ret.num,t);  
  640.         ret.sgn=ret.num[0]!=1||ret.num[1];  
  641.         return ret ;  
  642.     }  
  643.     friend inline bignum sqrt(const bignum&a,bignum&b)  
  644.     {  
  645.         bignum ret ;  
  646.         memcpy(b.num,a.num,sizeof(bignum_t));  
  647.         sqrt(ret.num,b.num);  
  648.         ret.sgn=ret.num[0]!=1||ret.num[1];  
  649.         b.sgn=b.num[0]!=1||ret.num[1];  
  650.         return ret ;  
  651.     }  
  652.     inline int length()  
  653.     {  
  654.         return :: length(num);  
  655.     }  
  656.     inline int zeronum()  
  657.     {  
  658.         return :: zeronum(num);  
  659.     }  
  660.     inline bignum C(const int m,const int n)  
  661.     {  
  662.         combination(num,m,n);  
  663.         sgn=1 ;  
  664.         return*this ;  
  665.     }  
  666.     inline bignum P(const int m,const int n)  
  667.     {  
  668.         permutation(num,m,n);  
  669.         sgn=1 ;  
  670.         return*this ;  
  671.     }  
  672. };  
  673.   
  674. bignum a[2000],m,nn;  
  675. bignum mod;  
  676. void init()  
  677. {  
  678.     a[0] = 1;  
  679.     a[1] = 1;  
  680.     for(int i=2; i<=1000; ++i)  
  681.     {  
  682.         a[i] = a[i-1] + a[i-2];  
  683.     }  
  684. }  
  685. int num[]= {0,1,0,1,1,2};  
  686. int main()  
  687. {  
  688.     mod=258280327;  
  689.     int t,n;  
  690.     init();  
  691.     scanf("%d",&t);  
  692.     while(t--){  
  693.         scanf("%d",&n);  
  694.         cin>>m;  
  695.         if(n==1&&m==1){//注意!  
  696.             puts("0");  
  697.             continue;  
  698.         }  
  699.         int h1=1;  
  700.         nn=1;  
  701.         int f=0;  
  702.         while(nn<5){  
  703.             if(nn==m){  
  704.                 printf("%d\n",num[h1]);  
  705.                 f=1;  
  706.             }  
  707.             h1++;  
  708.             nn=nn+1;  
  709.         }  
  710.         if(f)   continue;  
  711.         f=0;  
  712.         for(int i=1; i<=1001; i++){  
  713.             if(a[i]==m){  
  714.                 h1=i;  
  715.                 break;  
  716.             }  
  717.             else if(a[i]>m){  
  718.                 if(a[i]==m+1){  
  719.                     cout<<(a[i-2]-1)%mod<<endl;;  
  720.                     f=1;  
  721.                 }  
  722.                 h1=i-1;  
  723.                 break;  
  724.             }  
  725.         }  
  726.         if(f)   continue;  
  727.         cout<<(m-a[h1]+a[h1-2])%mod<<endl;  
  728.     }  
  729.     return 0;  
  730. }  

hdu  5347 

【题意】RT:

Problem Description
MZL define F(X) as the first ionization energy of the chemical element X

Now he get two chemical elements U,V,given as their atomic number,he wants to compare F(U) and F(V)

It is guaranteed that atomic numbers belongs to the given set:{1,2,3,4,..18,35,36,53,54,85,86}

It is guaranteed the two atomic numbers is either in the same period or in the same group

It is guaranteed that xy
 

Input
There are several test cases

For each test case,there are two numbers u,v,means the atomic numbers of the two element
 

Output
For each test case,if F(u)>F(v),print "FIRST BIGGER",else print"SECOND BIGGER"
 

Sample Input
1 25 3
 

Sample Output
SECOND BIGGERFIRST BIGGER
 
      两个化学元素U,V,给出它们的原子序数,比较F(U)和F(V),同一周期或同一族,暴力打表了
代码:
[cpp] view plaincopy
  1. #include <bits/stdc++.h>  
  2. using namespace std;  
  3. map <int ,int >val;  
  4. void init(){  
  5.     val[1]  = 1400;  
  6.     val[2]  = 2300;  
  7.     val[3]  = 520;  
  8.     val[4]  = 899;  
  9.     val[5]  = 800;  
  10.     val[6]  = 1086;  
  11.     val[7]  = 1402;  
  12.     val[8]  = 1313;  
  13.     val[9]  = 1681;  
  14.     val[10] = 2080;  
  15.     val[11] = 495;  
  16.     val[12] = 737;  
  17.     val[13] = 577;  
  18.     val[14] = 786;  
  19.     val[15] = 1011;  
  20.     val[16] = 999;  
  21.     val[17] = 1251;  
  22.     val[18] = 1520;  
  23.     val[35] = 1139;  
  24.     val[36] = 1350;  
  25.     val[53] = 1008;  
  26.     val[54] = 1170;  
  27.     val[85] = 890;  
  28.     val[86] = 1037;  
  29. }  
  30. int main()  
  31. {  
  32.     init();  
  33.     int x,y;  
  34.     while(~scanf("%d %d",&x,&y)){  
  35.         int lx=val[x];  
  36.         int ly=val[y];  
  37.         if(lx>ly) puts("FIRST BIGGER");  
  38.         else puts("SECOND BIGGER");  
  39.     }  
  40.     return 0;  
  41. }  







0 0