hdu----(5047)Sawtooth(大数相乘+数学推导)
2014-09-27 20:39
337 查看
Sawtooth
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 422 Accepted Submission(s): 134
[align=left]Problem Description[/align]
Think about a plane:
● One straight line can divide a plane into two regions.
● Two lines can divide a plane into at most four regions.
● Three lines can divide a plane into at most seven regions.
● And so on...
Now we have some figure constructed with two parallel rays in the
same direction, joined by two straight segments. It looks like a
character “M”. You are given N such “M”s. What is the maximum number of
regions that these “M”s can divide a plane ?
#include<cstdio> #include<cstring> char aa[50],bb[50]; int ans[50]; int mul( char *a, char *b, int temp[]) { int i,j,la,lb,l; la=strlen(a); lb=strlen(b); for ( i=0;i<la+lb;i++ ) temp[i]=0; for ( i=0;i<=la-1;i++ ) { l=i; for ( j=0;j<=lb-1;j++ ) { temp[l]=(b[j]-'0')*(a[i]-'0')+temp[l]; l++; } } while ( temp[l]==0 ) l--; for ( i=0;i<=l;i++ ) { temp[i+1]+=temp[i]/10; temp[i]=temp[i]%10; } if ( temp[l+1]!=0 ) l++; while ( temp[l]/10!=0 ) { temp[l+1]+=temp[l]/10; temp[l]=temp[l]%10; l++; } if ( temp[l]==0 ) l--; return l; } void cal(__int64 a,char *str) { int i=0; while(a>0) { str[i++]=(a%10)+'0'; a/=10; } } int main() { int cas; __int64 n; scanf("%d",&cas); for(int i=1;i<=cas;i++) { scanf("%I64d",&n); printf("Case #%d: ",i); if(n==0)printf("1\n"); else { memset(aa,'\0',sizeof(aa)); memset(bb,'\0',sizeof(bb)); memset(ans,0,sizeof(ans)); //,(8*n-7)*n+1 cal(8*n-7,aa); cal(n,bb); int len=mul(aa,bb,ans); ans[0]++; int c=0; for(int j=0;j<=len;j++) { ans[j]+=c; if(ans[j]>9) { c=ans[j]/10; ans[j]%=10; } } if(c>0) printf("%d",c); for(int j=len;j>=0;j--) printf("%d",ans[j]); printf("\n"); } } return 0; }
View Code
相关文章推荐
- HDU 5047 Sawtooth(数学 公式 大数)
- hdu 5047 Sawtooth 2014 ACM/ICPC Asia Regional Shanghai Online 数学
- Hdu 5047 Sawtooth(数学+大整数)
- HDU 5047 Sawtooth(大数优化+递推公式)
- HDU 5047 Sawtooth(大数模拟)上海赛区网赛1006
- HDU-4919-数学推导加Java大数
- [Java大数+输入输出优化] hdu 5047 Sawtooth
- HDU 5047 Sawtooth (大数模板+找规律)
- Hdu-5047 Sawtooth(C++大数模板)
- HDU 5047 Sawtooth 规律+ C++大数模拟 2014 ACM/ICPC Asia Regional Shanghai Online
- hdu 5047 Sawtooth 组合数学 高精度
- 2014 网选 上海赛区 hdu 5047 Sawtooth
- HDU 4577 X-Boxes (数学+大数除法)
- hdu 1046 数学公式推导
- HDU 1042 N! 大数相乘
- HDU - 5047 Sawtooth
- 【大数问题】 HDOJ 5047 Sawtooth
- HDU——5047 Sawtooth
- Hdu 5047 Sawtooth (平面分割) (2014上海Online)
- 数学_大数求模(HDU_1021)