X-man

导航

上一页 1 ··· 43 44 45 46 47 48 49 50 51 ··· 59 下一页

2013年5月30日 #

数论(2)-------扩展欧几里得算法

摘要: 扩展欧几里得算法------求解线性方程ax+by=c1.应用:线性方程ax+by=c ,已知a,b,c,求解x,y.2.基本思路:ax+by=c有解 => c=k*gcd(a,b)=kd(因为d=gcd(a,b)=>d|(ax+by))我们先考虑求解ax+by=d由欧几里得算法,d=bx'+(a mod b)y'=bx'+(a-[a/b]b)y'=ay'+b(x'-[a/b])y'则由上述两式子,我们可以得出 x=y' ,y=x'-[a/b]y'这样子,在欧几里得算法添加x,y变量,最后得到解。(可结 阅读全文

posted @ 2013-05-30 22:22 雨钝风轻 阅读(141) 评论(0) 推荐(0) 编辑

数论(1)-----欧几里得算法

摘要: 一.欧几里得算法------求最大公约数1.公式:gcd(a,b)=gcd(b,a mod b)(a为非负整数,b为正整数)2.证明:思路:两个整数a和b,如果a|b&&b|a(即a,b能互相整除),那么a=b.基础知识准备:A. (a mod b)=a-qb,q=(int)a/b;B. d|a&&d|b => d|(xa+yb) x,y为任意整数C. d|a&&d|b => d|gcd(a,b)过程:(1)证:gcd(a,b)|gcd(b,a mod b)设d=gcd(a,b)=>d|a&&d|b,由A和B知道 阅读全文

posted @ 2013-05-30 22:21 雨钝风轻 阅读(205) 评论(0) 推荐(0) 编辑

hdu 1276 士兵队列训练问题(STL的list)

摘要: #include<stdio.h>#include<list>using namespace std;list<int>li;list<int>::iterator it;int main(){ int _case,n; scanf("%d",&_case); while(_case--) { li.clear(); scanf("%d",&n); for(int i=1; i<=n; i++) li.push_back(i); int k=0; while(li.size()> 阅读全文

posted @ 2013-05-30 21:50 雨钝风轻 阅读(305) 评论(0) 推荐(0) 编辑

hdu 1573 X问题(中国剩余定理应用)

摘要: 题解: 求出除数a[0]……a[m-1]的最小公倍数gcd; 由中国剩余定理在【1,gcd】中存在且仅有一个x满足;#include<stdio.h>#include<string.h>int a[11],b[11];int gcd(int a,int b){ if(b==0)return a; return gcd(b,a%b);}int main(){ int _case; int n,m,i,j,k; scanf("%d",&_case); while(_case--) { memset(a,0,sizeof(a)); ... 阅读全文

posted @ 2013-05-30 20:59 雨钝风轻 阅读(201) 评论(0) 推荐(0) 编辑

hdu 2526 浪漫手机

摘要: 题意: 上一行的3个音符决定下一行的1个音符题解: 查找与替换 选择的输出的保存方式#include<stdio.h>#include<string.h>#include<vector>#include<map>#include<string>#include<iostream>#include<algorithm>using namespace std;string s1,s2;map<string,char>ma;char a[5];int main(){ int _case,m; int x, 阅读全文

posted @ 2013-05-30 17:05 雨钝风轻 阅读(294) 评论(0) 推荐(0) 编辑

hdu 3349 lazy gege

摘要: #include<stdio.h>#include<math.h>int main(){ int _case; double l,a,b; scanf("%d",&_case); while(_case--) { scanf("%lf %lf %lf",&l,&a,&b); if(a<b) { double t=b; b=a; a=t; } double d=sqrt(2.0)*l/2; if(d>=b/2) ... 阅读全文

posted @ 2013-05-30 14:58 雨钝风轻 阅读(211) 评论(0) 推荐(0) 编辑

hdu 1248 寒冰王座

摘要: 题解: 商品单价150,200,350,缩小50倍为3,4,7;(化为更简单的问题模型) 3,4,7可构成3,4,6,7,8,9,10……… 到这里结果呼之欲出^*^;输入的n相应处理:保存余数:yu=n%50; 再缩小50倍:m=n/50;#include<stdio.h>int main(){ int _case,n; scanf("%d",&_case); while(_case--) { scanf("%d",&n); int yu=n%50; int m=n/50; if(m... 阅读全文

posted @ 2013-05-30 13:13 雨钝风轻 阅读(222) 评论(0) 推荐(0) 编辑

hdu 1085 Holding Bin-Laden Captive!

摘要: 题解: 1.若num_1=0,显然答案为1; 2.若num_1!=0;能产生直到2*num_2+num_1; 的数 3.若2*num_2+num_1>=4,则能产生直到5*num_3+2*num_2+num_i的数#include<stdio.h>int main(){ int a,b,c; while(scanf("%d %d %d",&a,&b,&c)!=EOF&&(a!=0||b!=0||c!=0)) { if(a==0) { printf("1\n"); } else if(2*... 阅读全文

posted @ 2013-05-30 12:43 雨钝风轻 阅读(112) 评论(0) 推荐(0) 编辑

hdu 1715 大菲波数

摘要: #include<stdio.h>#include<vector>using namespace std;#define N 1010vector<int>a[N];int fb(){ int i,j,k; int jw; a[1].push_back(1); a[2].push_back(1); for(i=3;i<N;i++) { jw=0; for(j=0,k=0;k<a[i-2].size();j++,k++) { //a[i][j]+=jw; int t=a[i-... 阅读全文

posted @ 2013-05-30 09:17 雨钝风轻 阅读(259) 评论(0) 推荐(0) 编辑

2013年5月29日 #

hdu 1405 The Last Practice 输出格式需注意

摘要: #include<stdio.h>#include<string.h>#include<vector>#define N 65536using namespace std;int prime[N];bool visit[N];struct node{ int x,y;} cpt;vector<node>v;int num=0;int prim(){ memset(visit,true,sizeof(visit)); for(int i=2; i<=N; i++) { if(visit[i]==true) { num++;... 阅读全文

posted @ 2013-05-29 21:16 雨钝风轻 阅读(155) 评论(0) 推荐(0) 编辑

上一页 1 ··· 43 44 45 46 47 48 49 50 51 ··· 59 下一页