HDU 1592 Half of and a Half(大数)

Half of and a Half

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1179    Accepted Submission(s): 539

Problem Description

Gardon bought many many chocolates from the A Chocolate Market (ACM). When he was on the way to meet Angel, he met Speakless by accident. 
"Ah, so many delicious chocolates! I‘ll get half of them and a half!" Speakless said.
Gardon went on his way, but soon he met YZG1984 by accident....
"Ah, so many delicious chocolates! I‘ll get half of them and a half!" YZG1984 said.
Gardon went on his way, but soon he met Doramon by accident....
"Ah, so many delicious chocolates! I‘ll get half of them and a half!" Doramon said.
Gardon went on his way, but soon he met JGShining by accident....
"Ah, so many delicious chocolates! I‘ll get half of them and a half!" JGShining said.
.
.
.
After had had met N people , Gardon finally met Angel. He gave her half of the rest and a half, then Gardon have none for himself. Could you tell how many chocolates did he bought from ACM?

Input

Input contains many test cases.
Each case have a integer N, represents the number of people Gardon met except Angel. N will never exceed 1000;

Output

For every N inputed, tell how many chocolates Gardon had at first.

Sample Input

2

Sample Output

7

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<algorithm>
 4 using namespace std;
 5 struct node
 6 {
 7     int a[1100];
 8 }s[1010];
 9 int main()
10 {
11     int i,j,t,n;
12     s[0].a[0]=1;
13     for(i=1;i<=1000;i++)
14     {
15         int r=0;
16         for(j=0;j<1000;j++)
17         {
18             s[i].a[j]=s[i-1].a[j]*2+r;
19
20             r=s[i].a[j]/10;
21
22             s[i].a[j]%=10;
23
24         }
25         t=0;
26         while(s[i].a[t]+1>9)
27         {
28             s[i].a[t]=0;
29             t++;
30         }
31         s[i].a[t]+=1;
32     }
33     while(scanf("%d",&n)!=EOF)
34     {
35         for(i=999;i>=0,s[n].a[i]==0;i--);
36         for(j=i;j>=0;j--)
37             printf("%d",s[n].a[j]);
38         printf("\n");
39
40     }
41     return 0;
42 }
时间: 2024-10-29 10:48:09

HDU 1592 Half of and a Half(大数)的相关文章

HDU 2424-Gary&#39;s Calculator(表达式计算+大数)

Gary's Calculator Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 950    Accepted Submission(s): 209 Problem Description Gary has finally decided to find a calculator to avoid making simple cal

HDU 1250 Hat&#39;s Fibonacci(Java大数相加)+讲解

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1250 Problem Description A Fibonacci sequence is calculated by adding the previous two members the sequence, with the first two members being both 1. F(1) = 1, F(2) = 1, F(3) = 1,F(4) = 1, F(n>4) = F(n -

HDU 4919 打表找规律 java大数 map 递归

== oeis: 点击打开链接 瞎了,x.mod(BigInteger.ValueOf(2)).equal( BigInteger.ValueOf(1)) 写成了 x.mod(BigInteger.ValueOf(2)).equal( 1 ) T^T100块没了... import java.math.*; import java.util.*; import static java.lang.System.out; import java.io.*; public class Main { s

[hdu 4933]Miaomiao&#39;s Function 数位DP+大数

Miaomiao's Function Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 79    Accepted Submission(s): 18 Problem Description Firstly , Miaomiao define two functions f(x) , g(x): (K is the smallest

hdu 5666 Segment 俄罗斯乘法或者套大数板子

Segment Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Problem Description Silen August does not like to talk with others.She like to find some interesting problems. Today she finds an interesting problem.She find

HDU Train Problem II (卡特兰数+大数)

Problem Description As we all know the Train Problem I, the boss of the Ignatius Train Station want to know if all the trains come in strict-increasing order, how many orders that all the trains can get out of the railway.   Input The input contains

hdu 1002 A + B Problem II(大数模拟加法)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1002 题目要求:输入t 为测试组数,然后输入两个正数 a,b求和: [思路] 首先,用字符串读入a,b,再将a,b 逆序存到数组中,然后对应位相加就行了,长度小的数要注意补零 倒过来做可以让进位变得方便 ,如果对应位的和大于等于10,就把余数储存在当前位置,后一位加1: [代码] #include <iostream> #include <string> #include <cs

hdu 1568(Fibonacci)(就是大数的斐波那契公式)

Fibonacci Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 3569    Accepted Submission(s): 1627 Problem Description 2007年到来了.经过2006年一年的修炼,数学神童zouyu终于把0到100000000的Fibonacci数列 (f[0]=0,f[1]=1;f[i]

hdu 1002 A + B Problem II(大数)

题意:整数大数加法 思路:大数模板 #include<iostream> #include<stdio.h> #include<stdlib.h> #include<string.h> using namespace std; #define MAXN 9999//万进制 #define DLEN 4//4位 class BigNum{ private: int a[500];//可以控制大数位数(500*4) int len;//大数长度 public: