Problem A
Accepts: 1829
Time Limit: 2000/1000 MS (Java/Others)
Memory Limit: 65536/65536 K (Java/Others)
第一题....线段树 或者 前缀积+逆元...
代码:
1 #include <vector> 2 #include <map> 3 #include <set> 4 #include <algorithm> 5 #include <iostream> 6 #include <cstdio> 7 #include <cmath> 8 #include <cstdlib> 9 #include <string> 10 #include <cstring> 11 #include <queue> 12 #include <stack> 13 using namespace std; 14 15 #define MOD 9973 16 typedef long long LL; 17 char str[100010]; 18 int f[100010]; 19 20 LL qpow(LL x,LL k) 21 { 22 LL res = 1; 23 while(k){ 24 if(k & 1) 25 res=res*x%MOD; 26 x=x*x%MOD; 27 k>>=1; 28 } 29 return res; 30 } 31 LL inv(LL a,LL x) 32 { 33 return qpow(a,x-2); 34 } 35 36 int main() 37 { 38 int a,b,n; 39 while(~scanf("%d",&n)){ 40 scanf("%s",str); 41 int len=strlen(str); 42 for(int i=0;i<len;i++) 43 f[i+1]=(int)str[i]-28; 44 for(int i=2;i<=len;i++) 45 f[i]=(f[i-1]*f[i])%MOD; 46 47 f[0]=1; 48 49 for(int i=0; i<n; i++){ 50 scanf("%d %d",&a,&b); 51 int ans=(f[b]*inv(f[a-1],MOD))%MOD; 52 printf("%d ",ans); 53 } 54 } 55 return 0; 56 }
Problem B
Accepts: 2515
Time Limit: 2000/1000 MS (Java/Others)
Memory Limit: 65536/65536 K (Java/Others)
Fib大数处理...
代码:
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 using namespace std; 5 6 string sum(string s1,string s2) 7 { 8 if(s1.length()<s2.length()) 9 { 10 string temp=s1; 11 s1=s2; 12 s2=temp; 13 } 14 int i,j; 15 for(i=s1.length()-1,j=s2.length()-1;i>=0;i--,j--) 16 { 17 s1[i]=char(s1[i]+(j>=0?s2[j]-'0':0)); //注意细节 18 if(s1[i]-'0'>=10) 19 { 20 s1[i]=char((s1[i]-'0')%10+'0'); 21 if(i) s1[i-1]++; 22 else s1='1'+s1; 23 } 24 } 25 return s1; 26 } 27 int main(){ 28 string s1[210]; 29 int n; 30 s1[0]="0";s1[1]="1"; 31 for(int i=2; i<201; ++i){ 32 s1[i]=sum(s1[i-1],s1[i-2]); 33 } 34 while(scanf("%d",&n)!=EOF){ 35 cout<<s1[n+1]<<endl; 36 } 37 38 return 0; 39 }
Problem C
Accepts: 832
Time Limit: 2000/1000 MS (Java/Others)
Memory Limit: 131072/131072 K (Java/Others)