UVA 10519 - !! Really Strange !!(数论,规律)
来源:互联网 发布:用户画像数据建模图片 编辑:程序博客网 时间:2024/06/10 08:51
THE SAMS' CONTEST
Problem 0
!! REALLY STRANGE !!
BACKGROUND
Raju has recently passed BSc. Engineering in Computer Science & Engineering from BUET ( Bangladesh University of Extraordinary Talents), the best university of Bangladesh. After passing, he has been appointed manager of BCS ( Bangladesh Calculation Society ). His first project is to visit a district and then to report the total number of distinct regions there. But, going there, he is astonished to see a very strange phenomena of the local people. He discovered that, the people make their area circular. Every two area have exactly two points to intersect and no three circles intersect in a common point. There are so many people so that it's very hard to calculate total number of distinct regions for Raju. So, only in this case he seeks for your help.
Input
The problem contains multiple test cases. You are given total number of circular area n in separate lines (n<=10100). And you know the number houses in the world can't be fraction or negative. Input is terminated by end of file.
Output
For each line of the input, your correct program should output the value of the total number of regions in separate lines for each value of n.
Sample Input
34
Sample Output
814
题意:给定n,输出n个圆最多能把一平面分割成几块
思路:规律题,注意特判0的情况
代码:
#include <stdio.h>#include <string.h>#define max(a,b) (a)>(b)?(a):(b)#define min(a,b) (a)<(b)?(a):(b)const int N = 2222;const int MAXBIGN = 305;struct bign { int s[MAXBIGN]; int len; bign() {len = 1;memset(s, 0, sizeof(s)); } bign operator = (const char *number) {len = strlen(number);for (int i = 0; i < len; i++)s[len - i - 1] = number[i] - '0';return *this; } bign operator = (const int num) {char number[N];sprintf(number, "%d", num);*this = number;return *this; } bign (int number) {*this = number;} bign (const char* number) {*this = number;} bign operator + (const bign &c){ bign sum;int t = 0;sum.len = max(this->len, c.len);for (int i = 0; i < sum.len; i++) {if (i < this->len) t += this->s[i];if (i < c.len) t += c.s[i];sum.s[i] = t % 10;t /= 10;}while (t) {sum.s[sum.len++] = t % 10;t /= 10;}return sum; }bign operator * (const bign &c){ bign sum; bign zero;if (*this == zero || c == zero)return zero;int i, j;sum.len = this->len + c.len;for (i = 0; i < this->len; i++) {for (j = 0; j < c.len; j ++) {sum.s[i + j] += this->s[i] * c.s[j];}}for (i = 0; i < sum.len; i ++) {sum.s[i + 1] += sum.s[i] / 10;sum.s[i] %= 10;}sum.len ++;while (!sum.s[sum.len - 1]) {sum.len --;}return sum; } bign operator - (const bign &c) {bign ans;ans.len = max(this->len, c.len);int i;for (i = 0; i < c.len; i++) {if (this->s[i] < c.s[i]) {this->s[i] += 10;this->s[i + 1]--;}ans.s[i] = this->s[i] - c.s[i];}for (; i < this->len; i++) {if (this->s[i] < 0) {this->s[i] += 10;this->s[i + 1]--;}ans.s[i] = this->s[i];}while (ans.s[ans.len - 1] == 0) {ans.len--;}if (ans.len == 0) ans.len = 1;return ans; } void put() {if (len == 1 && s[0] == 0) {printf("0");} else {for (int i = len - 1; i >= 0; i--)printf("%d", s[i]);} } bool operator < (const bign& b) const {if (len != b.len)return len < b.len;for (int i = len - 1; i >= 0; i--)if (s[i] != b.s[i])return s[i] < b.s[i];return false; } bool operator > (const bign& b) const { return b < *this; } bool operator <= (const bign& b) const { return !(b < *this); } bool operator >= (const bign& b) const { return !(*this < b); } bool operator != (const bign& b) const { return b < *this || *this < b;} bool operator == (const bign& b) const { return !(b != *this); }};char a[105];int main() {while (~scanf("%s", a)) {bign n = a;bign zero = 0;bign one = 1;bign ans = 2;if (n == zero)printf("1");else {ans = n * (n - one) + ans;ans.put();}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 !! (递推)
- UVA10519 - !! Really Strange !!(数论+高精度)
- Really Strange!!
- !! Really Strange !!
- UVa 10229 - Modular Fibonacci(数论,规律)
- UVA 12050 - Palindrome Numbers(数论+规律)
- UVa 10940 - Throwing cards away II(数论,规律)
- 找规律(约瑟夫的数论问题,uva 1363)
- UVa10519 - !! Really Strange !!
- Vector和ArrayList的比较
- Red Hat Linux 9 安装JDK6
- 浅析JAVA之垃圾回收机制
- BZOJ2243 树链剖分
- Session的底层就是Cookie原理,Cookie禁止后的URL重写
- UVA 10519 - !! Really Strange !!(数论,规律)
- Maven命令详解 模块导入 MyEclipse + Maven开发Web工程的详细配置过程
- TCP/UDP常见端口
- PHP-数据类型转换
- 谷歌应用GoAgent让您自由访问网络(图文教程)
- Fedora 17下交叉编译vlc-2.0.6-win32小记
- 《人月神话》有感之职业的苦恼
- java的学习六点!
- java的注意要点!