2012年2月28日

POJ 1328 Radar Installation 贪心

摘要: #include"stdio.h" #include"math.h" #include"stdlib.h" typedef struct { double x1,x2; }POINT; int cmp(const void *a,const void *b) { return (*(POINT *)a).x1>(*(POINT *)b).x1?1:-1; } POINT t[1000]; main() { int n,d,ans,i=0,j,judge,tag; double tx,ty; while(scanf... 阅读全文

posted @ 2012-02-28 20:58 andy_ 阅读(174) 评论(0) 推荐(0)

HDOJ 1039 Easier Done Than Said? 简单的字符串处理

摘要: #include"stdio.h" #include"string.h" int vo(char *psw,int i) {return (psw[i]=='a'||psw[i]=='e'||psw[i]=='i'||psw[i]=='o'||psw[i]=='u');} int main() { char psw[21],ans[2][15]={{"not acceptable"},{"acceptable"}}; while(get 阅读全文

posted @ 2012-02-28 00:55 andy_ 阅读(205) 评论(0) 推荐(0)

HDOJ 1052 Tian Ji -- The Horse Racing 贪心

摘要: 田忌要以最小的代价赢和输对田忌和齐王的马从小到大各自排序,然后以田忌的马从两边对齐王的扫描,如果小的能赢,就赢,如果不能赢,就比两方最大的马,如果能赢则赢,如果也不能赢就用最小的和齐王最大的比掉,注意这里不管是否存在平局都保证了最优选择;#include"stdio.h" #include"algorithm" using namespace std; #define F(i,n) for((i)=0;(i)<(n);i++) int t[1000],q[1000],n,i,ans,ht,tt,hq,tq; main() { while(scanf 阅读全文

posted @ 2012-02-28 00:48 andy_ 阅读(245) 评论(0) 推荐(0)

HDOJ 2602 Bone Collector 01背包问题

摘要: #include"stdio.h" #include"string.h" #include"stdlib.h" #define MAX 1010 int f[MAX],value[MAX],cost[MAX]; main() { int i,v,n,t,j; scanf("%d",&t); while(t--) { scanf("%d%d",&n,&v); memset(f,0,sizeof(f)); ... 阅读全文

posted @ 2012-02-28 00:34 andy_ 阅读(202) 评论(0) 推荐(0)

HDOJ 2099 水

摘要: 学到一种输出策略。#include"stdio.h" main() { int a,b,i,f; while(scanf("%d%d",&a,&b)!=EOF&&(a||b)) { a*=100,f=0; for(i=0;i<100;i++) if((a+i)%b==0) printf(f++?" %02d":"%02d",i); putchar('\n... 阅读全文

posted @ 2012-02-28 00:33 andy_ 阅读(116) 评论(0) 推荐(0)

HDOJ 2037 今年暑假不AC 贪心

摘要: #include"stdio.h" #include"stdlib.h" typedef struct { int s; int e; }ITEM; int cmp(const void *a,const void *b) { return (*(ITEM *)a).e-(*(ITEM *)b).e; } ITEM a[100],t; main() { int n,cnt,i,j; while(scanf("%d",&n)!=EOF&&n) { for(i=0;i<n;i++)scanf... 阅读全文

posted @ 2012-02-28 00:31 andy_ 阅读(133) 评论(0) 推荐(0)

HDOJ 1789 Doing Homework again贪心

摘要: #include"stdio.h" #include"stdlib.h" #include"string.h" typedef struct{ int score,limit; }HWORK; HWORK a[1001]; int flag[1001]; int cmp(const void *a,const void *b) { return (*(HWORK *)b).score-(*(HWORK *)a).score; } main() { int t,n,i,j,ans; scanf("%d",&t 阅读全文

posted @ 2012-02-28 00:29 andy_ 阅读(137) 评论(0) 推荐(0)

HDOJ 1114 Piggy-Bank 完全背包

摘要: #include"stdio.h" //#include"stdlib.h" #define INF 100000000 #define maxn 10010 int p[510],w[510],f[maxn]; int min(int a,int b) {return a<b?a:b;} main() { int a,b,t,i,j,v,n; scanf("%d",&t); while(t--) { scanf("%d%d",&a,&b); ... 阅读全文

posted @ 2012-02-28 00:26 andy_ 阅读(165) 评论(0) 推荐(0)

