最近AC的一部分题目(水题一堆啊)
来源:互联网 发布:刘家昌华纳知乎 编辑:程序博客网 时间:2024/05/29 07:28
hdu1029,一个简单的dp问题(虽然这个问题貌似不用do唉,囧)
#include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>#define MAXN 500000using namespace std;int main(){ int num,n,index,max; while(scanf("%d",&num)!=EOF) { index=0; for(int i=0;i<num;i++) { scanf("%d",&n); if(index==0) { max=n; index++; } else { max==n?index++:index--; } } printf("%d\n",max); } return 0;}开始MAXN开小了,WA了,然后就没什么了
hdu1007,无脑模板题。。。。
#include <iostream>#include <cstring>#include <cstdio>#include <cstdlib>#include <cmath>using namespace std;const int N=100005;const double MAX=10e100,eps=0.00001;struct Point{double x,y;int index;};Point a[N],b[N],c[N];double closest(Point *,Point *,Point *,int ,int );double dis(Point,Point);int cmp_x(const void *,const void *);int cmp_y(const void *,const void *);int merge(Point *,Point *,int ,int ,int );int main(){ int n,i; double d; while(scanf("%d",&n)!=EOF,n) { for(i=0;i<n;i++) scanf("%lf %lf",&a[i].x,&a[i].y); qsort(a,n,sizeof(a[0]),cmp_x); for(i=0;i<n;i++) a[i].index = i; memcpy(b,a,n*sizeof(a[0])); qsort(b,n,sizeof(b[0]),cmp_y); d=closest(a,b,c,0,n-1); printf("%.2lf\n",d/2); } return 0;}double closest(Point a[],Point b[],Point c[],int p,int q){ if(q-p==1) return dis(a[p],a[q]); if(q-p==2) { double x1=dis(a[p],a[q]); double x2=dis(a[p+1],a[q]); double x3=dis(a[p],a[q+1]); if(x1<x2&&x1<x3) return x1; else if(x2<x3) return x2; else return x3; } int i,j,k,m=(p+q)/2; double d1,d2; for(i=p,j=p,k=m+1;i<=q;i++) if(b[i].index<=m) c[j++]=b[i]; else c[k++]=b[i]; d1=closest(a,c,b,p,m); d2=closest(a,c,b,m+1,q); double dm=min(d1,d2); merge(b,c,p,m,q); for(i=p,k=p;i<=q;i++) if(fabs(b[i].x-b[m].x)<dm) c[k++]=b[i]; for(i=p;i<k;i++) for(j=i+1;j<k&&c[j].y-c[i].y<dm;j++) { double temp=dis(c[i],c[j]); if(temp<dm) dm=temp; } return dm;}double dis(Point p,Point q){ double x1=p.x-q.x,y1=p.y-q.y; return sqrt(x1*x1+y1*y1);}int merge(Point p[],Point q[],int s,int m,int t){ int i,j,k; for(i=s,j=m+1,k=s;i<=m&&j<=t;) { if(q[i].y>q[j].y) p[k++]=q[j],j++; else p[k++]=q[i],i++; } while(i<=m) p[k++]=q[i++]; while(j<=t) p[k++]=q[j++]; memcpy(q+s,p+s,(t-s+1)*sizeof(p[0])); return 0;}int cmp_x(const void *p,const void *q){ double temp=((Point*)p)->x - ((Point*)q)->x; if(temp>0) return 1; else if(fabs(temp)<eps) return 0; else return -1;}int cmp_y(const void *p,const void *q){ double temp=((Point*)p)->y - ((Point*)q)->y; if(temp>0) return 1; else if(fabs(temp)<eps) return 0; else return -1;}
hdu1282,回文数,复习了一下strrev,strcpy,itoa,atoi几个字符串常用函数、
说实话,弄得还挺烦的。。。。估计是我太弱人的原因
#include <iostream>#include <cstring>#include <cstdio>#include <cstdlib>using namespace std;int main(){ int m[10000],time,i; char str1[100],str2[100]; while(cin>>str1) { time=0; memset(m,0,sizeof(m)); m[0]=atoi(str1); strcpy(str2,str1); strrev(str2); while(strcmp(str1,str2)!=0) { time++; m[time]=atoi(str1)+atoi(str2); itoa(m[time],str1,10); strcpy(str2,str1); strrev(str2); } cout<<time<<endl; cout<<m[0]; for(i=1;i<=time;i++) { cout<<"--->"<<m[i]; } cout<<endl; } return 0;}
hdu 1022 ,很无脑的栈应用。。。我做完逆波兰之后做这个没遇到什么压力
#include <iostream>#include <stack>using namespace std;int main(){ int num; string str1,str2; while(cin>>num>>str1>>str2) { int i,j; i=j=0; stack <char> sta; while(i<num) { if(str1[i]==str2[j]) { i++;j++; while(!sta.empty() && str2[j]==sta.top()) { j++;sta.pop(); } } else { sta.push(str1[i++]); } } if(sta.empty()) { cout<<"Yes."<<endl; i=j=0; stack <char> sta; while(i<num) { if(str1[i]==str2[j]) { i++;j++; cout<<"in"<<endl<<"out"<<endl; while(!sta.empty() && str2[j]==sta.top()) { j++;sta.pop(); cout<<"out"<<endl; } } else { sta.push(str1[i++]);cout<<"in"<<endl; } } cout<<"FINISH"<<endl; } else { cout<<"No."<<endl<<"FINISH"<<endl; } } return 0;}
hdu1584 深搜的一道入门题
#include <iostream>#include <string.h>#include <stdio.h>#include <string>#include <cmath>using namespace std;int x,ans,arr[11];bool dir[11];void dfs(int i,int sum){ if(sum>ans) return; if(i==10) { ans=sum; return; } else { for(int m=1;m<=10;m++) { if(!dir[m]) { for(int j=m+1;j<=10;j++) { if(!dir[j]) { dir[m]=1; dfs(i+1,sum+abs(arr[m]-arr[j])); dir[m]=0; break; } } } } }}int main(){ int num;cin>>num; while(num--) { for(int i=1;i<=10;i++) { cin>>x; arr[x]=i; } ans=1000; dfs(1,0); cout<<ans<<endl; } return 0;}
- 最近AC的一部分题目(水题一堆啊)
- 最近鲁的题目
- 我的AC题目清单
- 这是一堆 wrong 懵逼的题目
- 阶段一部分题目
- 最近的c#练习题目
- 最近面试的算法题目
- 最近要做的题目
- 杭电ACM中一部分关于string的题目
- 一堆android面试题目--抄写
- hdu 1301 Jungle Roads 一个很水的题 AC率也可以知道了 但是题目很难理解啊 英语渣o(╯□╰)oKruskal算法
- 各种待AC,待理解的题目
- Uva 上自己AC 的题目
- AC自动机的一些题目及思路
- 获取个人AC的题目代码
- HDU ACM 11 2034 人见人恨的A-B(此题题目有问题,不要纠结代码为何可以AC)
- 最近这一个多月都没怎么做题目,UVA才560AC
- gdfzoj #786 很容易AC的题(AC自动机)
- UVa:10803 Thunder Mountain(floyd求多源最短路)
- 查看CPU是否支持虚拟化
- Linux awk 命令 说明
- js中, opener,self,parent 区别
- 母函数 入门 + 模板
- 最近AC的一部分题目(水题一堆啊)
- This system is not registered with RHN解决方法
- 印度数学家“人脑计算机”夏琨塔拉·戴维 84 岁诞辰
- 天天锻炼身体好!
- /proc/sys/vm/drop_caches
- 跳绳是很好的一项运动!
- Android中java.lang.NoClassDefFoundError自定义jar包导入问题。
- Android优秀开源项目[持续更新~欢迎推荐~]
- 工信部敲定4G发牌吉日:最早本月下旬