ural 1108

2024-06-10 17:38
文章标签 ural 1108

本文主要是介绍ural 1108,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

大数乘法    不会java   比赛的时候各种细节RE  WA  ........

#include <cstdio>
#include <cstring>
#include <algorithm>using namespace std;
int un[] = {0,0,0,0,0,1,3,6,13,26,52,104,208,416,833,1667,3335,6700};
int a[10010],b[10010],c[10010],ca;
void cc()
{int w = 0;memset(c, 0, sizeof(c));for(int i = 0; i <= un[ca]; i++){for(int j = 0; j <= un[ca]; j++){c[i+j] += a[i]*b[j];if(c[i+j] > 9999){w = c[i+j]/10000;c[i+j+1] += w;c[i+j] %= 10000;}}}w = 0;for(int i = 0; i <= un[ca]; i++){c[i] += w;w = c[i]/10000;c[i] %= 10000;}memcpy(a, c, sizeof(c));c[0] += 1;memcpy(b, c, sizeof(c));
}
int main()
{int n;scanf("%d",&n);memset(a, 0, sizeof(a));memset(b, 0, sizeof(b));a[0] = 1;b[0] = 2;ca = 0;for(int i = 0; i < n; i++){int j;for(j = un[ca]; j >= 0; j--){if(b[j])break;}//printf("%d\n",j);printf("%d",b[j--]);for(; j >= 0; j--){printf("%.4d",b[j]);}putchar('\n');if(i == n-1)break;cc();ca++;}return 0;
}


这篇关于ural 1108的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1048832

相关文章

ural 1297. Palindrome dp

1297. Palindrome Time limit: 1.0 second Memory limit: 64 MB The “U.S. Robots” HQ has just received a rather alarming anonymous letter. It states that the agent from the competing «Robots Unli

ural 1149. Sinus Dances dfs

1149. Sinus Dances Time limit: 1.0 second Memory limit: 64 MB Let  An = sin(1–sin(2+sin(3–sin(4+…sin( n))…) Let  Sn = (…( A 1+ n) A 2+ n–1) A 3+…+2) An+1 For given  N print  SN Input One

ural 1820. Ural Steaks 贪心

1820. Ural Steaks Time limit: 0.5 second Memory limit: 64 MB After the personal contest, happy but hungry programmers dropped into the restaurant “Ural Steaks” and ordered  n specialty steaks

ural 1017. Staircases DP

1017. Staircases Time limit: 1.0 second Memory limit: 64 MB One curious child has a set of  N little bricks (5 ≤  N ≤ 500). From these bricks he builds different staircases. Staircase consist

ural 1026. Questions and Answers 查询

1026. Questions and Answers Time limit: 2.0 second Memory limit: 64 MB Background The database of the Pentagon contains a top-secret information. We don’t know what the information is — you

ural 1014. Product of Digits贪心

1014. Product of Digits Time limit: 1.0 second Memory limit: 64 MB Your task is to find the minimal positive integer number  Q so that the product of digits of  Q is exactly equal to  N. Inpu

后缀数组 - 求最长回文子串 + 模板题 --- ural 1297

1297. Palindrome Time Limit: 1.0 second Memory Limit: 16 MB The “U.S. Robots” HQ has just received a rather alarming anonymous letter. It states that the agent from the competing «Robots Unlim

【URAL】1057 Amount of Degrees 数位DP

传送门:【URAL】1057 Amount of Degrees 题目分析:将数转化成能达到的最大的01串,串上从右往左第i位为1表示该数包括B^i。 代码如下: #include <cstdio>#include <cstring>#include <algorithm>using namespace std ;typedef long long LL ;#de

【C++题解】1108 - 正整数N转换成一个二进制数

问题三:1108 - 正整数N转换成一个二进制数 类型:字符串、进制转换 题目描述: 输入一个不大于 32767 的整数 n ,将它转换成一个二进制数。 输入: 输入只有一行,包括一个整数 n (0≤n≤32767)。 输出: 输出只有一行。 样例: 输入: 100 输出: 1100100 输入: 0 输出: 0 完整代码如下: #inclu

HDU 1108(最小公倍数)

题意:如题。 #include <iostream>#include <vector>using namespace std;int dd(int x, int y);void main(){vector<vector<int> > tmpbox;unsigned int a;unsigned int b;while (cin >> a >> b){if (a > 100