about summary refs log tree commit diff
path: root/NTU
diff options
context:
space:
mode:
authorRaphael McSinyx <vn.mcsinyx@gmail.com>2017-01-09 10:47:37 +0700
committerRaphael McSinyx <vn.mcsinyx@gmail.com>2017-01-09 10:47:37 +0700
commit318184dbda0658d8afae6dd3c13a0718382726a1 (patch)
tree5a62259a03200cd77823431994fe3479e5d7461f /NTU
parent15b38076cc08d89024864252e99e10fe6f597196 (diff)
downloadcp-318184dbda0658d8afae6dd3c13a0718382726a1.tar.gz
Add NTU/{pali2,editpic}.c and update README.md
Diffstat (limited to 'NTU')
-rw-r--r--NTU/README.md4
-rw-r--r--NTU/editpic.c30
-rw-r--r--NTU/pali2.c68
3 files changed, 100 insertions, 2 deletions
diff --git a/NTU/README.md b/NTU/README.md
index 8261d6c..1caccf3 100644
--- a/NTU/README.md
+++ b/NTU/README.md
@@ -7,7 +7,7 @@
 - [x] writer: [Robot đánh chữ](http://laptrinh.ntu.edu.vn/Problem/Details/3255)
 - [x] ngto4: [Tổng nguyên tố](http://laptrinh.ntu.edu.vn/Problem/Details/3256)
 - [x] demso0: [Đếm số không bên phải](http://laptrinh.ntu.edu.vn/Problem/Details/3330)
-- [ ] pali2: [Tách chuỗi đối xứng](http://laptrinh.ntu.edu.vn/Problem/Details/3332)
+- [x] pali2: [Tách chuỗi đối xứng](http://laptrinh.ntu.edu.vn/Problem/Details/3332)
 - [x] moco: [Khu mộ cổ](http://laptrinh.ntu.edu.vn/Problem/Details/3343)
 - [x] dayso6: [Dãy số](http://laptrinh.ntu.edu.vn/Problem/Details/3344)
 - [x] keba2: [Kết bạn](http://laptrinh.ntu.edu.vn/Problem/Details/3345)
@@ -25,6 +25,6 @@
 - [ ] hamar: [Hàm số](http://laptrinh.ntu.edu.vn/Problem/Details/5557)
 - [x] xauduynhat: [Xâu duy nhất](http://laptrinh.ntu.edu.vn/Problem/Details/5573)
 - [x] chenhlech: [Chênh lệch](http://laptrinh.ntu.edu.vn/Problem/Details/5574)
-- [ ] editpic: [Chỉnh sửa ảnh](http://laptrinh.ntu.edu.vn/Problem/Details/5588)
+- [x] editpic: [Chỉnh sửa ảnh](http://laptrinh.ntu.edu.vn/Problem/Details/5588)
 - [ ] cntpalin: [Đếm số Palindrome](http://laptrinh.ntu.edu.vn/Problem/Details/5600)
 - [x] TutOnEqua: [Tutoring on equations](http://laptrinh.ntu.edu.vn/Problem/Details/5606)
diff --git a/NTU/editpic.c b/NTU/editpic.c
new file mode 100644
index 0000000..5e34d74
--- /dev/null
+++ b/NTU/editpic.c
@@ -0,0 +1,30 @@
+#include <stdio.h>
+
+const long long POW2[] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048,
+                          4096, 8192, 16384, 32768, 65536, 131072, 262144,
+                          524288, 1048576, 2097152, 4194304, 8388608, 16777216,
+                          33554432, 67108864, 134217728, 268435456, 536870912};
+
+int main()
+{
+	long long l, w, l0, w0, l1, w1;
+	char i;
+
+	scanf("%lld %lld", &l, &w);
+
+	for (i = 29; POW2[i] > l || POW2[i] * 4 > w * 5; i--);
+	l0 = POW2[i];
+	w0 = (l0 * 5 >= w * 4) ? w : l0 * 5 / 4;
+
+	for (i = 29; POW2[i] > w || POW2[i] * 4 > l * 5; i--);
+	w1 = POW2[i];
+	l1 = (w1 * 5 >= l * 4) ? l : w1 * 5 / 4;
+
+	l = l0 * w0 - l1 * w1;
+	if (l > 0 || !l && l0 > l1)
+		printf("%lld %lld\n", l0, w0);
+	else
+		printf("%lld %lld\n", l1, w1);
+
+	return 0;
+}
diff --git a/NTU/pali2.c b/NTU/pali2.c
new file mode 100644
index 0000000..72c9105
--- /dev/null
+++ b/NTU/pali2.c
@@ -0,0 +1,68 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+short MIN_K, *P;
+
+void putnc(char *s, short len)
+{
+	short i;
+
+	for (i = 0; i < len; i++)
+		putchar(s[i]);
+	putchar(10);
+}
+
+char palin(char *s, short len)
+{
+	short i;
+
+	for (i = 0; i < (len + 1) / 2; i++)
+		if (s[i] != s[len - i - 1])
+			return 0;
+
+	return 1;
+}
+
+void foo(char *s, short len, short k, short *p)
+{
+	short i, j;
+
+	if (palin(s, len)) {
+		MIN_K = k;
+		memcpy(P, p, k * sizeof(short));
+		return;
+	}
+
+	if (k >= MIN_K)
+		return;
+
+	for (i = len - 1; i; i--)
+		if (palin(s, i)) {
+			p[k] = p[k - 1] + i;
+			foo(s + i, len - i, k + 1, p);
+		}
+}
+
+int main()
+{
+	short n, i, *p;
+	char *s;
+
+	scanf("%hd\n", &n);
+	s = malloc(n + 1);
+	fgets(s, n + 1, stdin);
+
+	MIN_K = n;
+	P = malloc(n);
+	p = malloc(n);
+	p[0] = 0;
+	foo(s, n, 1, p);
+
+	printf("%hd\n", MIN_K);
+	for (i = 1; i < MIN_K; i++)
+		putnc(s + P[i - 1], P[i] - P[i - 1]);
+	puts(s + P[MIN_K - 1]);
+
+	return 0;
+}