UVa:11375 Matches
来源:互联网 发布:mac 16进制编辑器 编辑:程序博客网 时间:2024/06/07 09:07
白书上的例题。用到了大数加法。注意它问的是用n根火柴可以摆成多少个整数,就是说少于n根火柴的时候也是可以的。另外注意前导0的情况。
#include <iostream>#include <cstdio>#include <cstring>#include <string>#include <cmath>#include <vector>#include <queue>#include <algorithm>#define ll long long#define INF 2139062143#define MOD 20071027#define MAXN 20005using namespace std;int v[]= {6,2,5,5,4,5,6,3,7,6};int w[]= {0,0,1,1,1,2,3,1,0,0};void BigAdd(char *a,char *b,char *back){ char c[500]= {0}; int p=0,up=0; for(int i=strlen(a)-1,j=strlen(b)-1; i>=0||j>=0; --i,--j) { int x,y,z; if(i<0) x=0; else x=a[i]-'0'; if(j<0) y=0; else y=b[j]-'0'; z=(x+y+up)%10; up=(x+y+up)/10; c[p++]=z+'0'; } if(up) c[p++]='1'; c[p]=0; int q=0; for(int i=p-1; i>=0; --i) back[q++]=c[i]; if(q==0) back[q++]='0'; back[q]=0;}char f[2010][500];char d[2010][500];char temp[500]= {0};void Init(){ strcpy(d[0],"1"); for(int i=1; i<=2000; ++i)strcpy(d[i],"0"); for(int i=0; i<=2000; ++i) for(int j=0; j<10; ++j) if(!(i==0&&j==0)) BigAdd(d[i+v[j]],d[i],d[i+v[j]]); BigAdd(d[6],"1",d[6]); strcpy(f[0],"0"); for(int i=1; i<=2000; ++i) BigAdd(d[i],f[i-1],f[i]);}int main(){ Init(); int n; while(scanf("%d",&n)!=EOF) puts(f[n]); return 0;}
0 0
- Matches UVA 11375
- uva 11375 - Matches
- UVA 11375 - Matches
- UVA 11375 - Matches
- UVA - 11375 Matches
- UVa:11375 Matches
- UVa 11375 Matches
- UVa 11375 Matches
- Matches(uva 11375)
- UVa 11375 Matches (DP&高精度)
- uva 11375 - Matches(递推)
- UVA - 11375-Matches-dp+高精度
- Matches UVA
- UVA 11375 Matches(递推)
- UVA 11375 Matches (dp+高精度)【模板】
- UVA 11375 - Matches (数学——递推)
- Uva 11375 Matches 解题报告(递推+高精度)
- UVa 11375 - Matches (递推 JAVA 高精度)
- A. Bear and Raspberry
- ubuntu 12.04 alt+tab无法切换窗口的问题
- NSRunloop与NSTimer在IOS开发中如何工作
- JUnit4概述
- 安全技巧:用TCP/IP过滤保护用户计算机
- UVa:11375 Matches
- U3d中的A*算法调试
- Struts2判断GET/POST请求
- scull编译问题
- html5 css3编程语法缩写总结
- 2012蓝桥杯【初赛试题】比酒量
- XCODE5 SVN配置及使用办法
- ALAssetsLibrary详解(转)
- html5 css3缩写语法总结分享