C语言大数据处理
来源:互联网 发布:161端口 编辑:程序博客网 时间:2024/05/19 13:26
Contents
- 1.Description
- 2.Input
- 3.Output
- 4.Sample Input
- 5.Sample Output
- 6.Source
- 7.Code
- 8.note
- 8.1.大数处理
Description
12345
There are many students in PHT School.One day, the headmaster whose name is PigHeader wanted all students stand in a line. He prescribed that girl can not be in single.In other words, either no girl in the queue or more than one girl stands side by side. The case n=4 (n is the number of children) is like FFFF, FFFM, MFFF, FFMM, MFFM, MMFF, MMMM。Here F stands for a girl and M stands for a boy. The total number of queue satisfied the headmaster’s needs is 7.Can you make a program to find the total number of queue with n children?
Input
There are multiple cases in this problem and ended by the EOF. In each case, there is only one integer n means the number of children (1<=n<=1000)
Output
For each test case, there is only one integer means the number of queue satisfied the headmaster’s needs.
Sample Input
123
123
Sample Output
123
124
Source
HDU1297
Code
123456789101112131415161718192021222324252627282930
//// Created by Kevin on 2016/10/16.//#include<stdio.h>int main() {int n;int f[1001][101] = {0};f[0][1] = 1;f[1][1] = 1;f[2][1] = 2;f[3][1] = 4;for (int i = 4; i < 1001; ++i) {for (int j = 1; j < 101; ++j) {f[i][j] += f[i - 1][j] + f[i - 2][j] + f[i - 4][j]; //数组的每一位相加f[i][j + 1] += f[i][j] / 10000; //超过4位的部分保存至数组下一位中f[i][j] %= 10000; //每位数组只保存其中4位}}while (scanf("%d", &n) != EOF) {int k = 100;while (!f[n][k--]); //排除前面为空的数组printf("%d", f[n][k + 1]); //输出结果的前四位for (; k > 0; --k) {printf("%04d", f[n][k]); //输出其余的所有四位数字,若数字小于四位,则前面用0填充}printf("\n");}return 0;}
note
a.男孩,任何n - 1的合法队列追加1个男孩必然是合法的,情况数为f[n - 1];
b.女孩,在前n - 1的以女孩为末尾的队列后追加1位女孩也是合法的,我们可以转化为n - 2的队列中追加2位女孩;
一种情况是在n - 2的合法队列中追加2位女孩,情况数为f[n - 2];
但注意到可能前n - 2位以女孩为末尾的不合法队列(即单纯以1位女孩结尾),也可以追加2位女孩成为合法队列,而这种n - 2不合法队列必然是由n - 4合法队列+1男孩+1女孩的结构,即情况数为f[n - 4]。
大数处理
本题数据量极大,无法用任何数据类型直接存储,于是采用二维数组模拟大数运算,每一位单独相加,每位数组只保存其中4位。
0 0
- C语言大数据处理
- c语言、c++、大数据处理
- 五、C语言基本数据处理
- (C语言)ACM中的数据处理问题!
- 【C语言】PCM音频数据处理---降低采样率
- 巩固C语言(十一)----文件的数据处理
- 大数据处理需要用到的编程语言开发语言
- 大数据处理
- 大数据处理
- 大数据处理
- 大数据处理
- 大数据处理
- 大数据处理
- 大数据处理
- 大数据处理
- 大数据处理
- 大数据处理
- 大数据处理
- 数据库操纵语言DML
- IOS使用Jenkins进行持续集成
- Python IDE
- Emmet html快速编写神器
- Java IO编程(1)
- C语言大数据处理
- 2016 Android setContentView LayoutInflater 加载 原理
- 关于android6.0权限适配6.0系统以下的问题总结(二维码扫描)
- ruby字符串同时删除前后两个字符
- 百度地图开发API
- Hibernate(四)基于注解annotation的配置
- 办公时怎么样能轻松把ppt转换成word格式
- 关于APUE第十六章的客户端程序返回Servname not supported for ai_socktype错误的解决方法
- java bean复制