D - Half of and a Half 大数

D - Half of and a Half

Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u

Submit Status Practice HDU 1592

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<string.h>
 3 using namespace std;
 4 int ans[1000][510];
 5 int main()
 6 {
 7     //memset(ans,0,sizeof(ans));
 8     int n,i,j;
 9     while(scanf("%d",&n)!=EOF)
10     {
11
12         //i=300;
13 memset(ans,0,sizeof(ans));
14 ans[500]=1;
15         while(n--)
16         {
17             int c=0;
18             int s=0;
19
20             for(i=500;i>=0;i--)
21             {
22                 if(i==500)
23                  s=ans[i]*2+1+c;
24                  else s=ans[i]*2+c;
25                 ans[i]=s%10;
26                 c=s/10;
27
28             }
29         }
30         for(i=0;i<=500;i++) if(ans[i]!=0) break;
31         j=i;
32         for(j=i;j<=500;j++) printf("%d",ans[j]);
33         printf("\n");
34     }
35     return 0;
36 }

D - Half of and a Half 大数

时间: 2024-10-23 11:33:34

D - Half of and a Half 大数的相关文章

最短的计算大数乘法的c程序

#include <stdio.h> char s[99],t[99]; int m,n; void r(int i,int c) { int j=0,k=i; while(k)c+=s[j++]*t[k---1]; if(i)r(i-1,c/10); printf("%d",c%10); } void main() { gets(s);gets(t); while(s[n])s[n++]-=48; while(t[m])t[m++]-=48; r(m+n-1,0); }

light oj 1236 【大数分解】

给定一个大数,分解质因数,每个质因子的个数为e1,e2,e3,--em, 则结果为((1+2*e1)*(1+2*e2)--(1+2*em)+1)/2. //light oj 1236 大数分解素因子 #include <stdio.h> #include <iostream> #include <string.h> #include <algorithm> #include <math.h> #include <ctype.h> #i

nyoj 73 比大小 【java大数】

java大数. 代码: import java.util.Scanner; import java.math.*; public class Main{ public static void main(String[] args){ Scanner cin = new Scanner(System.in); BigInteger a, b; BigInteger t = BigInteger.valueOf(0); a = cin.nextBigInteger(); b = cin.nextBi

uva 1478 - Delta Wave(递推+大数+卡特兰数+组合数学)

题目链接:uva 1478 - Delta Wave 题目大意:对于每个位置来说,可以向上,水平,向下,坐标不能位负,每次上下移动最多为1, 给定n问说有多少种不同的图.结果对10100取模. 解题思路:因为最后都要落回y=0的位置,所以上升的次数和下降的次数是相同的,并且上升下降的关系满足出栈入栈的关系.即卡特兰数. 所以每次枚举i,表示有i个上升,i个下降,用组合数学枚举出位置,然后累加求和. C(2?in)?f(i)=C(2?i?2n)?f(i?1)?(n?2?i+1)?(n?2?i+2)

各类大数模板

ps:转自http://blog.csdn.net/y990041769/article/details/20116995 大数加法模板(本人验证过,其他还没用,只是写在这) 1 string sum(string s1,string s2) 2 { 3 if(s1.length()<s2.length()) 4 { 5 string temp=s1; 6 s1=s2; 7 s2=temp; 8 } 9 int i,j; 10 for(i=s1.length()-1,j=s2.length()-

【51Nod】1005 大数加法

给出2个大整数A,B,计算A+B的结果. Input 第1行:大数A 第2行:大数B (A,B的长度 <= 10000 需注意:A B有可能为负数) Output 输出A + B Input示例 68932147586 468711654886 Output示例 537643802472 ==================================================================================================== 问题解法

HDU 1018 大数(求N!的位数/相加)

Big Number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 35382    Accepted Submission(s): 16888 Problem Description In many applications very large integers numbers are required. Some of these

java-两个大数相加

题目要求:用字符串模拟两个大数相加. 一.使用BigInteger类.BigDecimal类 public static void main(String[] args) { String a="8888899999999888";  String b="88888888888888";  String str=new BigInteger(a).add(new BigInteger(b)).toString();  System.out.println(str);

大数乘法

1027 大数乘法 基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题  收藏  关注 给出2个大整数A,B,计算A*B的结果. Input 第1行:大数A 第2行:大数B (A,B的长度 <= 1000,A,B >= 0) Output 输出A * B Input示例 123456 234567 Output示例 28958703552 相关问题 大数加法 0 大数开平方 640 大数进制转换 320 大数除法 320 大数乘法 V2 80 代码: 1 #inclu

菲波那契数的余数------大数

Description 菲波那契数大家可能都已经很熟悉了: f(1)=0 f(2)=1 f(n)=f(n-1)+f(n-2) n>2 因此,当需要其除以某个数的余数时,不妨加一些处理就可以得到. Input 输入数据为一些整数对P.K,P(1 < P < 5000)表示菲波那契数的序号,K( 1 <= K < 15)表示2的幂次方.遇到两个空格隔开的0时表示结束处理. Output 输出其第P个菲波那契数除以2的K次方的余数. Sample Input 6 2 20 10 0