Shirlies
宁静专注认真的程序媛~
02 2012 档案
hdu 3293
摘要:这一题死的很悲剧,就n值问题,起初我还一直以为是排序的cmp出问题了,检查它,却忽略了后面的检查……呜呜~~~~(>_<)~~~~ 竟然wa了那么多次,而且用了那么长时间,如此基础的题目,看来我检查错误的能力还有待改善啊~~~View Code #include <cstdio>#include <cstdlib>#include <string>using namespace std;struct node{ char a1[100]; char b1[100]; char c1[100];}in[1000];int cmp(const voi 阅读全文
posted @ 2012-02-28 23:21 Shirlies 阅读(193) 评论(0) 推荐(0) 编辑
uva 784
摘要:#include <iostream>#include <cstdio>#include <cstring>using namespace std;char maze[31][81];char s[81];int xx,yy;int dx[4]={-1,0,1,0};int dy[4]={0,1,0,-1};void dfs(int x,int y);int main(){int T;char ch;char a[82];int k=0;scanf("%d",&T);getchar();while(T--){int i=0,j;x 阅读全文
posted @ 2012-02-23 21:05 Shirlies 阅读(180) 评论(0) 推荐(0) 编辑
hdu 2531
摘要:起初没有看懂题目,无处下手,就去翻翻别人的代码,才知道题目的意思,汗……简单的一般的广搜的变形,这个解释的比较详细http://blog.csdn.net/swm8023/article/details/6765219虽然知道怎么做了,但是还是犯错误,最后与上面这份代码比较之后才找出错误#include <iostream>#include <cstring>#include <queue>using namespace std;char map[102][102];int vis[102][102];int n,m,time,ans;int fx[21], 阅读全文
posted @ 2012-02-22 22:35 Shirlies 阅读(289) 评论(0) 推荐(0) 编辑
hdu 2102
摘要:虽然多了一层,但是还是比较基础的搜索题目,在T时间内,其实只要求出最小时间就可以了,然后比较两者,既然是求最小的时间,那么用广搜就比较好了……#include <iostream>#include <cstring>#include <queue>using namespace std;struct node{int f;int x,y;}n1;char map[2][12][12];int vis[2][12][12];int n,p,t,time;int dx[4]={-1,0,1,0};int dy[4]={0,1,0,-1};int fp,xp,yp 阅读全文
posted @ 2012-02-21 19:13 Shirlies 阅读(456) 评论(0) 推荐(0) 编辑
hdu 1732
摘要:参考http://blog.sina.com.cn/s/blog_622684e80100n3gz.html 阅读全文
posted @ 2012-02-21 11:59 Shirlies 阅读(168) 评论(0) 推荐(0) 编辑
hdu 1372
摘要:广搜无语,结构体竟然犯错,害我找问题……#include <iostream>#include <queue>using namespace std;typedef struct{char c1,c2;}node;node n1,n2,at;int dx[8]={-2,-1,1,2,2,1,-1,-2};int dy[8]={1,2,2,1,-1,-2,-2,-1};int main(){node m;int x,y;int vis[10][10];while(cin>>n1.c1>>n1.c2>>n2.c1>>n2.c2 阅读全文
posted @ 2012-02-20 21:41 Shirlies 阅读(268) 评论(0) 推荐(0) 编辑
hdu 1548
摘要:才开始搞杭电的搜索的题目(这一题算是第二道),首先看到这题,毫不客气的用了深搜,悲剧咯,栈溢出,网上搜了一看,晕,要广搜,好吧,第一次用stl的队列,写完了,样例过了,但是WA了,无语,真的没有发现什么错误啊,拿别人的代码看看,思路大致差不多啊,怎么啦,改了改又提交还是WA,不明所以,在研究这份代码的时候,忽然发现哪里错了,郁闷,貌似是习惯了c语言,把一切东西都定义在一堆,那个队列也定义在前面了,在进行下次数据测试的时候,那个队列并没有清空!#include <iostream>#include <cstring>#include <queue>using 阅读全文
posted @ 2012-02-20 20:11 Shirlies 阅读(885) 评论(0) 推荐(0) 编辑
hdu 2438
摘要:数学啊!http://apps.hi.baidu.com/share/detail/16843204代码就不贴了,这一题让我惭愧,不说了…… 阅读全文
posted @ 2012-02-20 00:02 Shirlies 阅读(253) 评论(0) 推荐(0) 编辑
hdu 1969
摘要:这一题起初我连题目都没有看懂,汗,貌似最近自己对题目的理解有点障碍啊,得多多看书了,最好拿本英文书阅读,泪崩啊……郁闷中,理解题目了,但是没有头绪,不知道这一题哪里是二分题目了,茫然中搜了题解http://www.cnblogs.com/newpanderking/archive/2011/08/24/2152576.html自卑啊,也明白了并不是学到了什么就一定会用!要灵活变化啊~~~#include "stdio.h"#include "math.h"#define pi acos(-1.0)//!!#define er 1e-6double are 阅读全文
posted @ 2012-02-19 21:03 Shirlies 阅读(614) 评论(0) 推荐(0) 编辑
hdu 2141
摘要:晕,这一题我是准备暴力的,但是这里给的数据有点大,那样是会TLE的,网上搜搜,无语啦,竟然可以这样来思考:合并前两个数组,然后再二分……#include "stdio.h"#include "stdlib.h"int li[505];int mi[505];int ni[505];int join[250005];int cmp(const void *a,const void *b){int *c,*d;c=(int *)a;d=(int *)b;return *c-*d;}int main(){int l,m,n;int s;int count=1; 阅读全文
posted @ 2012-02-19 17:07 Shirlies 阅读(560) 评论(0) 推荐(0) 编辑
hdu 1597
摘要:这一题摔的有点惨,为嘛?首先是题目看错了,还以为是数据范围的问题,改成__int64,总共wa了两次,在仔细看题目,汗……我应该取模的,好吧,取了模,还是Wa了,额……怎么了,网上翻了别人的代码,哦哦,数据范围有问题,刚才改的时候,又改回成int了,好了,a了。其实这一题蛮简单的,就是找规律……#include "stdio.h"#include "math.h"int main(){int T;__int64 n,k;scanf("%d",&T);while(T--){scanf("%I64d",& 阅读全文
posted @ 2012-02-19 15:33 Shirlies 阅读(459) 评论(0) 推荐(0) 编辑
hdu 2178
摘要:对这一题表示无语……#include "stdio.h"#include "math.h"int main(){int T;int n;scanf("%d",&T);while(T--){scanf("%d",&n);printf("%d\n",(int)pow(2,n)-1);}return 0;} 阅读全文
posted @ 2012-02-19 12:31 Shirlies 阅读(156) 评论(0) 推荐(0) 编辑
hdu 2899
摘要:先求导,在二分……#include "stdio.h"#include "math.h"#define er 1e-4double get_equ(double x){return 42*pow(x,6)+48*pow(x,5)+21*x*x+10*x;}int main(){int T;double y;double mid,left,right;scanf("%d",&T);while(T--){scanf("%lf",&y);left=0;right=100;mid=50;while(fabs 阅读全文
posted @ 2012-02-19 11:20 Shirlies 阅读(187) 评论(0) 推荐(0) 编辑
hdu 2199
摘要:基本的二分,但是我还是提交了几次,因为那个er开大了,超时了……#include "stdio.h"#include "math.h"#define er 1e-4//这里的er我起初开到了1e-7……超时了……int main(){int T;double n,t,u,d,a;scanf("%d",&T);while(T--){scanf("%lf",&n);n=n-6;if(n<0||n>(8*10000-100+3)*101*100){printf("No solutio 阅读全文
posted @ 2012-02-19 10:33 Shirlies 阅读(260) 评论(0) 推荐(0) 编辑
hdu 1297
摘要:如果在f(n-1)的后面再加一个m,序列仍然是合法的,如果在f(n-2)后面再加一对ff,结果仍然是合法的,还有一种情况来着,就是如果结尾时mf的话,再在后面加f,结果会变成合法的,但是和f(n-2)后加ff重复,所以应该加ff.所以最后就是f(n)=f(n-1)+f(n-2)+f(n-4)了。#include "stdio.h"#include "string.h"char s[1002][400];int main(){int n;int i,j;int len=1,l,carry;int a;char b[400],t;memset(s,0,siz 阅读全文
posted @ 2012-02-16 21:46 Shirlies 阅读(731) 评论(0) 推荐(0) 编辑
hdu 2604
摘要:考虑第n中,如果在第n-1中后面加m的话,就有f(n-1)中,如果加f的话还得考虑f(n-1)末尾的字母,如果f(n-1)末尾两位是mm和mf的话,在后面再加上f是不会出现O型的,mm型的好说,就是f(n-3)的后面加上mm就可以了,如果是mf的话还得考虑必须得是f(n-4)的后面加上mmf,所以总结为f(n)=f(n-1)+f(n-3)+f(n-4).但是这个题目的L值有点大,这一题我是险过的,还差点就超时了……#include "stdio.h"int main(){int l,m;int f[5];int i;while(scanf("%d%d", 阅读全文
posted @ 2012-02-15 21:01 Shirlies 阅读(522) 评论(0) 推荐(0) 编辑
hdu 2563
摘要:分两种情况,如果向上的话就有三种走法,一种向上,一种向左,一种向右,如果是向左(右)走,就有两种走法,一种向上,一种向左(右),然后继续分方向讨论……用一个二维数组,一个存储向上方向的步数,一个存储另外两个方向的步数,最后求和就可以了……#include "stdio.h"int main(){int T,n;__int64 s[2][32]={1,0};int i;for(i=1;i<=30;i++){s[0][i]=s[0][i-1]+s[1][i-1];s[1][i]=2*s[0][i-1]+s[1][i-1];}scanf("%d",&am 阅读全文
posted @ 2012-02-15 19:50 Shirlies 阅读(336) 评论(0) 推荐(0) 编辑
hdu 1133
摘要:看了别人的思路才找到怎么写的……#include "stdio.h"#include "string.h"int fib[210][400];int len=1;void cal_fib(int n){int i,j;int carry=0;memset(fib,0,sizeof(fib));fib[0][0]=1;fib[1][0]=1;len=1;for(i=2;i<=n;i++){carry=0;for(j=0;j<len;j++){fib[i][j]=fib[i-1][j]*i+carry;if(fib[i][j]>=10){c 阅读全文
posted @ 2012-02-15 18:26 Shirlies 阅读(594) 评论(0) 推荐(0) 编辑
hdu 1250
摘要:O(∩_∩)O哈哈~轻松过了,感觉超爽~~~大数是有点令人头疼啊……//#define OJ//搞鬼,vc6不让我定义这个,DEV又有什么木马,被360挡住了……真是纠结……#include "stdio.h"#include "string.h"#define MAX 100000int mem[4][420];int tem[420];int main(){#ifdef OJfreopen("data.in","r",stdin);freopen("data.out","w&quo 阅读全文
posted @ 2012-02-15 16:12 Shirlies 阅读(525) 评论(0) 推荐(0) 编辑
hdu 1005
摘要:这一题用到了快速幂的方法,还有就是构造矩阵……#include "stdio.h"#include "string.h"void mult(int f[2][2],int y[2][2],int c[2][2])//求矩阵相乘{int i;int a[2][2],b[2][2];memcpy(a,f,sizeof(int)*4);//这里也,要将数组复制过来,否则是会出错的,因为传过来的有可能是相同的矩阵相乘……memcpy(b,y,sizeof(int)*4);for(i=0;i<2;i++){c[i][0]=(a[i][0]*b[0][0]+a 阅读全文
posted @ 2012-02-15 14:57 Shirlies 阅读(419) 评论(0) 推荐(0) 编辑
hdu 1018
摘要:数学真是源远流长啊!!现在又有斯特林数log10(n!)=1.0/2*log10(2*pi*n)+n*log10(n/e)现在我对数学的崇拜又加深了!#include "stdio.h"#include "math.h"#define e 2.71828182int main(){int T;int n;double t;scanf("%d",&T);while(T--){scanf("%d",&n);t=(double)n*log10(n*1.0/e)+0.5*log10(2.0*n*3.1415 阅读全文
posted @ 2012-02-14 16:30 Shirlies 阅读(589) 评论(1) 推荐(0) 编辑
hdu 1032
摘要:#include <iostream>using namespace std;int get_count(int a){int count=1;while(a!=1){if(a%2)a=3*a+1;elsea=a/2;count++;}return count;}int main(){int n,m;while(cin>>n>>m){int max=get_count(n);int i,j;if(n>m){i=m;j=n;}else{i=n;j=m;}for(int k=i;k<=j;k++){if(max<get_count(k))max 阅读全文
posted @ 2012-02-13 19:23 Shirlies 阅读(113) 评论(0) 推荐(0) 编辑
hdu 1222
摘要:简单题~~~#include <iostream>using namespace std;int gcd(int a,int b){if(b==0)return a;elsereturn gcd(b,a%b);}int main(){int T;int m,n;cin>>T;while(T--){cin>>m>>n;if(m==1){cout<<"NO"<<endl;continue;}if(gcd(n,m)==1){cout<<"NO"<<endl;}els 阅读全文
posted @ 2012-02-13 18:52 Shirlies 阅读(140) 评论(0) 推荐(0) 编辑
hdu 1568
摘要:经典的数学题啊~~~题解:http://blog.csdn.net/cscj2010/article/details/6768395感触:数学还是得灵活应用啊,关键是这个公式啊……起初是打算用大数做的,觉得好麻烦,就搜了一下,看一下别人的思路,我晕,竟然可以这样思考,NB啊~~~还有就是因为后面约了一个式子,但是这个n得足够大,所以要先存储前面的几个数……#include "stdio.h"#include "math.h"int fib[50]={0,1};int main(){int n,i;double a;double ig,fp;for(i=2 阅读全文
posted @ 2012-02-13 10:53 Shirlies 阅读(491) 评论(0) 推荐(0) 编辑
hdu 1271
摘要:看过别人的解题思路才做出来的,解题思路网上一大片……把这个代码贴出来,是觉得有个问题大家一定要注意,就是可能有重复的值……#include "stdio.h"#include "stdlib.h"#include "string.h"int ans[1000];int cmp(const void *a,const void *b){return (*((int *)a)-*((int *)b));}int main(){int n;int i,k,t,a,b,c;while(scanf("%d",&n)= 阅读全文
posted @ 2012-02-12 11:00 Shirlies 阅读(497) 评论(0) 推荐(0) 编辑
hdu 1687
摘要:敲打代码的时候竟然忘记qsort()怎么用的了……题目大致意思就是求线段投影把x轴分成几段了,之前看过一道例题(刘汝佳编写的《算法入门经典》提到过类似的题目,有类似的思路吧),很类似……#include "stdio.h"#include "stdlib.h"#include "math.h"typedef struct point{ double start,end;}points;points p[120];int s_x,s_y;double get_x(int x,int y){ if(x==s_x) return (doub 阅读全文
posted @ 2012-02-11 20:32 Shirlies 阅读(209) 评论(0) 推荐(0) 编辑
uva 729
摘要:#include <iostream>#include <algorithm>using namespace std;int main(){int t;cin>>t;while(t--){int n,m;cin>>n>>m;char s[20];for(int i=n-1;i>=0;i--){if(n-i<=m)s[i]='1';elses[i]='0';}do{for(int i=0;i<n;i++)cout<<s[i];cout<<endl;}while(n 阅读全文
posted @ 2012-02-05 19:12 Shirlies 阅读(380) 评论(0) 推荐(0) 编辑
uva 10098
摘要:#include <iostream>#include <algorithm>#include <cstring>using namespace std;int main(){int t;cin>>t;while(t--){char s[20];cin>>s;int len=strlen(s);sort(s,s+len);do{cout<<s<<endl;}while(next_permutation(s,s+len));cout<<endl;}return 0;} 阅读全文
posted @ 2012-02-05 18:45 Shirlies 阅读(248) 评论(0) 推荐(0) 编辑
uva 146
摘要:感触:STL真好用~~~#include <iostream>#include <algorithm>#include <cstring>using namespace std;int main(){char s[60];cin>>s;while(s[0]!='#'){int len=strlen(s);if(next_permutation(s,s+len)){cout<<s<<endl;}else{cout<<"No Successor"<<endl;}cin 阅读全文
posted @ 2012-02-05 17:47 Shirlies 阅读(220) 评论(0) 推荐(0) 编辑
uva 11205
摘要:英文一大串,磨死人啊~~~题目大致是想说:找到一个P位的二进制数和给的二进制数与,得到的n个二进制数是不同的,但是呢,这个p位的二进制数1的个数要最小就是了(自己的理解)代码如下://#define LOCAL#include "stdio.h"#include "string.h"int p[150];int s[150][20];int sf[150];int differ(int *p,int m){int i,j;for(i=0;i<m;i++){for(j=i+1;j<m;j++){if(p[i]==p[j])return 0;}} 阅读全文
posted @ 2012-02-05 16:20 Shirlies 阅读(451) 评论(0) 推荐(0) 编辑
UVa 10167
摘要:#include <iostream>#include <string>using namespace std;int coord[120][2];int main(){int n;cin>>n;while(n){for(int i=0;i<(n<<1);i++){cin>>coord[i][0]>>coord[i][1];}for(int i=-500;i<=500;i++)//在vc6中这样定义i是错的,然而在DEV c++和GCC中还必须得这样,否则在uva上提交会编译错误{int re=1;for(in 阅读全文
posted @ 2012-02-05 10:00 Shirlies 阅读(363) 评论(0) 推荐(0) 编辑
uva 297
摘要:#include "stdio.h"#include "stdlib.h"typedef struct nodes{char ch;struct nodes *child[4];}node;char s1[10000];int sum;int pos;node* newnode(){node* t=(node *)malloc(sizeof(node));if(t!=NULL){t->child[0]=t->child[1]=t->child[2]=t->child[3]=NULL;}return t;}void build(no 阅读全文
posted @ 2012-02-04 13:06 Shirlies 阅读(233) 评论(0) 推荐(0) 编辑
uva 712
摘要:晕,这一题我竟然修改了很长时间,汗,关键在自己对字符串处理好像还是不是很熟练#include "stdio.h"#include "math.h"int main(){int n;char ch;char c[300],target[10],re[1000];int count=1;int m,s,i,j;scanf("%d",&n);while(n){getchar();//注意啊!while((ch=getchar())!='\n');fgets(c,sizeof(c),stdin);scanf(" 阅读全文
posted @ 2012-02-03 18:15 Shirlies 阅读(205) 评论(0) 推荐(0) 编辑
uva 548
摘要:二叉树的基本题型,不过对于我来说还是有点考验的……#include "stdio.h"int inorder[10005];int postorder[10005];int sum;int min1,min2;int find(int a,int *p,int n){int i;for(i=n-1;i>=0;i--)if(p[i]==a)return i;return 0;}void tree_min_node(int n,int *d1,int *d2,int sum){int k;if(n<=0) return;k=find(d1[n-1],d2,n);su 阅读全文
posted @ 2012-02-03 12:05 Shirlies 阅读(655) 评论(0) 推荐(0) 编辑
uva 112
摘要:应该是第一次搞二叉树的题目,这一题貌似难度有点大啊,有人的代码写的很简洁易懂,VERY GOOD!也是初次接触cin.clear(),挺有意思的。我个人认为这位解释的比较好http://zhidao.baidu.com/question/252322814.html?fr=qrl&cid=866&index=3还有就是那个好的代码了http://www.sunnybtoc.com/page/M0/S625/625828.html 阅读全文
posted @ 2012-02-02 20:59 Shirlies 阅读(390) 评论(0) 推荐(0) 编辑