2012年8月21日

USACO sec2.1 Healthy Holsteins

摘要: 状态压缩,先将生成的所有状态排序,然后枚举即可。/*PROG : holsteinLANG : C*/# include <stdio.h># include <stdlib.h>struct scoop{int a[30];};int V, G, r[(1 << 17) + 5];struct scoop g[17], v;/***************************************************/int bcnt(int x){ int ret = 0; while (x) { ++ret; x &= x-1; .. 阅读全文

posted @ 2012-08-21 17:41 getgoing 阅读(291) 评论(0) 推荐(0) 编辑

USACO sec2.1 Ordered Fractions

摘要: 首先两重 for 循环对可能取的值约分,分子分母分别存放,根据比较分数大小的方法排序,然后按顺序输出(相同的只输出一个);/*PROG : frac1LANG : C++*/# include <stdio.h># include <stdlib.h># define MAXN (160 * 160)/***************************************************/int num[MAXN], den[MAXN], r[MAXN], m = 0;int cmp(const void *xx, const void *yy){ in 阅读全文

posted @ 2012-08-21 16:00 getgoing 阅读(293) 评论(0) 推荐(0) 编辑

USACO sec2.1 Hamming Codes

摘要: 直接枚举就行了,不带回溯的搜索。/*PROG : hammingLANG : C++*/# include <stdio.h># define id(x) ((x)>>3)# define of(x) ((x)&0x7)# define get(x) ((h[id(x)]>>of(x))&0x1)# define set(x) (h[id(x)] |= (0x1<<of(x)))int n, b, d;char h[(1<<5) + 1];int sol[70];/*************************** 阅读全文

posted @ 2012-08-21 15:24 getgoing 阅读(227) 评论(0) 推荐(0) 编辑

USACO sec1.5 Checker Challenge

摘要: 八皇后问题,最大输入13,单case,时限1s;和 HDOJ 不同的是:Do not precalculate the value and print it (or even find a formula for it); that's cheating. Work on your program until it can solve the problem properly. If you insist on cheating, your login to the USACO training pages will be removed and you will be disqual 阅读全文

posted @ 2012-08-21 11:32 getgoing 阅读(317) 评论(0) 推荐(0) 编辑

USACO sec1.5 Superprime Rib

摘要: 没打表。/*PROG : sprimeLANG : C++*/# include <stdio.h>/*******************************/char isp(int x){ int i; if (x%2 == 0) return x == 2; if (x%3 == 0) return x == 3; if (x%5 == 0) return x == 5; for (i = 7; i*i < x; i+= 2) if (x%i == 0) return 0; return 1;}void g(int x, int r... 阅读全文

posted @ 2012-08-21 11:07 getgoing 阅读(262) 评论(0) 推荐(0) 编辑

USACO sec1.5 Prime Palindromes

摘要: 素回文数,打表。。打表输出# include <math.h># include <time.h># include <stdio.h># define id(x) ((x)>>3)# define of(x) ((x)&0x7)# define get(x) ((pt[id(x)]>>of(x))&0x1)# define set(x) (pt[id(x)] |= (0x1<<(of(x))))# define MAXN 100000000char pt[(MAXN>>3) +1];void 阅读全文

posted @ 2012-08-21 10:50 getgoing 阅读(378) 评论(0) 推荐(0) 编辑

USACO sec1.4 Mother's Milk

摘要: BFS 1 /* 2 PROG : milk3 3 LANG : C++ 4 */ 5 # include <stdio.h> 6 7 # define MAXN 20005 8 9 /**********************************************/10 int a[3], c[3], ss;11 char vis[MAXN];12 int Q[MAXN], front, rear;13 int sol[25];14 15 void cal(int s)16 {17 a[0] = s%21;18 a[1] = s/21%21;19 a[... 阅读全文

posted @ 2012-08-21 09:41 getgoing 阅读(239) 评论(0) 推荐(0) 编辑

导航