HDOJ1050 Moving Tables 贪心

摘要: #include"stdio.h" main() { int n,s,e,i,j,t,x,max; scanf("%d",&t); while(t--) { int num[200]={0}; scanf("%d",&n); max=-1; for(i=0;i<n;i++) { scanf("%d%d",&s,&e); ... 阅读全文

posted @ 2012-02-28 00:24 andy_ 阅读(141) 评论(0) 推荐(0)

hdoj 1033 Edge

摘要: 水题 只是题意难懂#include<stdio.h> main() { char s[201]; int i,x,y,d; while(gets(s)!=NULL) { puts("300 420 moveto\n310 420 lineto"); x=310,y=420,d=1; for(i=0;s[i];i++) { if(s[i]=='... 阅读全文

posted @ 2012-02-28 00:22 andy_ 阅读(145) 评论(0) 推荐(0)

HDOJ1022 Train Problem I 栈模拟

摘要: #include"stdio.h" #include"string.h" main() { char in[10],out[10],stack[10],str[2][4]={"out","in"}; int n,i,top,ans[20],j,rear,flag,k; while(scanf("%d %s %s",&n,in,out)!=EOF) { top=0,rear=0,flag=1,k=0,j=0; for(i=0;out[i];i++) ... 阅读全文

posted @ 2012-02-28 00:16 andy_ 阅读(173) 评论(0) 推荐(0)

HDOJ 1016 Prime Ring Problem 简单搜索

摘要: DFS//DFS //真的不能随便用全局变量 #include"stdio.h" #include"string.h" int circle[20],p[40],vis[20]; int n,order=1; void dfs(int c,int cnt) { int i,j; if(cnt==n&&p[1+circle[n]]) { for(j=1;j<n;j++) printf("%d ",circle[j]); printf... 阅读全文

posted @ 2012-02-28 00:14 andy_ 阅读(122) 评论(0) 推荐(0)

HDOJ 1015 Safecracker 简单搜索

摘要: DFS#include"stdio.h" #include"string.h" #include"stdlib.h" int vis[12],flag; int cmp(const void *a,const void *b) { return *(char *)b-*(char *)a;} int mult(char *ans) { int nu=0,x=1,sign=1; for(int i=0;i<5;i++) { for(int j=1;j<=i+1;j++) ... 阅读全文

posted @ 2012-02-28 00:12 andy_ 阅读(270) 评论(0) 推荐(0)

HDOJ1013 Digital Roots

摘要: 简单题 不过discuss 中有一位大牛的代码让我想了好长时间。附上他的代码#include<stdio.h> int main() { int a,c; for(;scanf("%1d",&a),a>0;printf("%d\n",--a%9u+1)) while((c=getchar())-48u<10)// 如果c等于空格那么c-48u(结果为unsigned型)将大于10 a+=c-48; return 0; } 阅读全文

posted @ 2012-02-28 00:06 andy_ 阅读(95) 评论(0) 推荐(0)

HDOJ 1042 N!

摘要: #include"stdio.h" #include"string.h" int a[8000]; main() { int n; while(scanf("%d",&n)!=EOF) { memset(a,0,sizeof(a)); int i,len=1,j; a[0]=1; for(j=2;j<=n;j++) { for(i=0;i<len;i++)a[i]*=j; for(i=0;i<len;i++) if(a[i]>99999){ a[i+1]+=a[i]/100000; a[i]%=1000 阅读全文

posted @ 2012-02-28 00:05 andy_ 阅读(106) 评论(0) 推荐(0)

HDOJ 1024 Max Sum Plus Plus

摘要: ans=max{dp[m,j]}(m<=j<=n)其中dp[m,j]为数组中前j个数的m段的最大和,且第m个段包含a[j];而dp[i][j]=max{dp[i,j-1]+a[j],max{dp[i-1,t]+a[j]}}(i-1=<t<j);dp[i][j]只与dp[i][j-1]及i-1阶段j之前的max(dp[i-1][t])有关,故只保存当前阶段的dp值和用b数组保存上一阶段的最大值#include"stdio.h" #define MIN 0x80000000 #define N 1000001 int a[N],b[N],dp[N]; m 阅读全文

posted @ 2012-02-28 00:00 andy_ 阅读(187) 评论(0) 推荐(0)

导航