summaryrefslogtreecommitdiff
path: root/1.4/combo.c
diff options
context:
space:
mode:
authorIru Cai <mytbk920423@gmail.com>2018-04-16 19:06:32 +0800
committerIru Cai <mytbk920423@gmail.com>2018-04-16 19:06:32 +0800
commitad4e2420e822b8a115aac6124307b89447578782 (patch)
tree6f4db875081597e2e64dd4221a97bbff25503dcc /1.4/combo.c
parenta7721767628a51b752ad3a96eb334734241dcd8b (diff)
downloadusaco-ad4e2420e822b8a115aac6124307b89447578782.tar.xz
1.2~1.5
Diffstat (limited to '1.4/combo.c')
-rw-r--r--1.4/combo.c51
1 files changed, 51 insertions, 0 deletions
diff --git a/1.4/combo.c b/1.4/combo.c
new file mode 100644
index 0000000..7c5b3d1
--- /dev/null
+++ b/1.4/combo.c
@@ -0,0 +1,51 @@
+/*
+ID: mytbk921
+LANG: C
+TASK: combo
+*/
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+int matches(int a[], int b[], int N)
+{
+ int i;
+ for (i = 0; i < 3; i++) {
+ if (abs(a[i]-b[i]) <= 2 ||
+ N - abs(a[i]-b[i]) <= 2)
+ continue;
+ else
+ return 0;
+ }
+ return 1;
+}
+
+int main()
+{
+ FILE *fin, *fout;
+ int farmer[3], master[3], test[3];
+ int N, i, count = 0;
+
+ fin = fopen("combo.in", "r");
+ fout = fopen("combo.out", "w");
+
+ fscanf(fin, "%d", &N);
+ for (i = 0; i<3; i++)
+ fscanf(fin, "%d", &farmer[i]);
+ for (i = 0; i<3; i++)
+ fscanf(fin, "%d", &master[i]);
+ fclose(fin);
+
+ for (test[0] = 1; test[0] <= N; test[0]++)
+ for (test[1] = 1; test[1] <= N; test[1]++)
+ for (test[2] = 1; test[2] <= N; test[2]++)
+ if (matches(farmer, test, N) || matches(master, test, N))
+ count++;
+
+ fprintf(fout, "%d\n", count);
+ fclose(fout);
+ return 0;
+}
+
+