UVa 10519 - !! Really Strange !!

题目:一个举行内有n和圆,他们分别互相相交于不同的两个点,问他们把平面分成几部分。

分析:大整数,递推。F(n)= F(n-1)+ 2(n-1)。

如果已经有n-1个圆,加入第n个,分别与前n-1个圆相交生成2(n-1)个交点,把圆分割成2(n-1)段弧;

每段弧会把他所属的区域一分为二,F(n)= n(n-1)+ 2 { 其中,n ≥ 1 }。

说明:注意输入为0特殊处理。

#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cmath>

using namespace std;

char buf[202];
int  number1[202];
int  number2[202];
int  number3[202];

int main()
{
	while (~scanf("%s",buf)) {
		int l = strlen(buf);
		if (l == 1 && buf[0] == '0') {
			printf("1\n");
			continue;
		}

		memset(number1, 0, sizeof(number1));
		memset(number2, 0, sizeof(number2));
		memset(number3, 0, sizeof(number3));
		for (int i = 0; buf[i]; ++ i) {
			number1[l-1-i] = buf[i]-'0';
			number2[l-1-i] = buf[i]-'0';
		}

		number1[0] --;
		for (int i = 0; i < l; ++ i)
			if (number1[i] < 0) {
				number1[i+1] --;
				number1[i] += 10;
			}

		for (int i = 0; i < l; ++ i)
		for (int j = 0; j < l; ++ j)
			number3[i+j] += number1[i]*number2[j];

		number3[0] += 2;
		for (int i = 0; i < 200; ++ i)
			if (number3[i] > 9) {
				number3[i+1] += number3[i]/10;
				number3[i] %= 10;
			}

		int end = 200;
		while (end > 0 && !number3[end]) -- end;

		while (end >= 0) printf("%d",number3[end --]);
		printf("\n");
	}
    return 0;
}
时间: 2024-11-06 13:36:30

UVa 10519 - !! Really Strange !!的相关文章

UVA题目分类

题目 Volume 0. Getting Started 开始10055 - Hashmat the Brave Warrior 10071 - Back to High School Physics 10300 - Ecological Premium 458 - The Decoder 494 - Kindergarten Counting Game 414 - Machined Surfaces 490 - Rotating Sentences 445 - Marvelous Mazes

UVA10519 - !! Really Strange !!(数论+高精度)

10519 - !! Really Strange !!(数论+高精度) 题目链接 题目大意:给你n个圆,每两个圆都有相交的部分,并且相交的两个点都唯一的,不能再和别的圆交于这点.问这样在一个矩形里的相交的n个圆可以产生多少个新的封闭图形.看图会明白的. 解题思路:规律:f(n) = f(n - 1) + 2 ?(n - 1) 最后推的 f(n) = n ? (n - 1) + 2; (n >= 1), 0的时候要特判.n本身就是个大数,结果也是个大数. 代码: import java.util

uva 11529 - Strange Tax Calculation(计数问题)

题目链接:uva 11529 - Strange Tax Calculation 题目大意:给出若干个点,保证随意三点不共线.随意选三个点作为三角行,其它点若又在该三角形内,则算是该三角形内部的点.问全部情况的三角形平均每一个三角形有多少个内部点. 解题思路:三角形的总数非常easy求C(3n),如今就是要求各个三角形内部点的总数.相同我们能够反过来,求每一个点在多少个三角形的内部. 然后我们确定一个点,求该点在多少个三角的内部.剩余n-1个点.能够组成C(3n?1])个三角形,所以仅仅要求出该

UVA 11529 - Strange Tax Calculation(计数问题)

题目链接:11529 - Strange Tax Calculation 题意:平面上n个建筑物,3个建筑物可以组成一个三角形,计算平均每个三角形内有多少个点 思路:问题等价于,求凹四边形的占所有四边形的比例,用O(n^2)的算法,跟 HDU 3629 Convex 这题是一个道理 代码: #include <stdio.h> #include <string.h> #include <math.h> #include <algorithm> using n

UVA - 11529 Strange Tax Calculation

The people living in large citieshave to pay more tax than people living in rural areas. That is because incities people have many facilities, which rural people don't have. Also peoplein large and famous cities tend to pay more tax than people livin

uva 10785 - The Mad Numerologist

题目 Numerology is a science that is used by many people to find out a mans personality, sole purpose of life, desires to experience etc. Some calculations of numerology are very complex, while others are quite simple. You can sit alone at home and do

UVA 14000 Lighting System Design(DP)

You are given the task to design a lighting system for a huge conference hall. After doing a lot of calculation & sketching, you have figured out the requirements for an energy-efficient design that can properly illuminate the entire hall. According

UVA 712(二叉树模拟)

L - S-Trees Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit Status Appoint description:  System Crawler  (2014-04-01) Description  S-Trees  A Strange Tree (S-tree) over the variable set  is a binary tree representing a B

UVA之10361 - Automatic Poetry

Problem I Automatic Poetry Input: standard input Output: standard output Time Limit: 2 seconds Memory Limit: 32 MB "Oh God", Lara Croft exclaims, "it's one of these dumb riddles again!" In Tomb Raider XIV, Lara is, as ever, gunning her