c语言编程求大神

作者&投稿:夙面 (若有异议请与网页底部的电邮联系)
#include <cstdio>

int main() {
int n; scanf("%d", &n);
int a = 0, b = 1;
for (int i = 1; i <= n; ++ i) {
int c = (a + b) % 10007;
a = b;
b = c;
}
printf("%d
", a);
return 0;
}

O(n)的

#include <iostream>
#include <cstring>
using namespace std;

const int mod = 10007;
const int maxn = 5;

typedef long long LL;
typedef int vector[maxn];
typedef int matrix[maxn][maxn];

int n;

matrix C;
void mulmat(const matrix& A, matrix& B) {
memset(C, 0, sizeof C);
for (int i = 0; i < n; ++ i)
for (int j = 0; j < n; ++ j)
for (int k = 0; k < n; ++ k)
C[i][j] = (C[i][j] + A[i][k] * B[k][j] % mod) % mod;
memcpy(B, C, sizeof C);
}

vector c;
void mulvec(const matrix& A, vector& b) {
memset(c, 0, sizeof c);
for (int i = 0; i < n; ++ i)
for (int k = 0; k < n; ++ k)
c[i] = (c[i] + A[i][k] * b[k] % mod) % mod;
memcpy(b, c, sizeof c);
}

matrix S, T;
void pow(matrix& S, LL n) {
memcpy(T, S, sizeof S);
for (-- n; n; n >>= 1) {
if (n&1) mulmat(T, S);
mulmat(T, T);
}
}

vector A; matrix B;

int main() {
LL m; cin >> m;

B[0][0] = 0, B[0][1] = 1, B[1][0] = 1, B[1][1] = 1;
A[0] = 0, A[1] = 1;
n = 2;

pow(B, m);
mulvec(B, A);

cout >> A[0] >> endl;
return 0;
}

再给个log(n)的。。这个更快,你输入任何一个int64以内的n,即n <= 9,223,372,036,854,775,808,以内的数,瞬秒出解。。。可以用上面的O(n)的对比一下,可以发现下面的这个快得多得多得多。。。。。【也可以和其他回答对比一下的啦-_-

其实可以做的更大。。只不过m是long long...要再大的话可以发信给我。。。

码得很辛苦啊。。。求采纳啊。。。。



#include <cstdio>
#include <vector>

using namespace std;

int solve(vector<int> &V, int n){

if(n == 1 || n == 2) return 1;

if(V[n] != 0) return V[n];

return V[n] = (solve(V, n-1) % 10007 + solve(V, n-2) % 10007) % 10007;
}

int main(){

int n;

scanf("%d", &n);

vector<int> V(n + 1, 0);

printf("%d
", solve(V, n));

return 0;
}


#include "stdafx.h"
#include <iostream>
#include <vector>
using namespace std;

int solve(unsigned int size)
{
    vector<int> fibonacci;
    fibonacci.push_back(1);
    fibonacci.push_back(1);

    for (unsigned int i=2; i<size; i++)
    {
        fibonacci.push_back((fibonacci[i-1]%10007+fibonacci[i-2]%10007)%10007);
    }

    return fibonacci[size-1];
}

int _tmain(int argc, _TCHAR* argv[])
{
    unsigned int size;

    cout<<"请输入Fibonacci序列规模:"<<endl;

    cin>>size;

    cout<<"Fibonacci["<<size<<"]%10007="<<solve(size)<<endl;

    return 0;
}


大学C语言编程,求大神~

#include #include #include #include typedef struct record { char title[64]; char author[24];char isbn[24]; double price; int copies; struct record *next;}Node,*LinkList,*pNode;LinkList InitList() {LinkList head = (pNode)malloc(sizeof(Node));head->title[0] = '\0';head->author[0] = '\0';head->isbn[0] = '\0';head->copies = 0;head->price = 0.0;head->next = NULL;return head;}pNode ReadData() {pNode p = (pNode)malloc(sizeof(Node));fflush(stdin);printf("书 名 : ");gets(p->title);printf("作 者 : ");gets(p->author);printf("图书编号 : ");gets(p->isbn);printf("单 价 : ");scanf("%lf",&p->price);printf("数 量 : ");scanf("%d",&p->copies);return p;}void Add(LinkList head) { // 头插法pNode p = ReadData();p->next = head->next;head->next = p;}void ReadFile(LinkList head) {char filename[60];FILE *inf;int n = 0;pNode p;printf("请输入文件名:");fflush(stdin);fgets(filename,60,stdin);if((inf = fopen(filename,"rb")) == NULL) {printf("无法打开数据文件:%s
",filename);system("pause");return;}p = (pNode)malloc(sizeof(Node));while(fread((void *)p,sizeof(Node),1,inf) == 1) {p->next = head->next;head->next = p;p = (pNode)malloc(sizeof(Node));++n;}free(p);fclose(inf);printf("共读入%d条图书信息!
",n);system("pause");}void ShowData(pNode pnode) {printf("书名 : %s
",pnode->title);printf("作者 : %s
",pnode->author);printf("编号 : %s
",pnode->isbn);printf("单价 : %.2lf元
",pnode->price);printf("数量 : %d本

",pnode->copies);}void PrintBookList(LinkList head) {pNode p = head->next;while(p) {ShowData(p);p = p->next;}system("pause");}void WriteFile(LinkList head) {char filename[60];FILE *outf;int n = 0;pNode p = head->next;printf("请输入文件名:");fflush(stdin);fgets(filename,60,stdin);if((outf = fopen(filename,"wb")) == NULL) {printf("无法打开数据文件:%s
",filename);system("pause");return;}while(p) {fwrite((void *)p,sizeof(Node),1,outf);p = p->next;}fclose(outf);printf("共写出%d条图书信息!
",n);system("pause");}void Sort(LinkList head) { // 选择排序(按ISBN)pNode pt,qt,q,p;for(p = head; p->next; p = p->next) {qt = p;for(q = p->next; q->next; q = q->next)if(strcmp(qt->next->isbn,q->next->isbn) > 0)qt = q;if(p != qt) { // 调整节点位置pt = p->next;p->next = qt->next;qt->next = qt->next->next;p->next->next = pt;}}}int Delete(LinkList head) {pNode p,q;char isbn[50],an[5];printf("请输入欲删除图书ISBN : ");gets(isbn);for(p = head; p->next; p = p->next) {if(strcmp(p->next->isbn,isbn) == 0) {printf("将要删除图书《%s》!
",p->next->title);ShowData(p->next);printf("1、删除,0、放弃!
");printf("请选择 : ");fflush(stdin);fgets(an,5,stdin);if(an[0] == '1') {q = p->next;p->next = q->next;free(q);}return 1;}}printf("对不起,没有找到编号为%s的图书!
",isbn);return 0;}void Modify(LinkList head) {pNode p = head->next;char isbn[50],an[5];int flag;do {printf("欲修改图书编号 : ");fflush(stdin);gets(isbn);flag = 1;while(p) {if(strcmp(isbn,p->isbn) == 0) {p = ReadData();flag = 0;break;}p = p->next;}if(flag) printf("没有找到编号为%s的图书。
",isbn);else printf("修改成功。

");printf("1、继续修改 0、返回主菜单
");fflush(stdin);gets(an);}while(an[0] == '1');}void FreeList(LinkList head) {pNode q,p = head;while(p) {q = p->next;free(p);p = q;}}void Menu(void) {system("cls");printf("**************************************************
");printf("* 1、添加 2、显示 *
");printf("* 3、排序 4、删除 *
");printf("* 5、修改 6、读文件 *
");printf("* 7、写文件 0、退出 *
");printf("**************************************************

");}int main() {int choice;LinkList head = InitList(); do {Menu();printf("请选择 : ");scanf("%d",&choice);switch(choice) {case 1 : Add(head); break;case 2 : PrintBookList(head); break;case 3 : Sort(head); break;case 4 : Delete(head); break;case 5 : Modify(head); break;case 6 : ReadFile(head); break;case 7 : WriteFile(head); break;default : break;}}while(choice);FreeList(head);printf("End!
");return 0;}

#include void fun(char *str){ int i; for(i=0;str[i]!='\0';++i){ if(str[i]>='0'&&str[i]<='8')str[i]++; else if(str[i]=='9')str[i]='0'; }}int main(){ char str[1024]; gets(str); fun(str); puts(str); return 0;}

求C语言程序大神!
答:include <stdio.h> #define N 1000 //预定义员工个数 /*定义员工结构体*/ struct Employee { char ID[20]; char Name[20]; float Mark1; }; /*声明员工数组及员工数量*/ struct Employee Employees[N]; int num=0; /*插入员工信息*/ int Employee_Inse...

用C语言给我编程一下呗!求大神!软妹子什么都不会
答:include<math.h> include <stdio.h> int main(void){ double x;printf("请输入x=");scanf("%lf",&x);if(x <=1.0 && x >0.0)printf("%lf",cos(x)+3.0);if(x > 1.0 && x <1.6)printf("%lf",sin(x)+x);if(x >= 1.6 && x <3.0)printf("%lf",1.0+sqrt(x...

c语言求大神编程
答://#include "stdafx.h"//vc++6.0加上这一行.#include "stdio.h"int main(void){ char i,ci,j,cj,n; printf("Input n(0<n<16)!\nn="); scanf("%d",&n); printf("\n\n"); for(i=1,ci=0;i;++ci<n ? i++ : i--){ for(j=1,cj=i;j;--cj>0...

C语言大神们,求一个编程: 我组织下语言(小学语文老师死的早!)_百度知 ...
答:fp1,-1L,SEEK_END);n=ftell(fp1)+1;ch=fgetc(fp1);while ( n ){ fputc(ch,fp2);fseek(fp1,-2L,SEEK_CUR);n--;ch=fgetc(fp1);} fclose(fp1);fclose(fp2);printf("done!\n");getchar();} VC++6.0上测试通过!注意文件test.txt要自己建立,并和这个可执行程序放在同一目录下!

最简单的c语言编程!!!求大神,急急急,在线等
答:include "stdio.h"float FiveNum(float Num[5]){ float temp; int i; for(i=1;i<5;i++){ if(temp<Num[i]) temp=Num[i]; } return temp; }void main(){ float num[5]; printf("请输入五个数,中间用空格隔开\n"); scanf("%f",&num[0]); ...

跪求大神用C语言编程
答:你给的效果图是不是错了,15公里的费用为:4+12*1.4=20.8 include<stdio.h>int main(){double distance;printf("请输入公里数:");scanf("%lf",&distance);//四舍五入 int temp = (int)(distance+0.5);double money = 4;if (temp<=3){money = 4;}else if (temp<20){money+=...

一个C语言程序问题,看晕了,求大神详解
答:while(y<=5){ if(x>=10)break; // <--- 1 if(x%2==0){ x+=5;continue;} // <--- 2 x-=3; y++; // <--- 3}循环开始,x=1,y=1 第一次循环: 条件1不成立,不会break。条件2不成立,执行3,x=-2, y=2;第二次循环: 条件1不成立。...

又一个c语言编程题,求编程大神帮忙啊!
答:求迷宫问题就是求出从入口到出口的所有路径。在求解时,通常用的是“穷举求解”的方法,即从入口出发,顺某一方向向前试探,若能走通,则继续往前走;否则沿原路退回,换一个方向再继续试探,直至所有可能的通路都试探完为止 include<stdio.h> include<stdlib.h> define M 15 define N 15 struct mark /...

求大神 c语言编程
答:include<stdio.h> include<ctype.h> int main(){int i,j,n=0;char s[200];gets(s);for(i=j=0;s[j];){for(;s[i]&&!isalpha(s[i]);i++);if(!s[i])break;for(j=i+1;isalpha(s[j]);j++);n+=toupper(s[i])==toupper(s[j-1]);i=j;} printf("%d",n);return 0...

汇编语言程序求解,来大神具体给我讲解一下这个程序
答:DW 64 DUP(?)STACK1 ENDS 是定义64字节大小的堆栈段。CODE SEGMENT ASSUME CS:CODE START: MOV SI,3000H ; 将地址 赋给si MOV CX,0008H ;cx中存放循环次数,也是字节个数 XOR AX,AX ;ax清零 CALL branch;调用branch子函数 A5: JMP A5 ;程序结束,一直在此循环 b...