UVA 10519 !! Really Strange !!
来源:互联网 发布:qq飞车青峰剃刀数据 编辑:程序博客网 时间:2024/05/29 17:25
题意:n个圆两两相交,将平面分成了几部分,假设已有n-1个圆,那么第n个圆将与前n-1个圆相交2*(n-1)个点,也就是2*(n-1)个弧,而一个弧将产生出一个新的部分,所以:
f(n) = f(n-1) + 2*(n-1),推出公式:f(n) = n^2-n+2,大数,害我错了好几次的是:n=0时的特判
#include <iostream>#include <cstdio>#include <cstring>#include <cmath>#include <algorithm>using namespace std;const int MAXN = 1000000;char n[MAXN];long long p[MAXN],ans[MAXN]; // f(n) = n^2-n+2 // f(0) = 1void pow_big(long long *a,long long *b,int &len){ int i,j; for (i = 0; i < len; i++) for (j = 0; j < len; j++) ans[i+j] += a[i] * b[j]; len *= 2; for (i = 0; i < len; i++){ ans[i+1] += ans[i] / 10; ans[i] %= 10; } while (ans[len] == 0) len--; len++;}void cal(long long *b,int &len){ int i,c=0; ans[0] += 2; if (ans[0] >= 10){ ans[1] += ans[0] / 10; ans[0] %= 10; } for (i = 0; i < len; i++){ ans[i] = ans[i] - b[i] + c; if (ans[i] < 0){ ans[i] += 10; c = -1; } else c = 0; } while (ans[len-1] == 0) len--;}int main(){ while (scanf("%s",n) != EOF){ memset(p,0,sizeof(p)); memset(ans,0,sizeof(ans)); int len = strlen(n); for (int i = 0; i < len; i++) p[i] = n[len-1-i] - '0'; if (p[0] == 0){ printf("1\n"); continue; } pow_big(p,p,len); cal(p,len); for (int i = len-1; i >= 0; i--) printf("%lld",ans[i]); printf("\n"); } return 0;}
- UVA 10519 !! Really Strange !!
- UVA 10519 !! Really Strange !!
- UVa:10519 - !! Really Strange !!
- UVa 10519 - !! Really Strange !!
- UVA 10519 !! Really Strange !!
- UVa 10519 - !! Really Strange !!
- uva 10519!! Really Strange !!
- uva 10519 - !! Really Strange !!(规律)
- UVA 10519 - !! Really Strange !!(数论,规律)
- UVa 10519 !! Really Strange !! (递推)
- Really Strange!!
- !! Really Strange !!
- UVa10519 - !! Really Strange !!
- UVA10519 - !! Really Strange !!(数论+高精度)
- UVA 11529 Strange Tax Calculation
- UVA - 11529 Strange Tax Calculation
- UVA 11529 Strange Tax Calculation
- UVA 11529 - Strange Tax Calculation(计数问题)
- 计算机图形学介绍
- 几种种依赖注入
- linux 系统使用/管理之-----64位装ubuntu win7双系统
- Java之异常与错误的区别及java的异常体系
- UVa 10252 - Common Permutation
- UVA 10519 !! Really Strange !!
- JAVA ThreadLocal
- Examples of JSON encoding
- Ubuntu更新命令
- JQuery mouse..事件+元素显示隐藏 切换 +淡入淡出+滑动效果。(可以做一个ul li下拉框滑动收起效果:slideUp)
- unity参数重载调用
- exit _exit _Exit
- JSON.simple example – Read and write JSON
- Linux远程联机服务器SSH VNC XDMCP RDP