From 92d2da1251d9712ee86c733e648c0feceeb7d571 Mon Sep 17 00:00:00 2001 From: Iru Cai Date: Thu, 19 Apr 2018 23:12:23 +0800 Subject: finish 2.1 --- 2.1/hamming.c | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2.1/holstein.c | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2.1/sort3.c | 55 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 208 insertions(+) create mode 100644 2.1/hamming.c create mode 100644 2.1/holstein.c create mode 100644 2.1/sort3.c diff --git a/2.1/hamming.c b/2.1/hamming.c new file mode 100644 index 0000000..abc3483 --- /dev/null +++ b/2.1/hamming.c @@ -0,0 +1,75 @@ +/* +ID: mytbk921 +LANG: C +TASK: hamming +*/ + +#include + +typedef unsigned char u8; + +static unsigned +popcount(unsigned x) +{ + unsigned c = 0; + while (x) { + if (x&1) c++; + x >>= 1; + } + return c; +} + +static unsigned +hamdist(unsigned x, unsigned y) +{ + return popcount(x^y); +} + +u8 s[64]; +int N, B, D; + +int search(int i) +{ + int t, j; + if (i==N) return 1; + + for (t=s[i-1]+1; t<(1<0) + fprintf(fout, "\n"); + } else { + fprintf(fout, " "); + } + fprintf(fout, "%d", s[i]); + } + fprintf(fout, "\n"); + } + fclose(fout); + return 0; +} diff --git a/2.1/holstein.c b/2.1/holstein.c new file mode 100644 index 0000000..637a43a --- /dev/null +++ b/2.1/holstein.c @@ -0,0 +1,78 @@ +/* +ID: mytbk921 +LANG: C +TASK: holstein +*/ + +#include +#include +#include +#include + +int vitamins[25]; +int feeds[15][25]; +int nv; +int nf; + +static unsigned +popcount(unsigned x) +{ + unsigned c = 0; + while (x) { + if (x&1) c++; + x >>= 1; + } + return c; +} + +int main() +{ + FILE *fin = fopen("holstein.in", "r"); + FILE *fout = fopen("holstein.out", "w"); + int i, j; + unsigned scm, best, ans_n, tn; + int tmp_v[25]; + + fscanf(fin, "%d", &nv); + for (i=0; i=ans_n) + continue; + memset(tmp_v, 0, sizeof(tmp_v)); + for (i=0; i +#include +#include +#include + +static inline int min(int a, int b) { return a